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


C# Ast.LocalVariableDeclaration类代码示例

本文整理汇总了C#中ICSharpCode.NRefactory.Ast.LocalVariableDeclaration的典型用法代码示例。如果您正苦于以下问题:C# LocalVariableDeclaration类的具体用法?C# LocalVariableDeclaration怎么用?C# LocalVariableDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LocalVariableDeclaration类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了LocalVariableDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: add_Variable

 public static VariableDeclaration add_Variable(this BlockStatement blockDeclaration, string name, Expression expression, TypeReference typeReference)
 {
     var variableDeclaration = new VariableDeclaration(name, expression) {TypeReference = typeReference};
     var localVariableDeclaration = new LocalVariableDeclaration(variableDeclaration);
     blockDeclaration.append(localVariableDeclaration);
     return variableDeclaration;
 }
开发者ID:SiGhTfOrbACQ,项目名称:O2.Platform.Projects,代码行数:7,代码来源:VariableDeclaration_ExtensionMethods.cs

示例2: VisitLocalVariableDeclaration

            public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
            {
                if (localVariableDeclaration.TypeReference.IsArrayType)
                {
                    if (localVariableDeclaration.Variables.Count > 0)
                    {
                        var decl = localVariableDeclaration.Variables[0] as VariableDeclaration;
                        if (decl != null)
                        {
                            if (decl.Initializer is CollectionInitializerExpression)
                            {
                                UnlockWith(localVariableDeclaration);
                            }
                            else if (decl.Initializer is ArrayCreateExpression)
                            {
                                ArrayCreateExpression decl2 = decl.Initializer as ArrayCreateExpression;
                                if (decl2.ArrayInitializer is CollectionInitializerExpression && decl2.ArrayInitializer.CreateExpressions.Count > 0)
                                {
                                    UnlockWith(decl2.ArrayInitializer);
                                }
                            }
                        }
                    }
                }

                return base.VisitLocalVariableDeclaration(localVariableDeclaration, data);
            }
开发者ID:timdams,项目名称:strokes,代码行数:27,代码来源:ArrayDeclarateInitAchievement.cs

示例3: VisitLocalVariableDeclaration

 public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
 {
     base.VisitLocalVariableDeclaration(localVariableDeclaration, data);
     if ((localVariableDeclaration.Modifier & Modifiers.Static) == Modifiers.Static) {
         INode parent = localVariableDeclaration.Parent;
         while (parent != null && !IsTypeLevel(parent)) {
             parent = parent.Parent;
         }
         if (parent != null) {
             INode type = parent.Parent;
             if (type != null) {
                 int pos = type.Children.IndexOf(parent);
                 if (pos >= 0) {
                     FieldDeclaration field = new FieldDeclaration(null);
                     field.TypeReference = localVariableDeclaration.TypeReference;
                     field.Modifier = Modifiers.Static;
                     field.Fields = localVariableDeclaration.Variables;
                     new PrefixFieldsVisitor(field.Fields, "static_" + GetTypeLevelEntityName(parent) + "_").Run(parent);
                     type.Children.Insert(pos + 1, field);
                     RemoveCurrentNode();
                 }
             }
         }
     }
     return null;
 }
开发者ID:almazik,项目名称:ILSpy,代码行数:26,代码来源:ToCSharpConvertVisitor.cs

示例4: VisitLocalVariableDeclaration

            public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
            {
                //Tim= not so happy about hardocing this RankSpecifier, not sure when this specifier contains more than 1 element
                if (localVariableDeclaration.TypeReference.IsArrayType && localVariableDeclaration.TypeReference.RankSpecifier[0]>=1)
                    UnlockWith(localVariableDeclaration);

                return base.VisitLocalVariableDeclaration(localVariableDeclaration, data);
            }
开发者ID:timdams,项目名称:strokes,代码行数:8,代码来源:MultipleDimensionArrayDeclarationAchievement.cs

示例5: VisitLocalVariableDeclaration

 public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
 {
     if ((localVariableDeclaration.Modifier & Modifiers.Const) == Modifiers.Const)
     {
         UnlockWith(localVariableDeclaration);
     }
     return base.VisitLocalVariableDeclaration(localVariableDeclaration, data);
 }
开发者ID:timdams,项目名称:strokes,代码行数:8,代码来源:ConstKeywordAchievement.cs

示例6: VisitLocalVariableDeclaration

            public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
            {
                if (localVariableDeclaration.TypeReference.ToString().Equals("Thread") ||
                    localVariableDeclaration.TypeReference.ToString().Equals("Threading.Thread"))
                {
                    UnlockWith(localVariableDeclaration);
                }

                return base.VisitLocalVariableDeclaration(localVariableDeclaration, data);
            }
开发者ID:timdams,项目名称:strokes,代码行数:10,代码来源:CreateThreadAchievement.cs

示例7: VisitLocalVariableDeclaration

 public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
 {
     foreach (var vd in localVariableDeclaration.Variables)
     {
         if (RenameTable.ContainsKey(vd.Name))
         {
             vd.Name = RenameTable[vd.Name];
         }
     }
     return base.VisitLocalVariableDeclaration(localVariableDeclaration, data);
 }
开发者ID:Adam-Fogle,项目名称:agentralphplugin,代码行数:11,代码来源:RenameLocalVariableRefactoring.cs

示例8: GetVariableNameFromVariableDeclaration

		string GetVariableNameFromVariableDeclaration(LocalVariableDeclaration declaration)
		{
			if (declaration == null)
				return null;
			if (declaration.Variables.Count != 1)
				return null;
			VariableDeclaration varDecl = declaration.Variables[0];
			if (!varDecl.Initializer.IsNull &&
			    // don't offer action for "var a = new Foo()"
			    !(varDecl.Initializer is ObjectCreateExpression))
				return varDecl.Name;
			return null;
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:13,代码来源:CheckAssignmentCache.cs

示例9: VisitLocalVariableDeclaration

 public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration,
                                                      object data)
 {
     if (localVariableDeclaration.TypeReference.Type.Contains("System.Double")
         || localVariableDeclaration.TypeReference.Type.Contains("System.Float")
         || localVariableDeclaration.TypeReference.Type.Contains("System.Decimal"))
     {
         foreach (VariableDeclaration variableDeclaration in localVariableDeclaration.Variables)
         {
             _doublefloatvariables.Add(variableDeclaration.Name);
         }
     }
     return base.VisitLocalVariableDeclaration(localVariableDeclaration, data);
 }
开发者ID:timdams,项目名称:strokes,代码行数:14,代码来源:DangerousEqualityCheckAchievement.cs

示例10: VisitLocalVariableDeclaration

            public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
            {
                if (localVariableDeclaration.TypeReference.Type.Equals("Thread") ||
                    localVariableDeclaration.TypeReference.Type.Equals("Threading.Thread") ||
                    localVariableDeclaration.TypeReference.Type.Equals("System.Threading.Thread"))
                {
                    foreach (VariableDeclaration variableDeclaration in localVariableDeclaration.Variables)
                    {
                        threadVars.Add(variableDeclaration.Name);
                    }
                }

                return base.VisitLocalVariableDeclaration(localVariableDeclaration, data);
            }
开发者ID:timdams,项目名称:strokes,代码行数:14,代码来源:ThreadMethodschievements.cs

示例11: TrackedVisitArrayCreateExpression

        public override object TrackedVisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data)
        {
            string variableName = GetVariableName(arrayCreateExpression);
            List<Expression> initializerList = arrayCreateExpression.ArrayInitializer.CreateExpressions;
            Expression replacedExpression = arrayCreateExpression;
            if (initializerList.Count > 0 && initializerList[0] is CollectionInitializerExpression && data is InsertionBlockData)
            {
                ArrayCreateExpression replacedArrayCreateExpression = arrayCreateExpression;
                replacedArrayCreateExpression.ArrayInitializer = null;
                replacedArrayCreateExpression.Arguments.Add(new PrimitiveExpression(initializerList.Count, initializerList.Count.ToString()));

                string arrayTypeName = arrayCreateExpression.CreateType.Type + "s";
                Position position = Position.After;
                if (variableName == null)
                {
                    variableName = arrayTypeName;
                    position = Position.Before;
                }

                List<Statement> initStatements = GetArrayInitStatements(replacedArrayCreateExpression, variableName, initializerList);
                InsertionBlockData insertionBlockData = (InsertionBlockData) data;
                insertionBlockData.Block = (BlockStatement) AstUtil.GetParentOfType(replacedArrayCreateExpression, typeof(BlockStatement));
                insertionBlockData.BlockChildIndex = GetBlockChildIndex(replacedArrayCreateExpression, position);
                insertionBlockData.Statements = initStatements;

                if (variableName == arrayTypeName)
                {
                    IdentifierExpression identifierExpression = new IdentifierExpression(variableName);
                    replacedExpression = identifierExpression;

                    VariableDeclaration variableDeclaration = new VariableDeclaration(variableName, arrayCreateExpression);
                    LocalVariableDeclaration localVariable = new LocalVariableDeclaration(variableDeclaration);
                    localVariable.TypeReference = arrayCreateExpression.CreateType;

                    initStatements.Insert(0, localVariable);
                }

                ReplaceCurrentNode(replacedExpression);
            }

            return base.TrackedVisitArrayCreateExpression(arrayCreateExpression, data);
        }
开发者ID:sourcewarehouse,项目名称:janett,代码行数:42,代码来源:ArrayInitializerTransformer.cs

示例12: VisitLocalVariableDeclaration

		public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
		{
			if (localVariableDeclaration.TypeReference.Type == "var")
				localVariableDeclaration.TypeReference = TypeReference.Null;
			return base.VisitLocalVariableDeclaration(localVariableDeclaration, data);
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:6,代码来源:ToVBNetConvertVisitor.cs

示例13: VisitLocalVariableDeclaration

 public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
 {
     localVariableDeclarations.Add(localVariableDeclaration);
     return base.VisitLocalVariableDeclaration(localVariableDeclaration, data);
 }
开发者ID:pusp,项目名称:o2platform,代码行数:5,代码来源:AstVisitors.cs

示例14: VisitLocalVariableDeclaration

 public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
 {
     if (this.CheckNode(localVariableDeclaration)) {
         return null;
     }
     return base.VisitLocalVariableDeclaration(localVariableDeclaration, data);
 }
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:7,代码来源:MemberFindAstVisitor.cs

示例15: PerformChanges

		public override List<Change> PerformChanges (RefactoringOptions options, object prop)
		{
			List<Change> result = new List<Change> ();
			ExtractMethodParameters param = (ExtractMethodParameters)prop;
			TextEditorData data = options.GetTextEditorData ();
			INRefactoryASTProvider provider = options.GetASTProvider ();
			IResolver resolver = options.GetResolver ();
			ICSharpCode.NRefactory.Ast.INode node = Analyze (options, param, false);
			if (param.VariablesToGenerate.Count > 0) {
				TextReplaceChange varGen = new TextReplaceChange ();
				varGen.Description = GettextCatalog.GetString ("Generate some temporary variables");
				varGen.FileName = options.Document.FileName;
				LineSegment line = data.Document.GetLine (Math.Max (0, data.Document.OffsetToLineNumber (data.SelectionRange.Offset) - 1));
				varGen.Offset = line.Offset + line.EditableLength;
				varGen.InsertedText = Environment.NewLine + options.GetWhitespaces (line.Offset);
				foreach (VariableDescriptor var in param.VariablesToGenerate) {
					TypeReference tr = options.ShortenTypeName (var.ReturnType).ConvertToTypeReference ();
					varGen.InsertedText += provider.OutputNode (options.Dom, new LocalVariableDeclaration (new VariableDeclaration (var.Name, null, tr))).Trim ();
				}
				result.Add (varGen);
			}
			InvocationExpression invocation = new InvocationExpression (new IdentifierExpression (param.Name));
			foreach (VariableDescriptor var in param.Parameters) {
				if (!param.OneChangedVariable && param.ChangedVariables.Contains (var.Name)) {
					FieldDirection fieldDirection = FieldDirection.Ref;
					VariableDescriptor outsideVar = null;
					if (param.VariablesOutside.TryGetValue (var.Name, out outsideVar) && (var.GetsAssigned || param.VariablesToGenerate.Where (v => v.Name == var.Name).Any ())) {
						if (!outsideVar.GetsAssigned)
							fieldDirection = FieldDirection.Out;
					}
					invocation.Arguments.Add (new DirectionExpression (fieldDirection, new IdentifierExpression (var.Name)));
				} else {
					invocation.Arguments.Add (new IdentifierExpression (var.Name));
				}
			}
			//	string mimeType = DesktopService.GetMimeTypeForUri (options.Document.FileName);
			TypeReference returnType = new TypeReference ("System.Void", true);
			ICSharpCode.NRefactory.Ast.INode outputNode;
			if (param.OneChangedVariable) {
				string name = param.ChangedVariables.First ();
				returnType = options.ShortenTypeName (param.Variables.Find (v => v.Name == name).ReturnType).ConvertToTypeReference ();
				if (param.OutsideVariableList.Any (v => v.Name == name && !v.IsDefined)) {
					LocalVariableDeclaration varDecl = new LocalVariableDeclaration (returnType);
					varDecl.Variables.Add (new VariableDeclaration (name, invocation));
					outputNode = varDecl;
				} else {
					outputNode = new ExpressionStatement (new AssignmentExpression (new IdentifierExpression (name), ICSharpCode.NRefactory.Ast.AssignmentOperatorType.Assign, invocation));
				}
			} else {
				outputNode = node is BlockStatement ? (ICSharpCode.NRefactory.Ast.INode)new ExpressionStatement (invocation) : invocation;
			}
			TextReplaceChange replacement = new TextReplaceChange ();
			replacement.Description = string.Format (GettextCatalog.GetString ("Substitute selected statement(s) with call to {0}"), param.Name);
			replacement.FileName = options.Document.FileName;
			replacement.Offset = options.Document.Editor.SelectionRange.Offset;
			replacement.RemovedChars = options.Document.Editor.SelectionRange.Length;
			replacement.MoveCaretToReplace = true;
			
			LineSegment line1 = data.Document.GetLineByOffset (options.Document.Editor.SelectionRange.EndOffset);
			if (options.Document.Editor.SelectionRange.EndOffset == line1.Offset) {
				if (line1.Offset > 0) {
					LineSegment line2 = data.Document.GetLineByOffset (line1.Offset - 1);
					replacement.RemovedChars -= line2.DelimiterLength;
				}
			}
			
			replacement.InsertedText = options.GetWhitespaces (options.Document.Editor.SelectionRange.Offset) + provider.OutputNode (options.Dom, outputNode).Trim ();
			
			result.Add (replacement);

			TextReplaceChange insertNewMethod = new TextReplaceChange ();
			insertNewMethod.FileName = options.Document.FileName;
			insertNewMethod.Description = string.Format (GettextCatalog.GetString ("Create new method {0} from selected statement(s)"), param.Name);
			insertNewMethod.RemovedChars = param.InsertionPoint.LineBefore == NewLineInsertion.Eol ? 0 : param.InsertionPoint.Location.Column;
			insertNewMethod.Offset = data.Document.LocationToOffset (param.InsertionPoint.Location) - insertNewMethod.RemovedChars;
			
			ExtractMethodAstTransformer transformer = new ExtractMethodAstTransformer (param.VariablesToGenerate);
			node.AcceptVisitor (transformer, null);
			if (!param.OneChangedVariable && node is Expression) {
				ResolveResult resolveResult = resolver.Resolve (new ExpressionResult ("(" + provider.OutputNode (options.Dom, node) + ")"), new DomLocation (options.Document.Editor.Caret.Line, options.Document.Editor.Caret.Column));
				if (resolveResult.ResolvedType != null)
					returnType = options.ShortenTypeName (resolveResult.ResolvedType).ConvertToTypeReference ();
			}
			
			MethodDeclaration methodDecl = new MethodDeclaration ();
			methodDecl.Name = param.Name;
			methodDecl.Modifier = param.Modifiers;
			methodDecl.TypeReference = returnType;
			
			if (!param.ReferencesMember)
				methodDecl.Modifier |= ICSharpCode.NRefactory.Ast.Modifiers.Static;
			if (node is BlockStatement) {
				methodDecl.Body = new BlockStatement ();
				methodDecl.Body.AddChild (new EmptyStatement ());
				if (param.OneChangedVariable)
					methodDecl.Body.AddChild (new ReturnStatement (new IdentifierExpression (param.ChangedVariables.First ())));
			} else if (node is Expression) {
				methodDecl.Body = new BlockStatement ();
				methodDecl.Body.AddChild (new ReturnStatement (node as Expression));
			}
//.........这里部分代码省略.........
开发者ID:pgoron,项目名称:monodevelop,代码行数:101,代码来源:ExtractMethodRefactoring.cs


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