Module.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Reflection / Module.cs / 1305376 / Module.cs

                            // ==++== 
//
//   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,
    } 
 
    [Serializable]
[System.Runtime.InteropServices.ComVisible(true)] 
    public enum ImageFileMachine
    {
        I386    = 0x014c,
 
        IA64    = 0x0200,
 
        AMD64   = 0x8664, 
    }
 
    [Serializable]
    [ClassInterface(ClassInterfaceType.None)]
    [ComDefaultInterface(typeof(_Module))]
    [System.Runtime.InteropServices.ComVisible(true)] 
    [PermissionSetAttribute(SecurityAction.InheritanceDemand, Unrestricted = true)]
    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); 
        }

        public override bool Equals(object o)
        { 
            return base.Equals(o);
        } 
 
        public override int GetHashCode()
        { 
            return base.GetHashCode();
        }
#endif // !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 
 
        #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
        {
            [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
        { 
            [System.Security.SecuritySafeCritical]  // auto-generated
            [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()); 
            }
        } 
 
        [System.Security.SecuritySafeCritical]  // auto-generated
        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_PAL && 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_PAL && FEATURE_X509 && FEATURE_CAS_POLICY 
        #endregion
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK