c# - CultureName of System assembly in .NET -
while writing code handling assemblies in c# noticed inconsistencies in field values of assembly
object (example of system
assembly):
> typeof(string).assembly.fullname "mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089"
but when accessing culturename
field of assemblyname
object directly, value empty string:
> typeof(string).assembly.getname().culturename ""
when run same test on linux (mono 3.99
) got result:
> typeof(string).assembly.getname().culturename "neutral"
why .net behaves way? couldn't find information on msdn regarding default value of culturename
field in assemblyname
class or meaning of empty string. empty string refers "neutral" culture name?
the culturename
property introduced in .net 4.5 , value of property assembly
neutral culture must equal empty string name of invariant culture because culturename
uses thecultureinfo
property (source):
public string culturename { { return (_cultureinfo == null) ? null : _cultureinfo.name; } }
but in mono culturename
property has different implementation (source). why different? think developers of mono know answer.
public string culturename { { if (cultureinfo == null) return null; if (cultureinfo.lcid == cultureinfo.invariantculture.lcid) return "neutral"; return cultureinfo.name; } }
so if want check assemblyname
has neutral culture, use code below:
if (object.equals(assemblyname.cultureinfo, cultureinfo.invariantculture)) { /* neutral culture */ }
Comments
Post a Comment