当前位置: 首页>>代码示例>>C#>>正文


C# BaseRefactoringContext.Resolve方法代码示例

本文整理汇总了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));
        }
开发者ID:segaman,项目名称:NRefactory,代码行数:17,代码来源:VariableHidesMemberIssue.cs

示例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 ();
		}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:14,代码来源:VariableHidesMemberIssue.cs

示例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;
        }
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:26,代码来源:TypeGuessing.cs

示例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;
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:18,代码来源:RemoveBackingStoreAction.cs

示例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;
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:14,代码来源:RemoveBackingStoreAction.cs

示例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(...)
//.........这里部分代码省略.........
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:101,代码来源:WorkbenchSingletonIssueProvider.cs


注:本文中的ICSharpCode.NRefactory.CSharp.Refactoring.BaseRefactoringContext.Resolve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。