本文整理汇总了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
};
});
}
示例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");
}
示例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));
}
}
示例4: ResolveType
public static Type ResolveType(ITypeInfo type)
{
return type != null ? type.Resolve(false) : null;
}
示例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);
}