本文整理汇总了C#中ITypeResolveContext类的典型用法代码示例。如果您正苦于以下问题:C# ITypeResolveContext类的具体用法?C# ITypeResolveContext怎么用?C# ITypeResolveContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ITypeResolveContext类属于命名空间,在下文中一共展示了ITypeResolveContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsReferenceType
public bool? IsReferenceType(ITypeResolveContext context)
{
switch (flags.Data & (FlagReferenceTypeConstraint | FlagValueTypeConstraint)) {
case FlagReferenceTypeConstraint:
return true;
case FlagValueTypeConstraint:
return false;
}
// protect against cyclic dependencies between type parameters
using (var busyLock = BusyManager.Enter(this)) {
if (busyLock.Success) {
foreach (ITypeReference constraintRef in this.Constraints) {
IType constraint = constraintRef.Resolve(context);
ITypeDefinition constraintDef = constraint.GetDefinition();
// While interfaces are reference types, an interface constraint does not
// force the type parameter to be a reference type; so we need to explicitly look for classes here.
if (constraintDef != null && constraintDef.ClassType == ClassType.Class)
return true;
if (constraint is ITypeParameter) {
bool? isReferenceType = constraint.IsReferenceType(context);
if (isReferenceType.HasValue)
return isReferenceType.Value;
}
}
}
}
return null;
}
示例2: Resolve
public IType Resolve(ITypeResolveContext context)
{
string[] parts = typeName.Split('.');
var assemblies = new [] { context.CurrentAssembly }.Concat(context.Compilation.Assemblies);
for (int i = parts.Length - 1; i >= 0; i--) {
string ns = string.Join(".", parts, 0, i);
string name = parts[i];
int topLevelTPC = (i == parts.Length - 1 ? typeParameterCount : 0);
foreach (var asm in assemblies) {
if (asm == null)
continue;
ITypeDefinition typeDef = asm.GetTypeDefinition(new TopLevelTypeName(ns, name, topLevelTPC));
for (int j = i + 1; j < parts.Length && typeDef != null; j++) {
int tpc = (j == parts.Length - 1 ? typeParameterCount : 0);
typeDef = typeDef.NestedTypes.FirstOrDefault(n => n.Name == parts[j] && n.TypeParameterCount == tpc);
}
if (typeDef != null)
return typeDef;
}
}
int idx = typeName.LastIndexOf('.');
if (idx < 0)
return new UnknownType("", typeName, typeParameterCount);
// give back a guessed namespace/type name
return new UnknownType(typeName.Substring(0, idx), typeName.Substring(idx + 1), typeParameterCount);
}
示例3: TypeInference
public TypeInference(ITypeResolveContext context, Conversions conversions = null)
{
if (context == null)
throw new ArgumentNullException("context");
this.context = context;
this.conversions = conversions ?? Conversions.Get(context);
}
示例4: GetAllBaseTypes
/// <summary>
/// Gets all base types.
/// </summary>
/// <remarks>This is the reflexive and transitive closure of <see cref="IType.GetBaseTypes"/>.
/// Note that this method does not return all supertypes - doing so is impossible due to contravariance
/// (and undesirable for covariance as the list could become very large).
/// </remarks>
public static IEnumerable<IType> GetAllBaseTypes(this IType type, ITypeResolveContext context)
{
List<IType> output = new List<IType>();
Stack<ITypeDefinition> activeTypeDefinitions = new Stack<ITypeDefinition>();
CollectAllBaseTypes(type, context, activeTypeDefinitions, output);
return output;
}
示例5: ResolveConstructor
public IMethod ResolveConstructor(ITypeResolveContext context)
{
CSharpResolver r = new CSharpResolver(context);
IType type = attributeType.Resolve(context);
int totalArgumentCount = 0;
if (positionalArguments != null)
totalArgumentCount += positionalArguments.Count;
if (namedCtorArguments != null)
totalArgumentCount += namedCtorArguments.Count;
ResolveResult[] arguments = new ResolveResult[totalArgumentCount];
string[] argumentNames = new string[totalArgumentCount];
int i = 0;
if (positionalArguments != null) {
while (i < positionalArguments.Count) {
IConstantValue cv = positionalArguments[i];
arguments[i] = cv.Resolve(context);
i++;
}
}
if (namedCtorArguments != null) {
foreach (var pair in namedCtorArguments) {
argumentNames[i] = pair.Key;
arguments[i] = pair.Value.Resolve(context);
i++;
}
}
MemberResolveResult mrr = r.ResolveObjectCreation(type, arguments, argumentNames) as MemberResolveResult;
return mrr != null ? mrr.Member as IMethod : null;
}
示例6: Resolve
public IAssembly Resolve(ITypeResolveContext context)
{
IAssembly asm = context.CurrentAssembly;
if (asm == null)
throw new ArgumentException("A reference to the current assembly cannot be resolved in the compilation's global type resolve context.");
return asm;
}
示例7: Resolve
public IAssembly Resolve(ITypeResolveContext context)
{
var project = _solution.Projects.FirstOrDefault(p => p.ProjectId == _projectGuid);
if (project != null)
return project.ProjectContent.Resolve(context);
return null;
}
示例8: CecilResolvedAttribute
public CecilResolvedAttribute(ITypeResolveContext context, UnresolvedAttributeBlob unresolved)
{
this.context = context;
this.blob = unresolved.blob;
this.ctorParameterTypes = unresolved.ctorParameterTypes;
this.attributeType = unresolved.attributeType.Resolve(context);
}
示例9: Resolve
public IAssembly Resolve(ITypeResolveContext context)
{
var project = _solution.Projects.FirstOrDefault(p => string.Equals(p.Title, _projectTitle, StringComparison.OrdinalIgnoreCase));
if (project != null)
return project.ProjectContent.Resolve(context);
return null;
}
示例10: GetValue
public object GetValue(ITypeResolveContext context)
{
if (value is ITypeReference)
return ((ITypeReference)value).Resolve(context);
else
return value;
}
示例11: 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;
}
示例12: ResolveType
IType ITypeReference.Resolve(ITypeResolveContext context)
{
// Strictly speaking, we might have to resolve the type in a nested compilation, similar
// to what we're doing with ConstantExpression.
// However, in almost all cases this will work correctly - if the resulting type is only available in the
// nested compilation and not in this, we wouldn't be able to map it anyways.
var ctx = context as CSharpTypeResolveContext;
if (ctx == null) {
ctx = new CSharpTypeResolveContext(context.CurrentAssembly ?? context.Compilation.MainAssembly, null, context.CurrentTypeDefinition, context.CurrentMember);
}
return ResolveType(new CSharpResolver(ctx));
// A potential issue might be this scenario:
// Assembly 1:
// class A { public class Nested {} }
// Assembly 2: (references asm 1)
// class B : A {}
// Assembly 3: (references asm 1 and 2)
// class C { public B.Nested Field; }
// Assembly 4: (references asm 1 and 3, but not 2):
// uses C.Field;
// Here we would not be able to resolve 'B.Nested' in the compilation of assembly 4, as type B is missing there.
}
示例13: Resolve
public IMember Resolve(ITypeResolveContext context)
{
IType type = typeReference.Resolve(context);
IEnumerable<IMember> members;
if (entityType == EntityType.Method) {
members = type.GetMethods(
m => m.Name == name && m.EntityType == EntityType.Method && m.TypeParameters.Count == typeParameterCount,
GetMemberOptions.IgnoreInheritedMembers);
} else {
members = type.GetMembers(
m => m.Name == name && m.EntityType == entityType,
GetMemberOptions.IgnoreInheritedMembers);
}
var resolvedParameterTypes = parameterTypes.Resolve(context);
foreach (IMember member in members) {
IParameterizedMember parameterizedMember = member as IParameterizedMember;
if (parameterTypes.Count == 0) {
if (parameterizedMember == null || parameterizedMember.Parameters.Count == 0)
return member;
} else if (parameterTypes.Count == parameterizedMember.Parameters.Count) {
bool signatureMatches = true;
for (int i = 0; i < parameterTypes.Count; i++) {
IType type1 = ParameterListComparer.Instance.NormalizeMethodTypeParameters(resolvedParameterTypes[i]);
IType type2 = ParameterListComparer.Instance.NormalizeMethodTypeParameters(parameterizedMember.Parameters[i].Type);
if (!type1.Equals(type2)) {
signatureMatches = false;
break;
}
}
if (signatureMatches)
return member;
}
}
return null;
}
示例14: GetNamedArguments
public IList<KeyValuePair<string, IConstantValue>> GetNamedArguments(ITypeResolveContext context)
{
if (namedArguments != null)
return new ReadOnlyCollection<KeyValuePair<string, IConstantValue>>(namedArguments);
else
return EmptyList<KeyValuePair<string, IConstantValue>>.Instance;
}
示例15: Resolve
ISymbol ISymbolReference.Resolve(ITypeResolveContext context)
{
var type = Resolve(context);
if (type is ITypeDefinition)
return (ISymbol)type;
return null;
}