// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-/*============================================================
-**
-**
-**
-**
-**
-**
-** Purpose: Used for binding and retrieving info about an assembly
-**
-**
-===========================================================*/
+using System.Configuration.Assemblies;
+using System.IO;
+using System.Runtime.CompilerServices;
+using System.Runtime.Serialization;
+using System.Text;
+using CultureInfo = System.Globalization.CultureInfo;
namespace System.Reflection
{
- using System;
- using System.IO;
- using System.Configuration.Assemblies;
- using System.Runtime.CompilerServices;
- using CultureInfo = System.Globalization.CultureInfo;
- using System.Runtime.Serialization;
- using System.Runtime.InteropServices;
- using System.Runtime.Versioning;
- using System.Text;
-
- public sealed class AssemblyName : ICloneable, ISerializable, IDeserializationCallback
+ public sealed class AssemblyName : ICloneable, IDeserializationCallback, ISerializable
{
- //
- // READ ME
// If you modify any of these fields, you must also update the
// AssemblyBaseObject structure in object.h
- //
- private string _Name; // Name
- private byte[] _PublicKey;
- private byte[] _PublicKeyToken;
- private CultureInfo _CultureInfo;
- private string _CodeBase; // Potential location to get the file
- private Version _Version;
-
- private StrongNameKeyPair _StrongNameKeyPair;
+ private string _name;
+ private byte[] _publicKey;
+ private byte[] _publicKeyToken;
+ private CultureInfo _cultureInfo;
+ private string _codeBase;
+ private Version _version;
- private SerializationInfo m_siInfo; //A temporary variable which we need during deserialization.
+ private StrongNameKeyPair _strongNameKeyPair;
- private byte[] _HashForControl;
- private AssemblyHashAlgorithm _HashAlgorithm;
- private AssemblyHashAlgorithm _HashAlgorithmForControl;
+ private byte[] _hashForControl;
+ private AssemblyHashAlgorithm _hashAlgorithm;
+ private AssemblyHashAlgorithm _hashAlgorithmForControl;
- private AssemblyVersionCompatibility _VersionCompatibility;
- private AssemblyNameFlags _Flags;
+ private AssemblyVersionCompatibility _versionCompatibility;
+ private AssemblyNameFlags _flags;
public AssemblyName()
{
- _HashAlgorithm = AssemblyHashAlgorithm.None;
- _VersionCompatibility = AssemblyVersionCompatibility.SameMachine;
- _Flags = AssemblyNameFlags.None;
+ _hashAlgorithm = AssemblyHashAlgorithm.None;
+ _versionCompatibility = AssemblyVersionCompatibility.SameMachine;
+ _flags = AssemblyNameFlags.None;
+ }
+
+ public AssemblyName(string assemblyName)
+ {
+ if (assemblyName == null)
+ throw new ArgumentNullException(nameof(assemblyName));
+ if ((assemblyName.Length == 0) ||
+ (assemblyName[0] == '\0'))
+ throw new ArgumentException(SR.Format_StringZeroLength);
+
+ _name = assemblyName;
+ nInit();
}
// Set and get the name of the assembly. If this is a weak Name
// the name partitions up the strong name's namespace
public string Name
{
- get { return _Name; }
- set { _Name = value; }
+ get { return _name; }
+ set { _name = value; }
}
public Version Version
{
- get
- {
- return _Version;
- }
- set
- {
- _Version = value;
- }
+ get { return _version; }
+ set { _version = value; }
}
// Locales, internally the LCID is used for the match.
public CultureInfo CultureInfo
{
- get
- {
- return _CultureInfo;
- }
- set
- {
- _CultureInfo = value;
- }
+ get { return _cultureInfo; }
+ set { _cultureInfo = value; }
}
public string CultureName
{
get
{
- return (_CultureInfo == null) ? null : _CultureInfo.Name;
+ return (_cultureInfo == null) ? null : _cultureInfo.Name;
}
set
{
- _CultureInfo = (value == null) ? null : new CultureInfo(value);
+ _cultureInfo = (value == null) ? null : new CultureInfo(value);
}
}
public string CodeBase
{
- get { return _CodeBase; }
- set { _CodeBase = value; }
+ get { return _codeBase; }
+ set { _codeBase = value; }
}
public string EscapedCodeBase
{
get
{
- if (_CodeBase == null)
+ if (_codeBase == null)
return null;
else
- return EscapeCodeBase(_CodeBase);
+ return EscapeCodeBase(_codeBase);
}
}
{
get
{
- int x = (((int)_Flags) & 0x70) >> 4;
+ int x = (((int)_flags) & 0x70) >> 4;
if (x > 5)
x = 0;
return (ProcessorArchitecture)x;
int x = ((int)value) & 0x07;
if (x <= 5)
{
- _Flags = (AssemblyNameFlags)((int)_Flags & 0xFFFFFF0F);
- _Flags |= (AssemblyNameFlags)(x << 4);
+ _flags = (AssemblyNameFlags)((int)_flags & 0xFFFFFF0F);
+ _flags |= (AssemblyNameFlags)(x << 4);
}
}
}
{
get
{
- int x = (((int)_Flags) & 0x00000E00) >> 9;
+ int x = (((int)_flags) & 0x00000E00) >> 9;
if (x > 1)
x = 0;
return (AssemblyContentType)x;
int x = ((int)value) & 0x07;
if (x <= 1)
{
- _Flags = (AssemblyNameFlags)((int)_Flags & 0xFFFFF1FF);
- _Flags |= (AssemblyNameFlags)(x << 9);
+ _flags = (AssemblyNameFlags)((int)_flags & 0xFFFFF1FF);
+ _flags |= (AssemblyNameFlags)(x << 9);
}
}
}
-
-
// Make a copy of this assembly name.
public object Clone()
{
AssemblyName name = new AssemblyName();
- name.Init(_Name,
- _PublicKey,
- _PublicKeyToken,
- _Version,
- _CultureInfo,
- _HashAlgorithm,
- _VersionCompatibility,
- _CodeBase,
- _Flags,
- _StrongNameKeyPair);
- name._HashForControl = _HashForControl;
- name._HashAlgorithmForControl = _HashAlgorithmForControl;
+ name.Init(_name,
+ _publicKey,
+ _publicKeyToken,
+ _version,
+ _cultureInfo,
+ _hashAlgorithm,
+ _versionCompatibility,
+ _codeBase,
+ _flags,
+ _strongNameKeyPair);
+ name._hashForControl = _hashForControl;
+ name._hashAlgorithmForControl = _hashAlgorithmForControl;
return name;
}
return nGetFileInformation(fullPath);
}
- internal void SetHashControl(byte[] hash, AssemblyHashAlgorithm hashAlgorithm)
- {
- _HashForControl = hash;
- _HashAlgorithmForControl = hashAlgorithm;
- }
-
// The public key that is used to verify an assemblies
// inclusion into the namespace. If the public key associated
// with the namespace cannot verify the assembly the assembly
// will fail to load.
public byte[] GetPublicKey()
{
- return _PublicKey;
+ return _publicKey;
}
public void SetPublicKey(byte[] publicKey)
{
- _PublicKey = publicKey;
+ _publicKey = publicKey;
if (publicKey == null)
- _Flags &= ~AssemblyNameFlags.PublicKey;
+ _flags &= ~AssemblyNameFlags.PublicKey;
else
- _Flags |= AssemblyNameFlags.PublicKey;
+ _flags |= AssemblyNameFlags.PublicKey;
}
// The compressed version of the public key formed from a truncated hash.
- // Will throw a SecurityException if _PublicKey is invalid
+ // Will throw a SecurityException if _publicKey is invalid
public byte[] GetPublicKeyToken()
{
- if (_PublicKeyToken == null)
- _PublicKeyToken = nGetPublicKeyToken();
- return _PublicKeyToken;
+ if (_publicKeyToken == null)
+ _publicKeyToken = nGetPublicKeyToken();
+ return _publicKeyToken;
}
public void SetPublicKeyToken(byte[] publicKeyToken)
{
- _PublicKeyToken = publicKeyToken;
+ _publicKeyToken = publicKeyToken;
}
// Flags modifying the name. So far the only flag is PublicKey, which
// indicates that a full public key and not the compressed version is
- // present.
+ // present.
// Processor Architecture flags are set only through ProcessorArchitecture
// property and can't be set or retrieved directly
- // Content Type flags are set only through ContentType property and can't be
+ // Content Type flags are set only through ContentType property and can't be
// set or retrieved directly
public AssemblyNameFlags Flags
{
- get { return (AssemblyNameFlags)((uint)_Flags & 0xFFFFF10F); }
+ get { return (AssemblyNameFlags)((uint)_flags & 0xFFFFF10F); }
set
{
- _Flags &= unchecked((AssemblyNameFlags)0x00000EF0);
- _Flags |= (value & unchecked((AssemblyNameFlags)0xFFFFF10F));
+ _flags &= unchecked((AssemblyNameFlags)0x00000EF0);
+ _flags |= (value & unchecked((AssemblyNameFlags)0xFFFFF10F));
}
}
public AssemblyHashAlgorithm HashAlgorithm
{
- get { return _HashAlgorithm; }
- set { _HashAlgorithm = value; }
+ get { return _hashAlgorithm; }
+ set { _hashAlgorithm = value; }
}
public AssemblyVersionCompatibility VersionCompatibility
{
- get { return _VersionCompatibility; }
- set { _VersionCompatibility = value; }
+ get { return _versionCompatibility; }
+ set { _versionCompatibility = value; }
}
public StrongNameKeyPair KeyPair
{
- get { return _StrongNameKeyPair; }
- set { _StrongNameKeyPair = value; }
+ get { return _strongNameKeyPair; }
+ set { _strongNameKeyPair = value; }
}
public string FullName
if (this.Name == null)
return string.Empty;
// Do not call GetPublicKeyToken() here - that latches the result into AssemblyName which isn't a side effect we want.
- byte[] pkt = _PublicKeyToken ?? nGetPublicKeyToken();
+ byte[] pkt = _publicKeyToken ?? nGetPublicKeyToken();
return AssemblyNameFormatter.ComputeDisplayName(Name, Version, CultureName, pkt, Flags, ContentType);
}
}
- // Returns the stringized version of the assembly name.
public override string ToString()
{
string s = FullName;
throw new PlatformNotSupportedException();
}
- public AssemblyName(string assemblyName)
- {
- if (assemblyName == null)
- throw new ArgumentNullException(nameof(assemblyName));
- if ((assemblyName.Length == 0) ||
- (assemblyName[0] == '\0'))
- throw new ArgumentException(SR.Format_StringZeroLength);
-
- _Name = assemblyName;
- nInit();
- }
-
/// <summary>
/// Compares the simple names disregarding Version, Culture and PKT. While this clearly does not
/// match the intent of this api, this api has been broken this way since its debut and we cannot
internal void SetProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm)
{
- ProcessorArchitecture = CalculateProcArchIndex(pek, ifm, _Flags);
+ ProcessorArchitecture = CalculateProcArchIndex(pek, ifm, _flags);
}
internal static ProcessorArchitecture CalculateProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm, AssemblyNameFlags flags)
AssemblyNameFlags flags,
StrongNameKeyPair keyPair) // Null if ref, matching Assembly if def
{
- _Name = name;
+ _name = name;
if (publicKey != null)
{
- _PublicKey = new byte[publicKey.Length];
- Array.Copy(publicKey, _PublicKey, publicKey.Length);
+ _publicKey = new byte[publicKey.Length];
+ Array.Copy(publicKey, _publicKey, publicKey.Length);
}
if (publicKeyToken != null)
{
- _PublicKeyToken = new byte[publicKeyToken.Length];
- Array.Copy(publicKeyToken, _PublicKeyToken, publicKeyToken.Length);
+ _publicKeyToken = new byte[publicKeyToken.Length];
+ Array.Copy(publicKeyToken, _publicKeyToken, publicKeyToken.Length);
}
if (version != null)
- _Version = (Version)version.Clone();
-
- _CultureInfo = cultureInfo;
- _HashAlgorithm = hashAlgorithm;
- _VersionCompatibility = versionCompatibility;
- _CodeBase = codeBase;
- _Flags = flags;
- _StrongNameKeyPair = keyPair;
+ _version = (Version)version.Clone();
+
+ _cultureInfo = cultureInfo;
+ _hashAlgorithm = hashAlgorithm;
+ _versionCompatibility = versionCompatibility;
+ _codeBase = codeBase;
+ _flags = flags;
+ _strongNameKeyPair = keyPair;
}
// This call opens and closes the file, but does not add the
DEFINE_CLASS(IMAGE_FILE_MACHINE, Reflection, ImageFileMachine)
DEFINE_CLASS_U(Reflection, AssemblyName, AssemblyNameBaseObject)
-DEFINE_FIELD_U(_Name, AssemblyNameBaseObject, m_pSimpleName)
-DEFINE_FIELD_U(_PublicKey, AssemblyNameBaseObject, m_pPublicKey)
-DEFINE_FIELD_U(_PublicKeyToken, AssemblyNameBaseObject, m_pPublicKeyToken)
-DEFINE_FIELD_U(_CultureInfo, AssemblyNameBaseObject, m_pCultureInfo)
-DEFINE_FIELD_U(_CodeBase, AssemblyNameBaseObject, m_pCodeBase)
-DEFINE_FIELD_U(_Version, AssemblyNameBaseObject, m_pVersion)
-DEFINE_FIELD_U(m_siInfo, AssemblyNameBaseObject, m_siInfo)
-DEFINE_FIELD_U(_HashForControl, AssemblyNameBaseObject, m_HashForControl)
-DEFINE_FIELD_U(_HashAlgorithm, AssemblyNameBaseObject, m_HashAlgorithm)
-DEFINE_FIELD_U(_HashAlgorithmForControl, AssemblyNameBaseObject, m_HashAlgorithmForControl)
-DEFINE_FIELD_U(_VersionCompatibility, AssemblyNameBaseObject, m_VersionCompatibility)
-DEFINE_FIELD_U(_Flags, AssemblyNameBaseObject, m_Flags)
+DEFINE_FIELD_U(_name, AssemblyNameBaseObject, _name)
+DEFINE_FIELD_U(_publicKey, AssemblyNameBaseObject, _publicKey)
+DEFINE_FIELD_U(_publicKeyToken, AssemblyNameBaseObject, _publicKeyToken)
+DEFINE_FIELD_U(_cultureInfo, AssemblyNameBaseObject, _cultureInfo)
+DEFINE_FIELD_U(_codeBase, AssemblyNameBaseObject, _codeBase)
+DEFINE_FIELD_U(_version, AssemblyNameBaseObject, _version)
+DEFINE_FIELD_U(_hashForControl, AssemblyNameBaseObject, _hashForControl)
+DEFINE_FIELD_U(_hashAlgorithm, AssemblyNameBaseObject, _hashAlgorithm)
+DEFINE_FIELD_U(_hashAlgorithmForControl, AssemblyNameBaseObject, _hashAlgorithmForControl)
+DEFINE_FIELD_U(_versionCompatibility, AssemblyNameBaseObject, _versionCompatibility)
+DEFINE_FIELD_U(_flags, AssemblyNameBaseObject, _flags)
DEFINE_CLASS(ASSEMBLY_NAME, Reflection, AssemblyName)
DEFINE_METHOD(ASSEMBLY_NAME, INIT, Init, IM_Str_ArrB_ArrB_Ver_CI_AHA_AVC_Str_ANF_SNKP_RetV)
DEFINE_METHOD(ASSEMBLY_NAME, SET_PROC_ARCH_INDEX, SetProcArchIndex, IM_PEK_IFM_RetV)
// Modifying the order or fields of this object may require other changes to the
// classlib class definition of this object.
- OBJECTREF m_pSimpleName;
- U1ARRAYREF m_pPublicKey;
- U1ARRAYREF m_pPublicKeyToken;
- OBJECTREF m_pCultureInfo;
- OBJECTREF m_pCodeBase;
- OBJECTREF m_pVersion;
- OBJECTREF m_StrongNameKeyPair;
- OBJECTREF m_siInfo;
- U1ARRAYREF m_HashForControl;
- DWORD m_HashAlgorithm;
- DWORD m_HashAlgorithmForControl;
- DWORD m_VersionCompatibility;
- DWORD m_Flags;
+ OBJECTREF _name;
+ U1ARRAYREF _publicKey;
+ U1ARRAYREF _publicKeyToken;
+ OBJECTREF _cultureInfo;
+ OBJECTREF _codeBase;
+ OBJECTREF _version;
+ OBJECTREF _strongNameKeyPair;
+ U1ARRAYREF _hashForControl;
+ DWORD _hashAlgorithm;
+ DWORD _hashAlgorithmForControl;
+ DWORD _versionCompatibility;
+ DWORD _flags;
protected:
AssemblyNameBaseObject() { LIMITED_METHOD_CONTRACT; }
~AssemblyNameBaseObject() { LIMITED_METHOD_CONTRACT; }
public:
- OBJECTREF GetSimpleName() { LIMITED_METHOD_CONTRACT; return m_pSimpleName; }
- U1ARRAYREF GetPublicKey() { LIMITED_METHOD_CONTRACT; return m_pPublicKey; }
- U1ARRAYREF GetPublicKeyToken() { LIMITED_METHOD_CONTRACT; return m_pPublicKeyToken; }
- OBJECTREF GetStrongNameKeyPair() { LIMITED_METHOD_CONTRACT; return m_StrongNameKeyPair; }
- OBJECTREF GetCultureInfo() { LIMITED_METHOD_CONTRACT; return m_pCultureInfo; }
- OBJECTREF GetAssemblyCodeBase() { LIMITED_METHOD_CONTRACT; return m_pCodeBase; }
- OBJECTREF GetVersion() { LIMITED_METHOD_CONTRACT; return m_pVersion; }
- DWORD GetAssemblyHashAlgorithm() { LIMITED_METHOD_CONTRACT; return m_HashAlgorithm; }
- DWORD GetFlags() { LIMITED_METHOD_CONTRACT; return m_Flags; }
- U1ARRAYREF GetHashForControl() { LIMITED_METHOD_CONTRACT; return m_HashForControl;}
- DWORD GetHashAlgorithmForControl() { LIMITED_METHOD_CONTRACT; return m_HashAlgorithmForControl; }
+ OBJECTREF GetSimpleName() { LIMITED_METHOD_CONTRACT; return _name; }
+ U1ARRAYREF GetPublicKey() { LIMITED_METHOD_CONTRACT; return _publicKey; }
+ U1ARRAYREF GetPublicKeyToken() { LIMITED_METHOD_CONTRACT; return _publicKeyToken; }
+ OBJECTREF GetStrongNameKeyPair() { LIMITED_METHOD_CONTRACT; return _strongNameKeyPair; }
+ OBJECTREF GetCultureInfo() { LIMITED_METHOD_CONTRACT; return _cultureInfo; }
+ OBJECTREF GetAssemblyCodeBase() { LIMITED_METHOD_CONTRACT; return _codeBase; }
+ OBJECTREF GetVersion() { LIMITED_METHOD_CONTRACT; return _version; }
+ DWORD GetAssemblyHashAlgorithm() { LIMITED_METHOD_CONTRACT; return _hashAlgorithm; }
+ DWORD GetFlags() { LIMITED_METHOD_CONTRACT; return _flags; }
+ U1ARRAYREF GetHashForControl() { LIMITED_METHOD_CONTRACT; return _hashForControl;}
+ DWORD GetHashAlgorithmForControl() { LIMITED_METHOD_CONTRACT; return _hashAlgorithmForControl; }
};
// VersionBaseObject