Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup Condition="'$(VisualStudioVersion)' == '17.0'">
<Version>9.11.5-beta03</Version>
<Version>9.11.5-beta04</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(VisualStudioVersion)' == '18.0'">
<Version>10.0.0-rc.2.1.2</Version>
<Version>10.0.0-rc.2.1.3</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone

using System.Reflection;

namespace BootstrapBlazor.Components;

/// <summary>
Expand Down Expand Up @@ -82,13 +80,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
protected virtual void OnLoadJSModule()
{
var type = this.GetType();
var inherited = type.GetCustomAttribute<JSModuleNotInheritedAttribute>() == null;
if (inherited)
if (CacheManager.GetAttribute<JSModuleNotInheritedAttribute>(type) == null)
{
var attributes = type.GetCustomAttributes<JSModuleAutoLoaderAttribute>();
if (attributes.Any())
var attr = CacheManager.GetAttribute<JSModuleAutoLoaderAttribute>(type);
if (attr != null)
{
var attr = attributes.First();
AutoInvokeDispose = attr.AutoInvokeDispose;
AutoInvokeInit = attr.AutoInvokeInit;

Expand Down
4 changes: 1 addition & 3 deletions src/BootstrapBlazor/Extensions/AssemblyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ static class AssemblyExtensions
/// </summary>
/// <param name="assembly"></param>
/// <returns></returns>
public static string GetUniqueName(this Assembly assembly) => assembly.IsCollectible
? $"{assembly.GetName().Name}-{assembly.GetHashCode()}"
: $"{assembly.GetName().Name}";
public static string GetUniqueName(this Assembly assembly) => CacheManager.GetUniqueName(assembly);
}
36 changes: 36 additions & 0 deletions src/BootstrapBlazor/Services/CacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,42 @@ private List<ICacheEntry> GetAllValues(MemoryCache cache)
}
#endif

#region Attribute
/// <summary>
/// 获得类型特性标签方法
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static Attr? GetAttribute<Attr>(Type type) where Attr : Attribute
{
return Instance.GetOrCreate((type, typeof(Attr)), _ =>
{
return type.GetCustomAttribute<Attr>();
});
}

#endregion

#region Assembly
/// <summary>
/// 获得唯一类型名称方法
/// </summary>
/// <param name="assembly"></param>
/// <returns></returns>
public static string GetUniqueName(Assembly assembly)
{
//key不拼接,作为当前静态实例唯一标识,因为GetUniqueName方法会被频繁调用
return Instance.GetOrCreate(assembly, _ =>
{
return assembly.IsCollectible
? $"{assembly.GetName().Name}-{assembly.GetHashCode()}"
: $"{assembly.GetName().Name}";
}
);
}

#endregion

#region Count
public static int ElementCount(object? value)
{
Expand Down
Loading