本文整理汇总了C#中ITypeResolveContext.GetClass方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeResolveContext.GetClass方法的具体用法?C# ITypeResolveContext.GetClass怎么用?C# ITypeResolveContext.GetClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITypeResolveContext
的用法示例。
在下文中一共展示了ITypeResolveContext.GetClass方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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.GetClass(nameSpace, name, typeParameterCount, StringComparer.Ordinal) ?? SharedTypes.UnknownType;
}
示例2: 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.GetClass("System", "Nullable", 1, StringComparer.Ordinal);
if (nullable != null)
return new ParameterizedType(nullable, new [] { elementType });
else
return SharedTypes.UnknownType;
}
示例3: GetBaseTypes
public IEnumerable<IType> GetBaseTypes(ITypeResolveContext context)
{
IType defaultBaseType = context.GetClass("System", HasValueTypeConstraint ? "ValueType" : "Object", 0, StringComparer.Ordinal);
if (defaultBaseType != null)
yield return defaultBaseType;
foreach (ITypeReference constraint in this.Constraints) {
yield return constraint.Resolve(context);
}
}
示例4: GetMethods
public IEnumerable<IMethod> GetMethods(ITypeResolveContext context, Predicate<IMethod> filter = null)
{
// TODO: get methods from constraints
IType objectType = context.GetClass("System", "Object", 0, StringComparer.Ordinal);
IEnumerable<IMethod> objectMethods;
if (objectType != null)
objectMethods = objectType.GetMethods(context, filter);
else
objectMethods = EmptyList<IMethod>.Instance;
// don't return static methods (those cannot be called from type parameter)
return objectMethods.Where(m => !m.IsStatic);
}