private static string GetEnvironmentVariableCore(string variable) { Debug.Assert(variable != null); if (s_environment == null) { using (var h = RuntimeMarshal.MarshalString(variable)) { return(internalGetEnvironmentVariable_native(h.Value)); } } variable = TrimStringOnFirstZero(variable); lock (s_environment) { s_environment.TryGetValue(variable, out string value); return(value); } }
public static AssemblyName GetAssemblyName(string assemblyFile) { if (assemblyFile == null) { throw new ArgumentNullException("assemblyFile"); } AssemblyName aname = new AssemblyName(); unsafe { Mono.MonoAssemblyName nativeName; string codebase; Assembly.InternalGetAssemblyName(Path.GetFullPath(assemblyFile), out nativeName, out codebase); try { aname.FillName(&nativeName, codebase, true, false, true, false); } finally { RuntimeMarshal.FreeAssemblyName(ref nativeName, false); } } return(aname); }
internal unsafe void FillName(MonoAssemblyName *native, string codeBase, bool addVersion, bool addPublickey, bool defaultToken) { _name = RuntimeMarshal.PtrToUtf8String(native->name); _flags = (AssemblyNameFlags)native->flags; _hashAlgorithm = (AssemblyHashAlgorithm)native->hash_alg; _versionCompatibility = AssemblyVersionCompatibility.SameMachine; if (addVersion) { var build = native->build == 65535 ? -1 : native->build; var revision = native->revision == 65535 ? -1 : native->revision; if (build == -1) { _version = new Version(native->major, native->minor); } else if (revision == -1) { _version = new Version(native->major, native->minor, build); } else { _version = new Version(native->major, native->minor, build, revision); } } _codeBase = codeBase; if (native->culture != IntPtr.Zero) { _cultureInfo = CultureInfo.GetCultureInfo(RuntimeMarshal.PtrToUtf8String(native->culture)); } if (native->public_key != IntPtr.Zero) { _publicKey = RuntimeMarshal.DecodeBlobArray(native->public_key); _flags |= AssemblyNameFlags.PublicKey; } else if (addPublickey) { _publicKey = EmptyArray <byte> .Value; _flags |= AssemblyNameFlags.PublicKey; } // MonoAssemblyName keeps the public key token as an hexadecimal string if (native->public_key_token [0] != 0) { var 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++]); } _publicKeyToken = keyToken; } else if (defaultToken) { _publicKeyToken = EmptyArray <byte> .Value; } }
internal unsafe void FillName(MonoAssemblyName *native, string codeBase, bool addVersion, bool addPublickey, bool defaultToken, bool assemblyRef) { this.name = RuntimeMarshal.PtrToUtf8String(native->name); this.major = native->major; this.minor = native->minor; #if NETCORE this.build = native->build == 65535 ? -1 : native->build; this.revision = native->revision == 65535 ? -1 : native->revision; #else this.build = native->build; this.revision = native->revision; #endif this.flags = (AssemblyNameFlags)native->flags; this.hashalg = (AssemblyHashAlgorithm)native->hash_alg; this.versioncompat = AssemblyVersionCompatibility.SameMachine; this.processor_architecture = (ProcessorArchitecture)native->arch; #if NETCORE if (addVersion) { if (this.build == -1) { this.version = new Version(this.major, this.minor); } else if (this.revision == -1) { this.version = new Version(this.major, this.minor, this.build); } else { this.version = new Version(this.major, this.minor, this.build, this.revision); } } #else if (addVersion) { this.version = new Version(this.major, this.minor, this.build, this.revision); } #endif this.codebase = codeBase; #if NETCORE if (native->culture != IntPtr.Zero) { this.cultureinfo = CultureInfo.GetCultureInfo(RuntimeMarshal.PtrToUtf8String(native->culture)); } #else if (native->culture != IntPtr.Zero) { this.cultureinfo = CultureInfo.CreateCulture(RuntimeMarshal.PtrToUtf8String(native->culture), assemblyRef); } #endif 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; } // 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; } }
static string GetEnvironmentVariableCore(string variable) { using (var h = RuntimeMarshal.MarshalString(variable)) { return(internalGetEnvironmentVariable_native(h.Value)); } }