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


C# ITypeInfo.Resolve方法代码示例

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


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

示例1: GetAttributeUsage

        internal AttributeUsageAttribute GetAttributeUsage(ITypeInfo attributeType)
        {
            return attributeUsageMemoizer.Memoize(attributeType, () =>
            {
                if (attributeType.FullName == @"System.AttributeUsageAttribute")
                {
                    // Note: Avoid indefinite recursion when determining whether AttributeUsageAttribute itself is inheritable.
                    return new AttributeUsageAttribute(AttributeTargets.Class)
                    {
                        Inherited = true
                    };
                }

                Type resolvedAttributeType = attributeType.Resolve(false);
                if (! Reflector.IsUnresolved(resolvedAttributeType))
                {
                    // We use the resolved type when possible primarily because ReSharper's Metadata reflection
                    // policy cannot resolve types in System and mscorlib which causes problems ironically when
                    // trying to resolve AttributeUsageAttribute itself.  However this is also a useful optimization
                    // in the case where the type can be resolved. -- Jeff.
                    var attributeUsages = (AttributeUsageAttribute[]) resolvedAttributeType.GetCustomAttributes(
                        typeof(AttributeUsageAttribute), true);

                    if (attributeUsages.Length != 0)
                        return attributeUsages[0];
                }
                else
                {
                    try
                    {
                        var attributeUsage = AttributeUtils.GetAttribute<AttributeUsageAttribute>(attributeType, true);
                        if (attributeUsage != null)
                            return attributeUsage;
                    }
                    catch (TargetParameterCountException)
                    {
                        // This is a hack to work around the fact that ReSharper does not correctly handle
                        // attribute parameters with enum values.  In particular, this affects the first
                        // parameter of AttributeUsageAttribute. -- Jeff.
                        return new AttributeUsageAttribute(AttributeTargets.All)
                        {
                            Inherited = true,
                            AllowMultiple = true
                        };
                    }
                }

                return new AttributeUsageAttribute(AttributeTargets.All)
                {
                    Inherited = true
                };
            });
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:53,代码来源:StaticReflectionPolicy.cs

示例2: CreateFixtureType

        private Type CreateFixtureType(ITypeInfo type)
        {
            var resolvedType = type.Resolve(false);
            if (resolvedType.IsClass)
            {
                ConstructorInfo constructor = resolvedType.GetConstructor(Type.EmptyTypes);

                if (constructor != null)
                {
                    return resolvedType;
                }
            }

            throw new InvalidOperationException("Cannot create the fixture");
        }
开发者ID:ElviraH,项目名称:concordion-net,代码行数:15,代码来源:ConcordionTestExplorer.cs

示例3: BuildNUnitFixturesFromType

        private void BuildNUnitFixturesFromType(ITypeInfo type)
        {
            try
            {
                // Note: This code takes advantage of the fact that ITypeInfo.Resolve will
                //       return an UnresolvedType object which adapts ITypeInfo to Type in a
                //       way that enables the native NUnit builders to perform the needed
                //       reflection in most cases.
                Type resolvedType = type.Resolve(false);

                if (NUnit.Core.TestFixtureBuilder.CanBuildFrom(resolvedType))
                {
                    var nunitFixture = (NUnit.Core.TestSuite) NUnit.Core.TestFixtureBuilder.BuildFrom(resolvedType);
                    nunitFixtures.Add(nunitFixture);
                }
            }
            catch (Exception ex)
            {
                testModel.AddAnnotation(new Annotation(AnnotationType.Error, type,
                    "An exception was thrown while exploring an NUnit test type.  This probably indicates that the type uses certain NUnit features that are not supported by the reflection-only test explorer engine.", ex));
            }
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:22,代码来源:NUnitReflectiveTestExplorerEngine.cs

示例4: ResolveType

 public static Type ResolveType(ITypeInfo type)
 {
     return type != null ? type.Resolve(false) : null;
 }
开发者ID:rprouse,项目名称:mbunit-v3,代码行数:4,代码来源:UnresolvedMemberInfo.cs

示例5: ResolveTypeWithMethodContext

 private static Type ResolveTypeWithMethodContext(ITypeInfo type, MethodInfo methodContext)
 {
     IResolvableTypeInfo resolvableType = type as IResolvableTypeInfo;
     return resolvableType != null ? resolvableType.Resolve(methodContext, true) : type.Resolve(true);
 }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:5,代码来源:ReflectorResolveUtils.cs


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