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


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

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


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

示例1: 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

示例2: 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


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