File tree Expand file tree Collapse file tree
src/BootstrapBlazor/Localization/Json Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55
66using Microsoft . Extensions . Localization ;
77using Microsoft . Extensions . Logging ;
8+
89using System . Collections . Concurrent ;
910using System . Globalization ;
1011using System . Reflection ;
@@ -119,7 +120,28 @@ public override LocalizedString this[string name]
119120 }
120121 else
121122 {
122- HandleMissingResourceItem ( name ) ;
123+ // 如果没有找到资源信息则尝试从父类中查找
124+ var type = Assembly . GetType ( typeName ) ;
125+ var propertyInfo = type ? . GetPropertyByName ( name ) ;
126+ if ( propertyInfo != null )
127+ {
128+ var baseType = propertyInfo . DeclaringType ! ;
129+ // 如果是父类属性则尝试从父类中查找
130+ if ( baseType != type )
131+ {
132+ var baseAssembly = baseType . Assembly ! ;
133+ var localizerStrings2 = MegerResolveLocalizers ( CacheManager . GetAllStringsByTypeName ( baseAssembly , baseType . FullName ! ) ) ;
134+
135+ var l2 = localizerStrings2 . Find ( i => i . Name == name ) ;
136+ if ( l2 is { ResourceNotFound : false } )
137+ {
138+ ret = l2 . Value ;
139+ }
140+ }
141+
142+ }
143+ if ( ret is null )
144+ HandleMissingResourceItem ( name ) ;
123145 }
124146 }
125147 return ret ;
You can’t perform that action at this time.
0 commit comments