// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
////////////////////////////////////////////////////////////////////////////////
// [....]
// [....]
//
namespace System.Reflection
{
using System;
using System.Diagnostics.SymbolStore;
using System.Runtime.Remoting;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.IO;
using System.Globalization;
using System.Runtime.Versioning;
using System.Diagnostics.Contracts;
[Serializable]
[Flags]
[System.Runtime.InteropServices.ComVisible(true)]
public enum PortableExecutableKinds
{
NotAPortableExecutableImage = 0x0,
ILOnly = 0x1,
Required32Bit = 0x2,
PE32Plus = 0x4,
Unmanaged32Bit = 0x8,
[ComVisible(false)]
Preferred32Bit = 0x10,
}
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum ImageFileMachine
{
I386 = 0x014c,
IA64 = 0x0200,
AMD64 = 0x8664,
ARM = 0x01c4,
}
[Serializable]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(_Module))]
[System.Runtime.InteropServices.ComVisible(true)]
#pragma warning disable 618
[PermissionSetAttribute(SecurityAction.InheritanceDemand, Unrestricted = true)]
#pragma warning restore 618
public abstract class Module : _Module, ISerializable, ICustomAttributeProvider
{
#region Static Constructor
static Module()
{
__Filters _fltObj;
_fltObj = new __Filters();
FilterTypeName = new TypeFilter(_fltObj.FilterTypeName);
FilterTypeNameIgnoreCase = new TypeFilter(_fltObj.FilterTypeNameIgnoreCase);
}
#endregion
#region Constructor
protected Module()
{
}
#endregion
#region Public Statics
public static readonly TypeFilter FilterTypeName;
public static readonly TypeFilter FilterTypeNameIgnoreCase;
#if !FEATURE_CORECLR
public static bool operator ==(Module left, Module right)
{
if (ReferenceEquals(left, right))
return true;
if ((object)left == null || (object)right == null ||
left is RuntimeModule || right is RuntimeModule)
{
return false;
}
return left.Equals(right);
}
public static bool operator !=(Module left, Module right)
{
return !(left == right);
}
#endif // !FEATURE_CORECLR
#if FEATURE_NETCORE || !FEATURE_CORECLR
public override bool Equals(object o)
{
return base.Equals(o);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
#endif //FEATURE_NETCORE || !FEATURE_CORECLR
#endregion
#region Literals
private const BindingFlags DefaultLookup = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
#endregion
#region object overrides
public override String ToString()
{
return ScopeName;
}
#endregion
public virtual IEnumerable CustomAttributes
{
get
{
return GetCustomAttributesData();
}
}
#region ICustomAttributeProvider Members
public virtual Object[] GetCustomAttributes(bool inherit)
{
throw new NotImplementedException();
}
public virtual Object[] GetCustomAttributes(Type attributeType, bool inherit)
{
throw new NotImplementedException();
}
public virtual bool IsDefined(Type attributeType, bool inherit)
{
throw new NotImplementedException();
}
public virtual IList GetCustomAttributesData()
{
throw new NotImplementedException();
}
#endregion
#region public instances members
public MethodBase ResolveMethod(int metadataToken)
{
return ResolveMethod(metadataToken, null, null);
}
public virtual MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
{
// This API was made virtual in V4. Code compiled against V2 might use
// "call" rather than "callvirt" to call it.
// This makes sure those code still works.
RuntimeModule rtModule = this as RuntimeModule;
if (rtModule != null)
return rtModule.ResolveMethod(metadataToken, genericTypeArguments, genericMethodArguments);
throw new NotImplementedException();
}
public FieldInfo ResolveField(int metadataToken)
{
return ResolveField(metadataToken, null, null);
}
public virtual FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
{
// This API was made virtual in V4. Code compiled against V2 might use
// "call" rather than "callvirt" to call it.
// This makes sure those code still works.
RuntimeModule rtModule = this as RuntimeModule;
if (rtModule != null)
return rtModule.ResolveField(metadataToken, genericTypeArguments, genericMethodArguments);
throw new NotImplementedException();
}
public Type ResolveType(int metadataToken)
{
return ResolveType(metadataToken, null, null);
}
public virtual Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
{
// This API was made virtual in V4. Code compiled against V2 might use
// "call" rather than "callvirt" to call it.
// This makes sure those code still works.
RuntimeModule rtModule = this as RuntimeModule;
if (rtModule != null)
return rtModule.ResolveType(metadataToken, genericTypeArguments, genericMethodArguments);
throw new NotImplementedException();
}
public MemberInfo ResolveMember(int metadataToken)
{
return ResolveMember(metadataToken, null, null);
}
public virtual MemberInfo ResolveMember(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
{
// This API was made virtual in V4. Code compiled against V2 might use
// "call" rather than "callvirt" to call it.
// This makes sure those code still works.
RuntimeModule rtModule = this as RuntimeModule;
if (rtModule != null)
return rtModule.ResolveMember(metadataToken, genericTypeArguments, genericMethodArguments);
throw new NotImplementedException();
}
public virtual byte[] ResolveSignature(int metadataToken)
{
// This API was made virtual in V4. Code compiled against V2 might use
// "call" rather than "callvirt" to call it.
// This makes sure those code still works.
RuntimeModule rtModule = this as RuntimeModule;
if (rtModule != null)
return rtModule.ResolveSignature(metadataToken);
throw new NotImplementedException();
}
public virtual string ResolveString(int metadataToken)
{
// This API was made virtual in V4. Code compiled against V2 might use
// "call" rather than "callvirt" to call it.
// This makes sure those code still works.
RuntimeModule rtModule = this as RuntimeModule;
if (rtModule != null)
return rtModule.ResolveString(metadataToken);
throw new NotImplementedException();
}
public virtual void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
{
// This API was made virtual in V4. Code compiled against V2 might use
// "call" rather than "callvirt" to call it.
// This makes sure those code still works.
RuntimeModule rtModule = this as RuntimeModule;
if (rtModule != null)
rtModule.GetPEKind(out peKind, out machine);
throw new NotImplementedException();
}
public virtual int MDStreamVersion
{
get
{
// This API was made virtual in V4. Code compiled against V2 might use
// "call" rather than "callvirt" to call it.
// This makes sure those code still works.
RuntimeModule rtModule = this as RuntimeModule;
if (rtModule != null)
return rtModule.MDStreamVersion;
throw new NotImplementedException();
}
}
[System.Security.SecurityCritical] // auto-generated_required
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
throw new NotImplementedException();
}
[System.Runtime.InteropServices.ComVisible(true)]
public virtual Type GetType(String className, bool ignoreCase)
{
return GetType(className, false, ignoreCase);
}
[System.Runtime.InteropServices.ComVisible(true)]
public virtual Type GetType(String className) {
return GetType(className, false, false);
}
[System.Runtime.InteropServices.ComVisible(true)]
public virtual Type GetType(String className, bool throwOnError, bool ignoreCase)
{
throw new NotImplementedException();
}
public virtual String FullyQualifiedName
{
#if FEATURE_CORECLR
[System.Security.SecurityCritical] // auto-generated
#endif
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
get
{
throw new NotImplementedException();
}
}
public virtual Type[] FindTypes(TypeFilter filter,Object filterCriteria)
{
Type[] c = GetTypes();
int cnt = 0;
for (int i = 0;i GetCustomAttributesData()
{
return CustomAttributeData.GetCustomAttributesInternal(this);
}
#endregion
#region Public Virtuals
[System.Security.SecurityCritical] // auto-generated_required
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException("info");
}
Contract.EndContractBlock();
UnitySerializationHolder.GetUnitySerializationInfo(info, UnitySerializationHolder.ModuleUnity, this.ScopeName, this.GetRuntimeAssembly());
}
[System.Security.SecuritySafeCritical] // auto-generated
[System.Runtime.InteropServices.ComVisible(true)]
public override Type GetType(String className, bool throwOnError, bool ignoreCase)
{
// throw on null strings regardless of the value of "throwOnError"
if (className == null)
throw new ArgumentNullException("className");
RuntimeType retType = null;
GetType(GetNativeHandle(), className, throwOnError, ignoreCase, JitHelpers.GetObjectHandleOnStack(ref retType));
return retType;
}
[System.Security.SecurityCritical] // auto-generated
internal string GetFullyQualifiedName()
{
String fullyQualifiedName = null;
GetFullyQualifiedName(GetNativeHandle(), JitHelpers.GetStringHandleOnStack(ref fullyQualifiedName));
return fullyQualifiedName;
}
public override String FullyQualifiedName
{
#if FEATURE_CORECLR
[System.Security.SecurityCritical] // auto-generated
#else
[System.Security.SecuritySafeCritical]
#endif
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
get
{
String fullyQualifiedName = GetFullyQualifiedName();
if (fullyQualifiedName != null) {
bool checkPermission = true;
try {
Path.GetFullPathInternal(fullyQualifiedName);
}
catch(ArgumentException) {
checkPermission = false;
}
if (checkPermission) {
new FileIOPermission( FileIOPermissionAccess.PathDiscovery, fullyQualifiedName ).Demand();
}
}
return fullyQualifiedName;
}
}
[System.Security.SecuritySafeCritical] // auto-generated
public override Type[] GetTypes()
{
return GetTypes(GetNativeHandle());
}
#endregion
#region Public Members
public override Guid ModuleVersionId
{
[System.Security.SecuritySafeCritical] // auto-generated
get
{
unsafe
{
Guid mvid;
MetadataImport.GetScopeProps(out mvid);
return mvid;
}
}
}
public override int MetadataToken
{
[System.Security.SecuritySafeCritical] // auto-generated
get
{
return ModuleHandle.GetToken(GetNativeHandle());
}
}
public override bool IsResource()
{
return IsResource(GetNativeHandle());
}
public override FieldInfo[] GetFields(BindingFlags bindingFlags)
{
if (RuntimeType == null)
return new FieldInfo[0];
return RuntimeType.GetFields(bindingFlags);
}
public override FieldInfo GetField(String name, BindingFlags bindingAttr)
{
if (name == null)
throw new ArgumentNullException("name");
if (RuntimeType == null)
return null;
return RuntimeType.GetField(name, bindingAttr);
}
public override MethodInfo[] GetMethods(BindingFlags bindingFlags)
{
if (RuntimeType == null)
return new MethodInfo[0];
return RuntimeType.GetMethods(bindingFlags);
}
public override String ScopeName
{
[System.Security.SecuritySafeCritical] // auto-generated
get
{
string scopeName = null;
GetScopeName(GetNativeHandle(), JitHelpers.GetStringHandleOnStack(ref scopeName));
return scopeName;
}
}
public override String Name
{
[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
[System.Security.SecuritySafeCritical] // auto-generated
get
{
String s = GetFullyQualifiedName();
#if !FEATURE_PAL
int i = s.LastIndexOf('\\');
#else
int i = s.LastIndexOf(System.IO.Path.DirectorySeparatorChar);
#endif
if (i == -1)
return s;
return new String(s.ToCharArray(), i + 1, s.Length - i - 1);
}
}
public override Assembly Assembly
{
[Pure]
get
{
return GetRuntimeAssembly();
}
}
internal RuntimeAssembly GetRuntimeAssembly()
{
return m_runtimeAssembly;
}
internal override ModuleHandle GetModuleHandle()
{
return new ModuleHandle(this);
}
internal RuntimeModule GetNativeHandle()
{
return this;
}
#if FEATURE_X509 && FEATURE_CAS_POLICY
[System.Security.SecuritySafeCritical] // auto-generated
public override System.Security.Cryptography.X509Certificates.X509Certificate GetSignerCertificate()
{
byte[] data = null;
GetSignerCertificate(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref data));
return (data != null) ? new System.Security.Cryptography.X509Certificates.X509Certificate(data) : null;
}
#endif // FEATURE_X509 && FEATURE_CAS_POLICY
#endregion
}
}