本文整理汇总了C#中ITypeResolveContext.GetTypeDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeResolveContext.GetTypeDefinition方法的具体用法?C# ITypeResolveContext.GetTypeDefinition怎么用?C# ITypeResolveContext.GetTypeDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITypeResolveContext
的用法示例。
在下文中一共展示了ITypeResolveContext.GetTypeDefinition方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
/// <summary>
/// Creates a nullable type.
/// </summary>
public static IType Create(IType elementType, ITypeResolveContext context)
{
if (elementType == null)
throw new ArgumentNullException("elementType");
if (context == null)
throw new ArgumentNullException("context");
ITypeDefinition nullable = context.GetTypeDefinition("System", "Nullable", 1, StringComparer.Ordinal);
if (nullable != null)
return new ParameterizedType(nullable, new [] { elementType });
else
return SharedTypes.UnknownType;
}
示例2: Resolve
public IType Resolve(ITypeResolveContext context)
{
// If both types exist, C# considers that to be an ambiguity, but we are less strict.
IType type = withoutSuffix.Resolve(context);
var attrType = context.GetTypeDefinition (typeof(System.Attribute));
if (attrType == null)
return SharedTypes.UnknownType;
if (type == SharedTypes.UnknownType || !(type.GetDefinition () != null && type.GetDefinition ().IsDerivedFrom (attrType, context)))
type = withSuffix.Resolve(context);
return type;
}
示例3: CachedResult
/*
sealed class CachedResult
{
public readonly CacheManager CacheManager;
public readonly IType Result;
public CachedResult(CacheManager cacheManager, IType result)
{
this.CacheManager = cacheManager;
this.Result = result;
}
}
*/
public IType Resolve(ITypeResolveContext context)
{
if (context == null)
throw new ArgumentNullException("context");
/* TODO PERF: caching disabled until we measure how much of an advantage it is
* (and whether other approaches like caching only the last N resolve calls in a thread-static cache would work better)
* Maybe even make a distinction between the really common type references (e.g. primitiveTypeReferences) and
* normal GetClassTypeReferences?
CacheManager cacheManager = context.CacheManager;
if (cacheManager != null) {
CachedResult result = this.v_cachedResult;
if (result != null && result.CacheManager == cacheManager)
return result.Result;
IType newResult = DoResolve(context);
this.v_cachedResult = new CachedResult(cacheManager, newResult);
cacheManager.Disposed += delegate { v_cachedResult = null; }; // maybe optimize this to use interface call instead of delegate?
return newResult;
} else {
return DoResolve(context);
}
}
IType DoResolve(ITypeResolveContext context)
{
*/
return context.GetTypeDefinition(nameSpace, name, typeParameterCount, StringComparer.Ordinal) ?? SharedTypes.UnknownType;
}
示例4: CachedResult
/*
sealed class CachedResult
{
public readonly CacheManager CacheManager;
public readonly IType Result;
public CachedResult(CacheManager cacheManager, IType result)
{
this.CacheManager = cacheManager;
this.Result = result;
}
}
*/
public IType Resolve(ITypeResolveContext context)
{
if (context == null)
throw new ArgumentNullException("context");
// CacheManager cache = context.CacheManager;
// if (cache != null) {
// IType cachedType = cache.GetShared(this) as IType;
// if (cachedType != null)
// return cachedType;
// }
IType type = context.GetTypeDefinition(nameSpace, name, typeParameterCount, StringComparer.Ordinal) ?? SharedTypes.UnknownType;
// if (cache != null)
// cache.SetShared(this, type);
return type;
}
示例5: GetBaseTypes
public IEnumerable<IType> GetBaseTypes(ITypeResolveContext context)
{
bool hasNonInterfaceConstraint = false;
foreach (ITypeReference constraint in this.Constraints) {
IType c = constraint.Resolve(context);
yield return c;
ITypeDefinition cdef = c.GetDefinition();
if (!(cdef != null && cdef.ClassType == ClassType.Interface))
hasNonInterfaceConstraint = true;
}
// Do not add the 'System.Object' constraint if there is another constraint with a base class.
if (HasValueTypeConstraint || !hasNonInterfaceConstraint) {
IType defaultBaseType = context.GetTypeDefinition("System", HasValueTypeConstraint ? "ValueType" : "Object", 0, StringComparer.Ordinal);
if (defaultBaseType != null)
yield return defaultBaseType;
}
}
示例6: GetNonCircularBaseTypes
// Problem with type parameter resolving - circular declarations
// void Example<S, T> (S s, T t) where S : T where T : S
IEnumerable<IType> GetNonCircularBaseTypes(ITypeResolveContext context)
{
var result = this.GetBaseTypes(context).Where(bt => !IsCircular (context, bt));
if (result.Any ())
return result;
// result may be empty, GetBaseTypes doesn't return object/struct when there are only constraints (even circular) as base types are available,
// but even when there are only circular references the default base type should be included.
IType defaultBaseType = context.GetTypeDefinition("System", HasValueTypeConstraint ? "ValueType" : "Object", 0, StringComparer.Ordinal);
if (defaultBaseType != null)
return new [] { defaultBaseType };
return Enumerable.Empty<IType> ();
}