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


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

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


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

示例1: ResolveEntryPoint

 public static MethodInfo ResolveEntryPoint(Assembly assembly, Cci.IMethodReference method, EmitContext context)
 {
     var containingType = method.GetContainingType(context);
     Debug.Assert(containingType is Cci.INamespaceTypeReference);
     var type = ResolveType(assembly, (Cci.INamespaceTypeReference)containingType);
     return type.GetMethod(method.Name, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
 }
开发者ID:furesoft,项目名称:roslyn,代码行数:7,代码来源:ReflectionEmitter.cs

示例2: MakeMethodRef

        private MethodRef MakeMethodRef(Cci.IMethodReference methodRef, Cci.ISpecializedMethodReference specializedRef, bool isConstructor)
        {
            Type declaringType = ResolveType(methodRef.GetContainingType(_context));

            MethodBase unspecializedDefinition = null;
            if (specializedRef != null)
            {
                // resolvemethod
                unspecializedDefinition = isConstructor ? ResolveConstructor(specializedRef.UnspecializedVersion) : ResolveMethod(specializedRef.UnspecializedVersion);
            }

            var m = new MethodRef(declaringType, methodRef.Name, GetManagedCallingConvention(methodRef.CallingConvention), unspecializedDefinition, GetExtraParameterTypes(methodRef));

            Type[] genericParameters;
            ParameterInfo[] parameters;
            ParameterInfo returnParameter;

            if (unspecializedDefinition != null)
            {
                if (isConstructor)
                {
                    returnParameter = new SimpleParameterInfo(unspecializedDefinition, 0, typeof(void));
                }
                else
                {
                    returnParameter = ((MethodInfo)unspecializedDefinition).ReturnParameter;
                }

                // TODO(tomat): change containing method?
                genericParameters = unspecializedDefinition.GetGenericArguments();
                parameters = unspecializedDefinition.GetParameters();
            }
            else
            {
                MakeMethodParameters(m, methodRef, out genericParameters, out parameters, out returnParameter);
            }

            m.InitializeParameters(genericParameters, parameters, returnParameter);

            return m;
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:41,代码来源:ReflectionEmitter.cs

示例3: ResolveConstructor

        private MethodBase ResolveConstructor(Cci.IMethodReference methodRef)
        {
            Debug.Assert(!methodRef.IsGeneric);

            // A method ref to a varargs method is always resolved as an entry in the method
            // ref table, never in the method def table, *even if the method is locally declared.*
            // (We could in theory resolve it as a method def if there were no extra arguments,
            // but in practice we do not.)

            var methodDef = (Cci.IMethodDefinition)methodRef.AsDefinition(_context);
            if (methodDef != null && IsLocal(methodRef.GetContainingType(_context)) && !methodRef.AcceptsExtraArguments)
            {
                return _constructorBuilders[methodDef];
            }

            MethodBase result;
            if (_methodRefs.TryGetValue(methodRef, out result))
            {
                return result;
            }

            Debug.Assert(methodRef.AsGenericMethodInstanceReference == null);

            Cci.ISpecializedMethodReference specializedRef = methodRef.AsSpecializedMethodReference;

            if (specializedRef != null &&
                IsLocal(specializedRef.UnspecializedVersion.GetContainingType(_context)))
            {
                // get declaring type (TypeBuilder or TypeBuilderInstantiation since it's defined in the module being built):
                Type declaringType = ResolveType(methodRef.GetContainingType(_context));
                ConstructorBuilder ctorBuilder = _constructorBuilders[(Cci.IMethodDefinition)specializedRef.UnspecializedVersion.AsDefinition(_context)];
                result = TypeBuilder.GetConstructor(declaringType, ctorBuilder);
            }
            else
            {
                result = MakeMethodRef(methodRef, specializedRef, isConstructor: true);
            }

            _methodRefs.Add(methodRef, result);
            return result;
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:41,代码来源:ReflectionEmitter.cs

示例4: ResolveMethod

        private MethodInfo ResolveMethod(Cci.IMethodReference methodRef)
        {
            var methodDef = (Cci.IMethodDefinition)methodRef.AsDefinition(_context);

            // A method ref to a varargs method is always resolved as an entry in the method
            // ref table, never in the method def table, *even if the method is locally declared.*
            // (We could in theory resolve it as a method def if there were no extra arguments,
            // but in practice we do not.)

            if (methodDef != null && IsLocal(methodRef.GetContainingType(_context)) && !methodRef.AcceptsExtraArguments)
            {
                return _methodBuilders[methodDef];
            }

            MethodBase methodBase;
            if (_methodRefs.TryGetValue(methodRef, out methodBase))
            {
                return (MethodInfo)methodBase;
            }

            MethodInfo result;

            Cci.ISpecializedMethodReference specializedRef = methodRef.AsSpecializedMethodReference;
            Cci.IGenericMethodInstanceReference genericRef = methodRef.AsGenericMethodInstanceReference;

            if (specializedRef != null &&
                IsLocal(specializedRef.UnspecializedVersion.GetContainingType(_context)))
            {
                // get declaring type (TypeBuilder or TypeBuilderInstantiation since it's defined in the module being built):
                Type type = ResolveType(specializedRef.GetContainingType(_context));
                MethodBuilder methodBuilder = _methodBuilders[(Cci.IMethodDefinition)specializedRef.UnspecializedVersion.AsDefinition(_context)];
                MethodInfo methodOnTypeBuilder = TypeBuilder.GetMethod(type, methodBuilder);

                if (genericRef != null)
                {
                    Type[] typeArgs = genericRef.GetGenericArguments(_context).Select(arg => ResolveType(arg)).ToArray();
                    result = methodOnTypeBuilder.MakeGenericMethod(typeArgs);
                }
                else
                {
                    result = methodOnTypeBuilder;
                }
            }
            else if (genericRef != null)
            {
                MethodInfo genericMethod = ResolveMethod(genericRef.GetGenericMethod(_context));
                Type[] typeArgs = genericRef.GetGenericArguments(_context).Select((arg) => ResolveType(arg)).ToArray();

                if (genericMethod is MethodRef)
                {
                    result = new MethodSpec(genericMethod, typeArgs);
                }
                else
                {
                    result = genericMethod.MakeGenericMethod(typeArgs);
                }
            }
            else
            {
                result = MakeMethodRef(methodRef, specializedRef, isConstructor: false);
            }

            _methodRefs.Add(methodRef, result);
            return result;
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:65,代码来源:ReflectionEmitter.cs

示例5: ResolveField

        private FieldInfo ResolveField(Cci.IFieldReference fieldRef)
        {
            var fieldDef = fieldRef.GetResolvedField(_context);
            if (fieldDef != null && IsLocal(fieldRef.GetContainingType(_context)))
            {
                return _fieldBuilders[fieldDef];
            }

            FieldInfo result;
            if (_fieldRefs.TryGetValue(fieldRef, out result))
            {
                return result;
            }

            Type declaringType = ResolveType(fieldRef.GetContainingType(_context));
            Cci.ISpecializedFieldReference specializedRef = fieldRef.AsSpecializedFieldReference;

            if (specializedRef != null)
            {
                if (IsLocal(specializedRef.UnspecializedVersion.GetContainingType(_context)))
                {
                    // declaring type is TypeBuilder or TypeBuilderInstantiation since it's defined in the module being built:
                    FieldBuilder fieldBuilder = _fieldBuilders[(Cci.IFieldDefinition)specializedRef.UnspecializedVersion.AsDefinition(_context)];
                    result = TypeBuilder.GetField(declaringType, fieldBuilder);
                }
                else
                {
                    FieldInfo unspecializedDefinition = ResolveField(specializedRef.UnspecializedVersion);
                    result = new FieldRef(declaringType, fieldRef.Name, unspecializedDefinition.FieldType);
                }
            }
            else
            {
                GenericContext genericContext;
                if (declaringType.IsGenericTypeDefinition)
                {
                    genericContext = new GenericContext(declaringType.GetGenericArguments(), Type.EmptyTypes);
                }
                else
                {
                    genericContext = default(GenericContext);
                }

                // TODO: modifiers?
                Type fieldType = ResolveType(fieldRef.GetType(_context), genericContext);
                result = new FieldRef(declaringType, fieldRef.Name, fieldType);
            }

            _fieldRefs.Add(fieldRef, result);
            return result;
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:51,代码来源:ReflectionEmitter.cs

示例6: EmitWorker


//.........这里部分代码省略.........
                    // TODO(tomat): This fails for enum fields if the enum is a nested type in a generic type (TypeBuilderInstantiation throws in IsSubclassOf)
                    fieldBuilder.SetConstant(constant.Value);
                }

                EmitCustomAttributes(fieldBuilder, fieldDef.GetAttributes(_context));
            }

            // define generic parameter custom attributes (needs all types, methods and constructors defined):
            foreach (var genericParameter in _genericParameterBuilders)
            {
                EmitCustomAttributes(genericParameter.Value, ((Cci.IGenericParameter)genericParameter.Key).GetAttributes(_context));
            }

            cancellationToken.ThrowIfCancellationRequested();

            // bodies (IL may need a method token of a generic method, which bakes its generic parameters -> we need to emit generic parameters first)
            foreach (var method in _methodBuilders)
            {
                if (Cci.Extensions.HasBody(method.Key))
                {
                    EmitMethodBody(method.Value, null, method.Key.GetBody(_context));
                }
            }

            foreach (var ctor in _constructorBuilders)
            {
                if (Cci.Extensions.HasBody(ctor.Key))
                {
                    EmitMethodBody(null, ctor.Value, ctor.Key.GetBody(_context));
                }
            }

            // base type, implemented interfaces, generic parameters
            // member relationships, properties, events, custom attributes (needs attribute constructors, all members):
            foreach (var definedType in _typeBuilders)
            {
                FinishType(definedType.Value, definedType.Key);
            }

            // module and assembly attributes:
            EmitCustomAttributes(_builder, _module.ModuleAttributes);
            EmitCustomAttributes((AssemblyBuilder)_builder.Assembly, _module.AssemblyAttributes);

            cancellationToken.ThrowIfCancellationRequested();

            // order types to satisfy dependencies:
            IEnumerable<TypeBuilder> orderedTypeBuilders = OrderTypeBuilders();
            if (orderedTypeBuilders == null)
            {
                throw new NotSupportedException("Ref.Emit limitation: cycle in type dependencies");
            }

            // create types and entry point:
            MethodInfo resolvedEntryPoint = null;
            Type entryPointType = null;
            if (entryPoint != null)
            {
                entryPointType = ResolveType(entryPoint.GetContainingType(_context));
            }

            foreach (var typeBuilder in orderedTypeBuilders)
            {
                Type type = null;

                // TODO (tomat): we should test for features not allowed in a collectible assembly upfront
                // rather than waiting for an exception to happen.
                try
                {
                    type = typeBuilder.CreateType();

                    // TODO (tomat): this is very strange, the TypeLoadException is swallowed when VS debugger is attached
                    // and the execution continues with type == null. See bug DevDiv2\DevDiv bug 391550.
                    if (type == null)
                    {
                        throw new NotSupportedException("Ref.Emit limitation");
                    }
                }
                catch (TypeLoadException e)
                {
                    throw new NotSupportedException("Ref.Emit limitation: " + e.Message);
                }

                if (typeBuilder == entryPointType)
                {
                    resolvedEntryPoint = (MethodInfo)ResolveRuntimeMethodOrConstructor(type, entryPoint, isConstructor: false);
                }

                cancellationToken.ThrowIfCancellationRequested();
            }

            // PE entry point:
            if (_module.EntryPoint != null)
            {
                Debug.Assert(_module.EntryPoint == entryPoint);
                ((AssemblyBuilder)_builder.Assembly).SetEntryPoint(resolvedEntryPoint);
            }

            Debug.Assert(entryPoint == null || resolvedEntryPoint != null);
            return resolvedEntryPoint;
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:101,代码来源:ReflectionEmitter.cs


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