本文整理汇总了C#中ICSharpCode.NRefactory.CSharp.Refactoring.BaseRefactoringContext.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# BaseRefactoringContext.Resolve方法的具体用法?C# BaseRefactoringContext.Resolve怎么用?C# BaseRefactoringContext.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.NRefactory.CSharp.Refactoring.BaseRefactoringContext
的用法示例。
在下文中一共展示了BaseRefactoringContext.Resolve方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HidesMember
protected static bool HidesMember(BaseRefactoringContext ctx, AstNode node, string variableName)
{
var typeDecl = node.GetParent<TypeDeclaration>();
if (typeDecl == null)
return false;
var entityDecl = node.GetParent<EntityDeclaration>();
var memberResolveResult = ctx.Resolve(entityDecl) as MemberResolveResult;
if (memberResolveResult == null)
return false;
var typeResolveResult = ctx.Resolve(typeDecl) as TypeResolveResult;
if (typeResolveResult == null)
return false;
var sourceMember = memberResolveResult.Member;
return typeResolveResult.Type.GetMembers(m => m.Name == variableName).Any(m2 => IsAccessible(sourceMember, m2));
}
示例2: HidesMember
protected static bool HidesMember(BaseRefactoringContext ctx, AstNode node, string variableName)
{
var typeDecl = node.GetParent<TypeDeclaration> ();
if (typeDecl == null)
return false;
var typeResolveResult = ctx.Resolve (typeDecl) as TypeResolveResult;
if (typeResolveResult == null)
return false;
var entityDecl = node.GetParent<EntityDeclaration> ();
var isStatic = (entityDecl.Modifiers & Modifiers.Static) == Modifiers.Static;
return typeResolveResult.Type.GetMembers (m => m.Name == variableName && m.IsStatic == isStatic).Any ();
}
示例3: GuessType
public static IType GuessType(BaseRefactoringContext context, AstNode expr)
{
if (expr is SimpleType && expr.Role == Roles.TypeArgument) {
if (expr.Parent is MemberReferenceExpression || expr.Parent is IdentifierExpression) {
var rr = context.Resolve (expr.Parent);
var argumentNumber = expr.Parent.GetChildrenByRole (Roles.TypeArgument).TakeWhile (c => c != expr).Count ();
var mgrr = rr as MethodGroupResolveResult;
if (mgrr != null && mgrr.Methods.Any () && mgrr.Methods.First ().TypeArguments.Count > argumentNumber)
return mgrr.Methods.First ().TypeParameters[argumentNumber];
} else if (expr.Parent is MemberType || expr.Parent is SimpleType) {
var rr = context.Resolve (expr.Parent);
var argumentNumber = expr.Parent.GetChildrenByRole (Roles.TypeArgument).TakeWhile (c => c != expr).Count ();
var mgrr = rr as TypeResolveResult;
if (mgrr != null && mgrr.Type.TypeParameterCount > argumentNumber) {
return mgrr.Type.GetDefinition ().TypeParameters[argumentNumber];
}
}
}
var type = GetValidTypes(context.Resolver, expr).ToArray();
var typeInference = new TypeInference(context.Compilation);
typeInference.Algorithm = TypeInferenceAlgorithm.Improved;
var inferedType = typeInference.FindTypeInBounds(type, emptyTypes);
return inferedType;
}
示例4: ScanSetter
internal static IField ScanSetter (BaseRefactoringContext context, PropertyDeclaration propertyDeclaration)
{
if (propertyDeclaration.Setter.Body.Statements.Count != 1)
return null;
var setAssignment = propertyDeclaration.Setter.Body.Statements.First () as ExpressionStatement;
var assignment = setAssignment != null ? setAssignment.Expression as AssignmentExpression : null;
if (assignment == null || assignment.Operator != AssignmentOperatorType.Assign)
return null;
var idExpr = assignment.Right as IdentifierExpression;
if (idExpr == null || idExpr.Identifier != "value")
return null;
if (!IsPossibleExpression(assignment.Left))
return null;
var result = context.Resolve (assignment.Left);
if (result == null || !(result is MemberResolveResult))
return null;
return ((MemberResolveResult)result).Member as IField;
}
示例5: ScanGetter
internal static IField ScanGetter (BaseRefactoringContext context, PropertyDeclaration propertyDeclaration)
{
if (propertyDeclaration.Getter.Body.Statements.Count != 1)
return null;
var returnStatement = propertyDeclaration.Getter.Body.Statements.First () as ReturnStatement;
if (returnStatement == null)
return null;
if (!IsPossibleExpression(returnStatement.Expression))
return null;
var result = context.Resolve (returnStatement.Expression);
if (result == null || !(result is MemberResolveResult))
return null;
return ((MemberResolveResult)result).Member as IField;
}
示例6: GetIssues
public override IEnumerable<CodeIssue> GetIssues(BaseRefactoringContext context, string subIssue = null)
{
foreach (var mre in context.RootNode.Descendants.OfType<MemberReferenceExpression>()) {
var rr = context.Resolve(mre);
var mrr = rr as MemberResolveResult;
if (mrr == null)
continue;
switch (mrr.Member.FullName) {
case "ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainWin32Window":
yield return Issue(
mre,
script => {
script.Replace(mre, new IdentifierExpression("SD").Member("WinForms").Member("MainWin32Window"));
});
break;
case "ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.Workbench":
yield return Issue(
mre,
script => {
script.Replace(mre, new IdentifierExpression("SD").Member("Workbench"));
});
break;
case "ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.StatusBar":
yield return Issue(
mre,
script => {
script.Replace(mre, new IdentifierExpression("SD").Member("StatusBar"));
});
break;
case "ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.InvokeRequired":
yield return Issue(
mre,
script => {
script.Replace(mre, new IdentifierExpression("SD").Member("MainThread").Member("InvokeRequired"));
});
break;
case "ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainWindow":
yield return Issue(
mre,
script => {
script.Replace(mre, new IdentifierExpression("SD").Member("Workbench").Member("MainWindow"));
});
break;
}
}
foreach (var invocationExpression in context.RootNode.Descendants.OfType<InvocationExpression>()) {
var rr = context.Resolve(invocationExpression);
var irr = rr as CSharpInvocationResolveResult;
if (irr == null)
continue;
switch (irr.Member.FullName) {
case "ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.CallLater":
yield return Issue(
invocationExpression,
script => {
script.Replace(invocationExpression,
new IdentifierExpression("SD").Member("MainThread").Invoke("CallLater", invocationExpression.Arguments.Select(e => e.Clone())));
});
break;
case "ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.AssertMainThread":
yield return Issue(
invocationExpression,
script => {
script.Replace(invocationExpression,
new IdentifierExpression("SD").Member("MainThread").Invoke("VerifyAccess"));
});
break;
case "ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.SafeThreadAsyncCall":
{
// SD.MainThread.InvokeAsync(argument).FireAndForget();
Expression arg = invocationExpression.Arguments.First().Clone();
if (invocationExpression.Arguments.Count > 1)
arg = new LambdaExpression { Body = arg.Invoke(invocationExpression.Arguments.Skip(1).Select(a => a.Clone())) };
yield return Issue(
invocationExpression,
script => {
script.Replace(invocationExpression,
new IdentifierExpression("SD").Member("MainThread")
.Invoke("InvokeAsyncAndForget", arg));
});
break;
}
case "ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.SafeThreadCall":
case "ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.SafeThreadFunction":
{
// SD.MainThread.InvokeIfRequired(argument);
Expression arg = invocationExpression.Arguments.First().Clone();
if (invocationExpression.Arguments.Count > 1)
arg = new LambdaExpression { Body = arg.Invoke(invocationExpression.Arguments.Skip(1).Select(a => a.Clone())) };
yield return Issue(
invocationExpression,
script => {
script.Replace(invocationExpression,
new IdentifierExpression("SD").Member("MainThread").Invoke("InvokeIfRequired", arg));
});
break;
}
case "ICSharpCode.SharpDevelop.IMessageLoop.InvokeAsync":
// We used to recommend SD.MainThread.InvokeAsync(...).FireAndForget(),
// but it's better to use SD.MainThread.InvokeAsyncAndForget(...)
//.........这里部分代码省略.........