本文整理汇总了C#中ITypeResolveContext.WithCurrentMember方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeResolveContext.WithCurrentMember方法的具体用法?C# ITypeResolveContext.WithCurrentMember怎么用?C# ITypeResolveContext.WithCurrentMember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITypeResolveContext
的用法示例。
在下文中一共展示了ITypeResolveContext.WithCurrentMember方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnknownCodeContext
public UnknownCodeContext(ICompilation compilation, IUnresolvedFile file, TextLocation location)
: this(compilation)
{
var curDef = file.GetInnermostTypeDefinition (location);
if (curDef != null) {
var resolvedDef = curDef.Resolve (context).GetDefinition ();
if (resolvedDef != null) {
context = context.WithCurrentTypeDefinition (resolvedDef);
var curMember = resolvedDef.Members.FirstOrDefault (m => m.Region.FileName == file.FileName && m.Region.Begin <= location && location < m.BodyRegion.End);
if (curMember != null)
context = context.WithCurrentMember (curMember);
}
}
}
示例2: Resolve
public static IMember Resolve(ITypeResolveContext context,
EntityType entityType,
string name,
ITypeReference explicitInterfaceTypeReference = null,
IList<string> typeParameterNames = null,
IList<ITypeReference> parameterTypeReferences = null)
{
if (context.CurrentTypeDefinition == null)
return null;
if (parameterTypeReferences == null)
parameterTypeReferences = EmptyList<ITypeReference>.Instance;
if (typeParameterNames == null || typeParameterNames.Count == 0) {
// non-generic member
// In this case, we can simply resolve the parameter types in the given context
var parameterTypes = parameterTypeReferences.Resolve(context);
if (explicitInterfaceTypeReference == null) {
foreach (IMember member in context.CurrentTypeDefinition.Members) {
if (member.IsExplicitInterfaceImplementation)
continue;
if (IsNonGenericMatch(member, entityType, name, parameterTypes))
return member;
}
} else {
IType explicitInterfaceType = explicitInterfaceTypeReference.Resolve(context);
foreach (IMember member in context.CurrentTypeDefinition.Members) {
if (!member.IsExplicitInterfaceImplementation)
continue;
if (member.ImplementedInterfaceMembers.Count != 1)
continue;
if (IsNonGenericMatch(member, entityType, name, parameterTypes)) {
if (explicitInterfaceType.Equals(member.ImplementedInterfaceMembers[0].DeclaringType))
return member;
}
}
}
} else {
// generic member
// In this case, we must specify the correct context for resolving the parameter types
foreach (IMethod method in context.CurrentTypeDefinition.Methods) {
if (method.EntityType != entityType)
continue;
if (method.Name != name)
continue;
if (method.Parameters.Count != parameterTypeReferences.Count)
continue;
// Compare type parameter count and names:
if (!typeParameterNames.SequenceEqual(method.TypeParameters.Select(tp => tp.Name)))
continue;
// Once we know the type parameter names are fitting, we can resolve the
// type references in the context of the method:
var contextForMethod = context.WithCurrentMember(method);
var parameterTypes = parameterTypeReferences.Resolve(contextForMethod);
if (!IsParameterTypeMatch(method, parameterTypes))
continue;
if (explicitInterfaceTypeReference == null) {
if (!method.IsExplicitInterfaceImplementation)
return method;
} else if (method.IsExplicitInterfaceImplementation && method.ImplementedInterfaceMembers.Count == 1) {
IType explicitInterfaceType = explicitInterfaceTypeReference.Resolve(contextForMethod);
if (explicitInterfaceType.Equals(method.ImplementedInterfaceMembers[0].DeclaringType))
return method;
}
}
}
return null;
}
示例3: AbstractResolvedMember
protected AbstractResolvedMember(IUnresolvedMember unresolved, ITypeResolveContext parentContext)
: base(unresolved, parentContext)
{
this.unresolved = unresolved;
this.context = parentContext.WithCurrentMember(this);
}