|
|
@@ -85,17 +85,29 @@ namespace System.Reflection {
|
|
|
}
|
|
|
|
|
|
[MethodImpl (MethodImplOptions.InternalCall)]
|
|
|
- static extern bool ParseName (AssemblyName aname, string assemblyName);
|
|
|
-
|
|
|
+ static extern bool ParseAssemblyName (IntPtr name, out MonoAssemblyName aname, out bool is_version_definited, out bool is_token_defined);
|
|
|
+
|
|
|
public AssemblyName (string assemblyName)
|
|
|
{
|
|
|
if (assemblyName == null)
|
|
|
throw new ArgumentNullException ("assemblyName");
|
|
|
if (assemblyName.Length < 1)
|
|
|
throw new ArgumentException ("assemblyName cannot have zero length.");
|
|
|
-
|
|
|
- if (!ParseName (this, assemblyName))
|
|
|
- throw new FileLoadException ("The assembly name is invalid.");
|
|
|
+
|
|
|
+ using (var name = RuntimeMarshal.MarshalString (assemblyName)) {
|
|
|
+ MonoAssemblyName nativeName;
|
|
|
+ bool isVersionDefined, isTokenDefined;
|
|
|
+ //ParseName free the name if it fails.
|
|
|
+ if (!ParseAssemblyName (name.Value, out nativeName, out isVersionDefined, out isTokenDefined))
|
|
|
+ throw new FileLoadException ("The assembly name is invalid.");
|
|
|
+ try {
|
|
|
+ unsafe {
|
|
|
+ this.FillName (&nativeName, null, isVersionDefined, false, isTokenDefined);
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ RuntimeMarshal.FreeAssemblyName (ref nativeName);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
[MonoLimitation ("Not used, as the values are too limited; Mono supports more")]
|
|
|
@@ -454,53 +466,57 @@ namespace System.Reflection {
|
|
|
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
|
|
static extern unsafe MonoAssemblyName* GetNativeName (IntPtr assembly_ptr);
|
|
|
|
|
|
- internal static AssemblyName Create (Assembly assembly, bool fillCodebase)
|
|
|
+ internal unsafe void FillName (MonoAssemblyName *native, string codeBase, bool addVersion, bool addPublickey, bool defaultToken)
|
|
|
{
|
|
|
- AssemblyName aname = new AssemblyName ();
|
|
|
- unsafe {
|
|
|
- MonoAssemblyName *native = GetNativeName (assembly._mono_assembly);
|
|
|
+ this.name = RuntimeMarshal.PtrToUtf8String (native->name);
|
|
|
|
|
|
- aname.name = RuntimeMarshal.PtrToUtf8String (native->name);
|
|
|
+ this.major = native->major;
|
|
|
+ this.minor = native->minor;
|
|
|
+ this.build = native->build;
|
|
|
+ this.revision = native->revision;
|
|
|
|
|
|
- aname.major = native->major;
|
|
|
- aname.minor = native->minor;
|
|
|
- aname.build = native->build;
|
|
|
- aname.revision = native->revision;
|
|
|
+ this.flags = (AssemblyNameFlags)native->flags;
|
|
|
|
|
|
- aname.flags = (AssemblyNameFlags)native->flags;
|
|
|
+ this.hashalg = (AssemblyHashAlgorithm)native->hash_alg;
|
|
|
|
|
|
- aname.hashalg = (AssemblyHashAlgorithm)native->hash_alg;
|
|
|
+ this.versioncompat = AssemblyVersionCompatibility.SameMachine;
|
|
|
+ this.processor_architecture = (ProcessorArchitecture)native->arch;
|
|
|
|
|
|
- aname.versioncompat = AssemblyVersionCompatibility.SameMachine;
|
|
|
- aname.processor_architecture = (ProcessorArchitecture)native->arch;
|
|
|
+ if (addVersion)
|
|
|
+ this.version = new Version (this.major, this.minor, this.build, this.revision);
|
|
|
|
|
|
- aname.version = new Version (aname.major, aname.minor, aname.build, aname.revision);
|
|
|
+ this.codebase = codeBase;
|
|
|
|
|
|
- if (fillCodebase)
|
|
|
- aname.codebase = assembly.CodeBase;
|
|
|
+ if (native->culture != IntPtr.Zero)
|
|
|
+ this.cultureinfo = CultureInfo.CreateCulture ( RuntimeMarshal.PtrToUtf8String (native->culture), false);
|
|
|
|
|
|
- if (native->culture != IntPtr.Zero)
|
|
|
- aname.cultureinfo = CultureInfo.CreateCulture ( RuntimeMarshal.PtrToUtf8String (native->culture), false);
|
|
|
+ if (native->public_key != IntPtr.Zero) {
|
|
|
+ this.publicKey = RuntimeMarshal.DecodeBlobArray (native->public_key);
|
|
|
+ this.flags |= AssemblyNameFlags.PublicKey;
|
|
|
+ } else if (addPublickey) {
|
|
|
+ this.publicKey = EmptyArray<byte>.Value;
|
|
|
+ this.flags |= AssemblyNameFlags.PublicKey;
|
|
|
+ }
|
|
|
|
|
|
- if (native->public_key != IntPtr.Zero) {
|
|
|
- aname.publicKey = RuntimeMarshal.DecodeBlobArray (native->public_key);
|
|
|
- aname.flags |= AssemblyNameFlags.PublicKey;
|
|
|
- } else {
|
|
|
- aname.publicKey = EmptyArray<byte>.Value;
|
|
|
- aname.flags |= AssemblyNameFlags.PublicKey;
|
|
|
+ // MonoAssemblyName keeps the public key token as an hexadecimal string
|
|
|
+ if (native->public_key_token [0] != 0) {
|
|
|
+ byte[] keyToken = new byte [8];
|
|
|
+ for (int i = 0, j = 0; i < 8; ++i) {
|
|
|
+ keyToken [i] = (byte)(RuntimeMarshal.AsciHexDigitValue (native->public_key_token [j++]) << 4);
|
|
|
+ keyToken [i] |= (byte)RuntimeMarshal.AsciHexDigitValue (native->public_key_token [j++]);
|
|
|
}
|
|
|
+ this.keyToken = keyToken;
|
|
|
+ } else if (defaultToken) {
|
|
|
+ this.keyToken = EmptyArray<byte>.Value;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // MonoAssemblyName keeps the public key token as an hexadecimal string
|
|
|
- if (native->public_key_token [0] != 0) {
|
|
|
- byte[] keyToken = new byte [8];
|
|
|
- for (int i = 0, j = 0; i < 8; ++i) {
|
|
|
- keyToken [i] = (byte)(RuntimeMarshal.AsciHexDigitValue (native->public_key_token [j++]) << 4);
|
|
|
- keyToken [i] |= (byte)RuntimeMarshal.AsciHexDigitValue (native->public_key_token [j++]);
|
|
|
- }
|
|
|
- aname.keyToken = keyToken;
|
|
|
- } else {
|
|
|
- aname.keyToken = EmptyArray<byte>.Value;
|
|
|
- }
|
|
|
+ internal static AssemblyName Create (Assembly assembly, bool fillCodebase)
|
|
|
+ {
|
|
|
+ AssemblyName aname = new AssemblyName ();
|
|
|
+ unsafe {
|
|
|
+ MonoAssemblyName *native = GetNativeName (assembly._mono_assembly);
|
|
|
+ aname.FillName (native, fillCodebase ? assembly.CodeBase : null, true, true, true);
|
|
|
}
|
|
|
return aname;
|
|
|
}
|