当前位置: 首页>>代码示例>>C#>>正文


C# RuntimeModule.ResolveType方法代码示例

本文整理汇总了C#中System.Reflection.RuntimeModule.ResolveType方法的典型用法代码示例。如果您正苦于以下问题:C# RuntimeModule.ResolveType方法的具体用法?C# RuntimeModule.ResolveType怎么用?C# RuntimeModule.ResolveType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.RuntimeModule的用法示例。


在下文中一共展示了RuntimeModule.ResolveType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FilterCustomAttributeRecord

 private static unsafe bool FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, ref Assembly lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, bool mustBeInheritable, object[] attributes, IList derivedAttributes, out RuntimeType attributeType, out IRuntimeMethodInfo ctor, out bool ctorHasParameters, out bool isVarArg)
 {
     ctor = null;
     attributeType = null;
     ctorHasParameters = false;
     isVarArg = false;
     IntPtr ptr1 = (IntPtr) (((void*) caRecord.blob.Signature) + caRecord.blob.Length);
     attributeType = decoratedModule.ResolveType(scope.GetParentToken((int) caRecord.tkCtor), null, null) as RuntimeType;
     if (!attributeFilterType.IsAssignableFrom(attributeType))
     {
         return false;
     }
     if (!AttributeUsageCheck(attributeType, mustBeInheritable, attributes, derivedAttributes))
     {
         return false;
     }
     RuntimeAssembly targetAssembly = (RuntimeAssembly) attributeType.Assembly;
     RuntimeAssembly assembly = (RuntimeAssembly) decoratedModule.Assembly;
     if ((targetAssembly != lastAptcaOkAssembly) && !RuntimeAssembly.AptcaCheck(targetAssembly, assembly))
     {
         return false;
     }
     lastAptcaOkAssembly = assembly;
     ConstArray methodSignature = scope.GetMethodSignature(caRecord.tkCtor);
     isVarArg = (methodSignature[0] & 5) != 0;
     ctorHasParameters = methodSignature[1] != 0;
     if (ctorHasParameters)
     {
         ctor = ModuleHandle.ResolveMethodHandleInternal(decoratedModule.GetNativeHandle(), (int) caRecord.tkCtor);
     }
     else
     {
         ctor = attributeType.GetTypeHandleInternal().GetDefaultConstructor();
         if ((ctor == null) && !attributeType.IsValueType)
         {
             throw new MissingMethodException(".ctor");
         }
     }
     if (ctor == null)
     {
         if (!attributeType.IsVisible && !attributeType.TypeHandle.IsVisibleFromModule(decoratedModule))
         {
             return false;
         }
         return true;
     }
     if (RuntimeMethodHandle.IsVisibleFromModule(ctor, decoratedModule))
     {
         return true;
     }
     MetadataToken token = new MetadataToken();
     if (decoratedToken.IsParamDef)
     {
         token = new MetadataToken(scope.GetParentToken((int) decoratedToken));
         token = new MetadataToken(scope.GetParentToken((int) token));
     }
     else if ((decoratedToken.IsMethodDef || decoratedToken.IsProperty) || (decoratedToken.IsEvent || decoratedToken.IsFieldDef))
     {
         token = new MetadataToken(scope.GetParentToken((int) decoratedToken));
     }
     else if (decoratedToken.IsTypeDef)
     {
         token = decoratedToken;
     }
     return (token.IsTypeDef && RuntimeMethodHandle.IsVisibleFromType(ctor, decoratedModule.ModuleHandle.ResolveTypeHandle((int) token)));
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:66,代码来源:CustomAttribute.cs

示例2: FilterCustomAttributeRecord

        [System.Security.SecurityCritical]  // auto-generated
        private unsafe static bool FilterCustomAttributeRecord(
            CustomAttributeRecord caRecord,
            MetadataImport scope,
            ref Assembly lastAptcaOkAssembly, 
            RuntimeModule decoratedModule,
            MetadataToken decoratedToken,
            RuntimeType attributeFilterType,
            bool mustBeInheritable,
            object[] attributes,
            IList derivedAttributes,
            out RuntimeType attributeType,
            out IRuntimeMethodInfo ctor,
            out bool ctorHasParameters,
            out bool isVarArg)
        {
            ctor = null;
            attributeType = null;
            ctorHasParameters = false;
            isVarArg = false;
            
            IntPtr blobStart = caRecord.blob.Signature;
            IntPtr blobEnd = (IntPtr)((byte*)blobStart + caRecord.blob.Length);

#if FEATURE_LEGACYNETCF
            if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8) {
                try
                {
                    // Resolve attribute type from ctor parent token found in decorated decoratedModule scope
                    attributeType = decoratedModule.ResolveType(scope.GetParentToken(caRecord.tkCtor), null, null) as RuntimeType;
                }
                catch(Exception)
                {
                    return false;
                }
            }
            else
#endif
            // Resolve attribute type from ctor parent token found in decorated decoratedModule scope
            attributeType = decoratedModule.ResolveType(scope.GetParentToken(caRecord.tkCtor), null, null) as RuntimeType;


            // Test attribute type against user provided attribute type filter
            if (!(attributeFilterType.IsAssignableFrom(attributeType)))
                return false;

            // Ensure if attribute type must be inheritable that it is inhertiable
            // Ensure that to consider a duplicate attribute type AllowMultiple is true
            if (!AttributeUsageCheck(attributeType, mustBeInheritable, attributes, derivedAttributes))
                return false;

            // Windows Runtime attributes aren't real types - they exist to be read as metadata only, and as such
            // should be filtered out of the GetCustomAttributes path.
            if ((attributeType.Attributes & TypeAttributes.WindowsRuntime) == TypeAttributes.WindowsRuntime)
            {
                return false;
            }

#if FEATURE_APTCA
            // APTCA checks
            RuntimeAssembly attributeAssembly = (RuntimeAssembly)attributeType.Assembly;
            RuntimeAssembly decoratedModuleAssembly = (RuntimeAssembly)decoratedModule.Assembly;

            if (attributeAssembly != lastAptcaOkAssembly && 
                !RuntimeAssembly.AptcaCheck(attributeAssembly, decoratedModuleAssembly))
                return false;

            // Cache last successful APTCA check (optimization)
            lastAptcaOkAssembly = decoratedModuleAssembly;
#endif // FEATURE_APTCA

            // Resolve the attribute ctor
            ConstArray ctorSig = scope.GetMethodSignature(caRecord.tkCtor);
            isVarArg = (ctorSig[0] & 0x05) != 0;
            ctorHasParameters = ctorSig[1] != 0;

            if (ctorHasParameters)
            {
                // Resolve method ctor token found in decorated decoratedModule scope
                ctor = ModuleHandle.ResolveMethodHandleInternal(decoratedModule.GetNativeHandle(), caRecord.tkCtor);
            }
            else
            {
                // Resolve method ctor token from decorated decoratedModule scope
                ctor = attributeType.GetTypeHandleInternal().GetDefaultConstructor();

                if (ctor == null && !attributeType.IsValueType)
                    throw new MissingMethodException(".ctor");
            }

            // Visibility checks
            MetadataToken tkParent = new MetadataToken();
                
            if (decoratedToken.IsParamDef)
            {
                tkParent = new MetadataToken(scope.GetParentToken(decoratedToken));
                tkParent = new MetadataToken(scope.GetParentToken(tkParent));
            }               
            else if (decoratedToken.IsMethodDef || decoratedToken.IsProperty || decoratedToken.IsEvent || decoratedToken.IsFieldDef) 
            {
//.........这里部分代码省略.........
开发者ID:enavro,项目名称:coreclr,代码行数:101,代码来源:CustomAttribute.cs

示例3: FilterCustomAttributeRecord

        [System.Security.SecurityCritical]  // auto-generated 
        private unsafe static bool FilterCustomAttributeRecord(
            CustomAttributeRecord caRecord, MetadataImport scope, ref Assembly lastAptcaOkAssembly, 
            RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, bool mustBeInheritable,
            object[] attributes, IList derivedAttributes,
            out RuntimeType attributeType, out IRuntimeMethodInfo ctor, out bool ctorHasParameters, out bool isVarArg)
        { 
            ctor = null;
            attributeType = null; 
            ctorHasParameters = false; 
            isVarArg = false;
 
            IntPtr blobStart = caRecord.blob.Signature;
            IntPtr blobEnd = (IntPtr)((byte*)blobStart + caRecord.blob.Length);

            // Resolve attribute type from ctor parent token found in decorated decoratedModule scope 
            attributeType = decoratedModule.ResolveType(scope.GetParentToken(caRecord.tkCtor), null, null) as RuntimeType;
 
            // Test attribute type against user provided attribute type filter 
            if (!(attributeFilterType.IsAssignableFrom(attributeType)))
                return false; 

            // Ensure if attribute type must be inheritable that it is inhertiable
            // Ensure that to consider a duplicate attribute type AllowMultiple is true
            if (!AttributeUsageCheck(attributeType, mustBeInheritable, attributes, derivedAttributes)) 
                return false;
 
#if FEATURE_APTCA 
            // APTCA checks
            RuntimeAssembly attributeAssembly = (RuntimeAssembly)attributeType.Assembly; 
            RuntimeAssembly decoratedModuleAssembly = (RuntimeAssembly)decoratedModule.Assembly;

            if (attributeAssembly != lastAptcaOkAssembly &&
                !RuntimeAssembly.AptcaCheck(attributeAssembly, decoratedModuleAssembly)) 
                return false;
 
            // Cache last successful APTCA check (optimization) 
            lastAptcaOkAssembly = decoratedModuleAssembly;
#endif // FEATURE_APTCA 

            // Resolve the attribute ctor
            ConstArray ctorSig = scope.GetMethodSignature(caRecord.tkCtor);
            isVarArg = (ctorSig[0] & 0x05) != 0; 
            ctorHasParameters = ctorSig[1] != 0;
 
            if (ctorHasParameters) 
            {
                // Resolve method ctor token found in decorated decoratedModule scope 
                ctor = ModuleHandle.ResolveMethodHandleInternal(decoratedModule.GetNativeHandle(), caRecord.tkCtor);
            }
            else
            { 
                // Resolve method ctor token from decorated decoratedModule scope
                ctor = attributeType.GetTypeHandleInternal().GetDefaultConstructor(); 
 
                if (ctor == null && !attributeType.IsValueType)
                    throw new MissingMethodException(".ctor"); 
            }

            // Visibility checks
            if (ctor == null) 
            {
                if (!attributeType.IsVisible && !attributeType.TypeHandle.IsVisibleFromModule(decoratedModule)) 
                    return false; 

                return true; 
            }

            if (RuntimeMethodHandle.IsVisibleFromModule(ctor, decoratedModule))
                return true; 

            MetadataToken tkParent = new MetadataToken(); 
 
            if (decoratedToken.IsParamDef)
            { 
                tkParent = new MetadataToken(scope.GetParentToken(decoratedToken));
                tkParent = new MetadataToken(scope.GetParentToken(tkParent));
            }
            else if (decoratedToken.IsMethodDef || decoratedToken.IsProperty || decoratedToken.IsEvent || decoratedToken.IsFieldDef) 
            {
                tkParent = new MetadataToken(scope.GetParentToken(decoratedToken)); 
            } 
            else if (decoratedToken.IsTypeDef)
            { 
                tkParent = decoratedToken;
            }

            if (tkParent.IsTypeDef) 
                return RuntimeMethodHandle.IsVisibleFromType(ctor, decoratedModule.ModuleHandle.ResolveTypeHandle(tkParent));
 
            return false; 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:92,代码来源:CustomAttribute.cs


注:本文中的System.Reflection.RuntimeModule.ResolveType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。