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


C# Microsoft.Cci.AsTypeDefinition方法代码示例

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


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

示例1: ResolveType

        private Type ResolveType(
            Cci.ITypeReference typeRef,
            GenericContext genericContext = default(GenericContext),
            TypeBuilder dependentType = null,
            bool valueTypeDependency = false)
        {
            var typeDef = typeRef.AsTypeDefinition(_context);
            if (typeDef != null && IsLocal(typeRef))
            {
                var builder = _typeBuilders[typeDef];
                if (dependentType != null && (!valueTypeDependency || builder.IsValueType))
                {
                    AddDependency(dependentType, builder);
                }

                return builder;
            }

            Type result;
            Cci.IGenericParameterReference genericParamRef;
            Cci.IGenericTypeInstanceReference genericRef;
            Cci.ISpecializedNestedTypeReference specializedNestedRef;
            Cci.INestedTypeReference nestedRef;
            Cci.IArrayTypeReference arrayType;
            Cci.IManagedPointerTypeReference refType;
            Cci.IPointerTypeReference ptrType;
            Cci.INamespaceTypeReference nsType;
            Cci.IModifiedTypeReference modType;

            if ((nsType = typeRef.AsNamespaceTypeReference) != null)
            {
                // cache lookup (no type dependencies to track):
                if (_typeRefs.TryGetValue(typeRef, out result))
                {
                    return result;
                }

                // a namespace type builder would already be found in type builders, so we don't get here:
                Debug.Assert(!IsLocal(typeRef));

                Cci.IUnitReference unitRef = nsType.GetUnit(_context);

                Cci.IAssemblyReference assemblyRef;
                var moduleRef = unitRef as Cci.IModuleReference;
                if (moduleRef != null)
                {
                    if (ReferenceEquals(moduleRef.GetContainingAssembly(_context), _module.GetContainingAssembly(_context)))
                    {
                        throw new NotSupportedException("Ref.Emit limitation: modules not supported");
                    }
                    else
                    {
                        assemblyRef = moduleRef.GetContainingAssembly(_context);
                    }
                }
                else
                {
                    assemblyRef = unitRef as Cci.IAssemblyReference;
                }

                // We only track dependency among type builders so we don't need to track it here.
                result = ResolveType(ResolveAssembly(assemblyRef), nsType);
            }
            else if ((specializedNestedRef = typeRef.AsSpecializedNestedTypeReference) != null)
            {
                Type unspecialized = ResolveType(specializedNestedRef.UnspecializedVersion, genericContext, dependentType, valueTypeDependency);

                // the resulting type doesn't depend on generic arguments if it is not a value type:
                if (valueTypeDependency && !unspecialized.IsValueType)
                {
                    dependentType = null;
                }

                Type[] typeArgs = ResolveGenericArguments(specializedNestedRef, genericContext, dependentType);

                // cache lookup (all type dependencies already established above):
                if (_typeRefs.TryGetValue(typeRef, out result))
                {
                    return result;
                }

                result = unspecialized.MakeGenericType(typeArgs);
            }
            else if ((genericRef = typeRef.AsGenericTypeInstanceReference) != null)
            {
                Type genericType = ResolveType(genericRef.GenericType, genericContext, dependentType, valueTypeDependency);

                // the resulting type doesn't depend on generic arguments if it is not a value type:
                if (valueTypeDependency && !genericType.IsValueType)
                {
                    dependentType = null;
                }

                Type[] typeArgs = ResolveGenericArguments(genericRef, genericContext, dependentType);

                // cache lookup (all type dependencies already established above):
                if (_typeRefs.TryGetValue(typeRef, out result))
                {
                    return result;
                }
//.........这里部分代码省略.........
开发者ID:furesoft,项目名称:roslyn,代码行数:101,代码来源:ReflectionEmitter.cs


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