本文整理汇总了C#中RefactoringOptions.GetIndent方法的典型用法代码示例。如果您正苦于以下问题:C# RefactoringOptions.GetIndent方法的具体用法?C# RefactoringOptions.GetIndent怎么用?C# RefactoringOptions.GetIndent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RefactoringOptions
的用法示例。
在下文中一共展示了RefactoringOptions.GetIndent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PerformChanges
//.........这里部分代码省略.........
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));
}
foreach (VariableDescriptor var in param.VariablesToDefine) {
BlockStatement block = methodDecl.Body;
LocalVariableDeclaration varDecl = new LocalVariableDeclaration (options.ShortenTypeName (var.ReturnType).ConvertToTypeReference ());
varDecl.Variables.Add (new VariableDeclaration (var.Name));
block.Children.Insert (0, varDecl);
}
foreach (VariableDescriptor var in param.Parameters) {
TypeReference typeReference = options.ShortenTypeName (var.ReturnType).ConvertToTypeReference ();
ParameterDeclarationExpression pde = new ParameterDeclarationExpression (typeReference, var.Name);
if (!param.OneChangedVariable) {
if (param.ChangedVariables.Contains (var.Name))
pde.ParamModifier = ICSharpCode.NRefactory.Ast.ParameterModifiers.Ref;
if (param.VariablesToGenerate.Where (v => v.Name == var.Name).Any ()) {
pde.ParamModifier = ICSharpCode.NRefactory.Ast.ParameterModifiers.Out;
}
VariableDescriptor outsideVar = null;
if (var.GetsAssigned && param.VariablesOutside.TryGetValue (var.Name, out outsideVar)) {
if (!outsideVar.GetsAssigned)
pde.ParamModifier = ICSharpCode.NRefactory.Ast.ParameterModifiers.Out;
}
}
methodDecl.Parameters.Add (pde);
}
string indent = options.GetIndent (param.DeclaringMember);
StringBuilder methodText = new StringBuilder ();
switch (param.InsertionPoint.LineBefore) {
case NewLineInsertion.Eol:
methodText.AppendLine ();
break;
case NewLineInsertion.BlankLine:
methodText.Append (indent);
methodText.AppendLine ();
break;
}
if (param.GenerateComment) {
methodText.Append (indent);
methodText.AppendLine ("/// <summary>");
methodText.Append (indent);
methodText.AppendLine ("/// TODO: write a comment.");
methodText.Append (indent);
methodText.AppendLine ("/// </summary>");
Ambience ambience = AmbienceService.GetAmbienceForFile (options.Document.FileName);
foreach (ParameterDeclarationExpression pde in methodDecl.Parameters) {
methodText.Append (indent);
methodText.Append ("/// <param name=\"");
methodText.Append (pde.ParameterName);
methodText.Append ("\"> A ");
methodText.Append (ambience.GetString (pde.TypeReference.ConvertToReturnType (), OutputFlags.IncludeGenerics | OutputFlags.UseFullName));
methodText.Append (" </param>");
methodText.AppendLine ();
}
if (methodDecl.TypeReference.Type != "System.Void") {
methodText.Append (indent);
methodText.AppendLine ("/// <returns>");
methodText.Append (indent);
methodText.Append ("/// A ");
示例2: Run
public override void Run (RefactoringOptions options)
{
IResolver resolver = options.GetResolver ();
INRefactoryASTProvider provider = options.GetASTProvider ();
TextEditorData data = options.GetTextEditorData ();
IType type = options.ResolveResult.CallingType;
if (invoke.TargetObject is IdentifierExpression) {
fileName = options.Document.FileName;
newMethodName = ((IdentifierExpression)invoke.TargetObject).Identifier;
indent = options.GetIndent (options.ResolveResult.CallingMember);
if (options.ResolveResult.CallingMember.IsStatic)
modifiers |= ICSharpCode.NRefactory.Ast.Modifiers.Static;
} else {
newMethodName = ((MemberReferenceExpression)invoke.TargetObject).MemberName;
string callingObject = provider.OutputNode (options.Dom, ((MemberReferenceExpression)invoke.TargetObject).TargetObject);
ResolveResult resolveResult = resolver.Resolve (new ExpressionResult (callingObject), resolvePosition);
type = options.Dom.GetType (resolveResult.ResolvedType);
fileName = type.CompilationUnit.FileName;
if (resolveResult.StaticResolve)
modifiers |= ICSharpCode.NRefactory.Ast.Modifiers.Static;
if (fileName == options.Document.FileName) {
indent = options.GetIndent (options.ResolveResult.CallingMember);
// insertNewMethod.Offset = options.Document.TextEditor.GetPositionFromLineColumn (options.ResolveResult.CallingMember.BodyRegion.End.Line, options.ResolveResult.CallingMember.BodyRegion.End.Column);
} else {
var openDocument = IdeApp.Workbench.OpenDocument (fileName);
data = openDocument.Editor;
if (data == null)
return;
modifiers |= ICSharpCode.NRefactory.Ast.Modifiers.Public;
bool isInInterface = type.ClassType == MonoDevelop.Projects.Dom.ClassType.Interface;
if (isInInterface)
modifiers = ICSharpCode.NRefactory.Ast.Modifiers.None;
if (data == null)
throw new InvalidOperationException ("Can't open file:" + modifiers);
try {
indent = data.Document.GetLine (type.Location.Line - 1).GetIndentation (data.Document) ?? "";
} catch (Exception) {
indent = "";
}
indent += "\t";
// insertNewMethod.Offset = otherFile.Document.LocationToOffset (type.BodyRegion.End.Line - 1, 0);
}
}
InsertionCursorEditMode mode = new InsertionCursorEditMode (data.Parent, HelperMethods.GetInsertionPoints (data.Document, type));
if (fileName == options.Document.FileName) {
for (int i = 0; i < mode.InsertionPoints.Count; i++) {
var point = mode.InsertionPoints[i];
if (point.Location < data.Caret.Location) {
mode.CurIndex = i;
} else {
break;
}
}
}
ModeHelpWindow helpWindow = new ModeHelpWindow ();
helpWindow.TransientFor = IdeApp.Workbench.RootWindow;
helpWindow.TitleText = GettextCatalog.GetString ("<b>Create Method -- Targeting</b>");
helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Key</b>"), GettextCatalog.GetString ("<b>Behavior</b>")));
helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Up</b>"), GettextCatalog.GetString ("Move to <b>previous</b> target point.")));
helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Down</b>"), GettextCatalog.GetString ("Move to <b>next</b> target point.")));
helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Enter</b>"), GettextCatalog.GetString ("<b>Declare new method</b> at target point.")));
helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Esc</b>"), GettextCatalog.GetString ("<b>Cancel</b> this refactoring.")));
mode.HelpWindow = helpWindow;
mode.StartMode ();
mode.Exited += delegate(object s, InsertionCursorEventArgs args) {
if (args.Success) {
insertionPoint = args.InsertionPoint;
insertionOffset = data.Document.LocationToOffset (args.InsertionPoint.Location);
base.Run (options);
if (string.IsNullOrEmpty (fileName))
return;
MonoDevelop.Ide.Gui.Document document = IdeApp.Workbench.OpenDocument (fileName);
TextEditorData docData = document.Editor;
if (docData != null) {
docData.ClearSelection ();
docData.Caret.Offset = selectionEnd;
docData.SetSelection (selectionStart, selectionEnd);
}
}
};
}
示例3: PerformChanges
public override List<Change> PerformChanges (RefactoringOptions options, object properties)
{
List<Change> result = new List<Change> ();
Parameters param = properties as Parameters;
if (param == null)
return result;
TextEditorData data = options.GetTextEditorData ();
IResolver resolver = options.GetResolver ();
IMember curMember = options.Document.CompilationUnit.GetMemberAt (data.Caret.Line, data.Caret.Column);
ResolveResult resolveResult = options.ResolveResult;
int start = 0;
int end = 0;
if (resolveResult == null) {
LineSegment line = data.Document.GetLine (data.Caret.Line);
if (line != null) {
var stack = line.StartSpan.Clone ();
Mono.TextEditor.Highlighting.SyntaxModeService.ScanSpans (data.Document, data.Document.SyntaxMode, data.Document.SyntaxMode, stack, line.Offset, data.Caret.Offset);
foreach (Span span in stack) {
if (span.Color == "string.single" || span.Color == "string.double") {
resolveResult = resolver.Resolve (new ExpressionResult (SearchString (data, span.Color == "string.single" ? '\'' : '"', out start, out end)), DomLocation.Empty);
end++;
}
}
}
if (end == 0) {
resolveResult = resolver.Resolve (new ExpressionResult (SearchNumber (data, out start, out end)), DomLocation.Empty);
}
} else {
start = data.Document.LocationToOffset (resolveResult.ResolvedExpression.Region.Start.Line, resolveResult.ResolvedExpression.Region.Start.Column);
end = data.Document.LocationToOffset (resolveResult.ResolvedExpression.Region.End.Line, resolveResult.ResolvedExpression.Region.End.Column);
}
if (start == 0 && end == 0)
return result;
INRefactoryASTProvider provider = options.GetASTProvider ();
FieldDeclaration fieldDeclaration = new FieldDeclaration (null);
VariableDeclaration varDecl = new VariableDeclaration (param.Name);
varDecl.Initializer = provider.ParseExpression (resolveResult.ResolvedExpression.Expression);
fieldDeclaration.Fields.Add (varDecl);
fieldDeclaration.Modifier = param.Modifiers;
fieldDeclaration.Modifier |= ICSharpCode.NRefactory.Ast.Modifiers.Const;
fieldDeclaration.TypeReference = resolveResult.ResolvedType.ConvertToTypeReference ();
fieldDeclaration.TypeReference.IsKeyword = true;
TextReplaceChange insertConstant = new TextReplaceChange ();
insertConstant.FileName = options.Document.FileName;
insertConstant.Description = string.Format (GettextCatalog.GetString ("Generate constant '{0}'"), param.Name);
insertConstant.Offset = data.Document.LocationToOffset (curMember.Location.Line, 1);
insertConstant.InsertedText = provider.OutputNode (options.Dom, fieldDeclaration, options.GetIndent (curMember)) + Environment.NewLine;
result.Add (insertConstant);
TextReplaceChange replaceConstant = new TextReplaceChange ();
replaceConstant.FileName = options.Document.FileName;
replaceConstant.Description = string.Format (GettextCatalog.GetString ("Replace expression with constant '{0}'"), param.Name);
replaceConstant.Offset = start;
replaceConstant.RemovedChars = end - start;
replaceConstant.InsertedText = param.Name;
result.Add (replaceConstant);
return result;
}
示例4: PerformChanges
public override List<Change> PerformChanges (RefactoringOptions options, object prop)
{
List<Change> result = new List<Change> ();
MemberResolveResult resolveResult = options.ResolveResult as MemberResolveResult;
IProperty property = resolveResult.ResolvedMember as IProperty;
TextEditorData data = options.GetTextEditorData ();
INRefactoryASTProvider astProvider = options.GetASTProvider ();
backingStoreName = GetBackingStoreName (property);
FieldDeclaration backingStore = new FieldDeclaration (null);
backingStore.TypeReference = options.Document.CompilationUnit.ShortenTypeName (property.ReturnType, property.Location).ConvertToTypeReference ();
backingStore.Fields.Add (new VariableDeclaration (backingStoreName));
DocumentLocation location = property.Location.ToDocumentLocation (data.Document);
location.Column = 0;
refactoringStartOffset = data.Document.LocationToOffset (location);
result.Add (new TextReplaceChange () {
FileName = options.Document.FileName,
Offset = refactoringStartOffset,
InsertedText = astProvider.OutputNode (options.Dom, backingStore, options.GetIndent (property))
});
if (property.HasGet) {
int startOffset = data.Document.LocationToOffset (property.GetRegion.Start.ToDocumentLocation (data.Document));
int endOffset = data.Document.LocationToOffset (property.GetRegion.End.ToDocumentLocation (data.Document));
BlockStatement getBlock = new BlockStatement ();
getBlock.AddChild (new ReturnStatement (new IdentifierExpression (backingStoreName)));
string text = astProvider.OutputNode (options.Dom, new PropertyGetRegion (getBlock, null), options.GetIndent (property) + "\t").Trim ();
result.Add (new TextReplaceChange () {
FileName = options.Document.FileName,
Offset = startOffset,
RemovedChars = endOffset - startOffset,
InsertedText = text
});
}
if (property.HasSet) {
int startOffset = data.Document.LocationToOffset (property.SetRegion.Start.ToDocumentLocation (data.Document));
int endOffset = data.Document.LocationToOffset (property.SetRegion.End.ToDocumentLocation (data.Document));
BlockStatement setBlock = new BlockStatement ();
setBlock.AddChild (new ExpressionStatement (new AssignmentExpression (new IdentifierExpression (backingStoreName), AssignmentOperatorType.Assign, new IdentifierExpression ("value"))));
string text = astProvider.OutputNode (options.Dom, new PropertySetRegion (setBlock, null), options.GetIndent (property) + "\t").Trim ();
result.Add (new TextReplaceChange () {
FileName = options.Document.FileName,
Offset = startOffset,
RemovedChars = endOffset - startOffset,
InsertedText = text
});
}
return result;
}
示例5: PerformChanges
public override List<Change> PerformChanges (RefactoringOptions options, object prop)
{
List<Change> result = new List<Change> ();
TextEditorData data = options.GetTextEditorData ();
MemberResolveResult resolveResult = options.ResolveResult as MemberResolveResult;
IProperty property = resolveResult.ResolvedMember as IProperty;
INRefactoryASTProvider astProvider = options.GetASTProvider ();
string backingStoreName = RetrieveBackingStore (options, astProvider, property);
int backinStoreStart;
int backinStoreEnd;
IField backingStore = GetBackingStoreField (options, backingStoreName, out backinStoreStart, out backinStoreEnd);
if (backingStore != null) {
foreach (MemberReference memberRef in ReferenceFinder.FindReferences (backingStore)) {
result.Add (new TextReplaceChange () {
FileName = memberRef.FileName,
Offset = memberRef.Position,
RemovedChars = memberRef.Name.Length,
InsertedText = property.Name
});
}
result.RemoveAll (c => backinStoreStart <= ((TextReplaceChange)c).Offset && ((TextReplaceChange)c).Offset <= backinStoreEnd);
result.Add (new TextReplaceChange () {
FileName = options.Document.FileName,
Offset = backinStoreStart,
RemovedChars = backinStoreEnd - backinStoreStart
});
}
if (property.HasGet) {
int startOffset = data.Document.LocationToOffset (property.GetRegion.Start.ToDocumentLocation (data.Document));
int endOffset = data.Document.LocationToOffset (property.GetRegion.End.ToDocumentLocation (data.Document));
string text = astProvider.OutputNode (options.Dom, new PropertyGetRegion (null, null), options.GetIndent (property) + "\t").Trim ();
result.RemoveAll (c => startOffset <= ((TextReplaceChange)c).Offset && ((TextReplaceChange)c).Offset <= endOffset);
result.Add (new TextReplaceChange () {
FileName = options.Document.FileName,
Offset = startOffset,
RemovedChars = endOffset - startOffset,
InsertedText = text
});
}
int setStartOffset;
int setEndOffset;
PropertySetRegion setRegion = new PropertySetRegion (null, null);
string setText;
if (property.HasSet) {
setStartOffset = data.Document.LocationToOffset (property.SetRegion.Start.ToDocumentLocation (data.Document));
setEndOffset = data.Document.LocationToOffset (property.SetRegion.End.ToDocumentLocation (data.Document));
setText = astProvider.OutputNode (options.Dom, setRegion, options.GetIndent (property) + "\t").Trim ();
} else {
setEndOffset = setStartOffset = data.Document.LocationToOffset (property.GetRegion.End.ToDocumentLocation (data.Document));
setRegion.Modifier = ICSharpCode.NRefactory.Ast.Modifiers.Private;
setText = Environment.NewLine + astProvider.OutputNode (options.Dom, setRegion, options.GetIndent (property) + "\t").TrimEnd ();
}
result.RemoveAll (c => setStartOffset <= ((TextReplaceChange)c).Offset && ((TextReplaceChange)c).Offset <= setEndOffset);
result.Add (new TextReplaceChange () {
FileName = options.Document.FileName,
Offset = setStartOffset,
RemovedChars = setEndOffset - setStartOffset,
InsertedText = setText
});
return result;
}
示例6: PerformChanges
public override List<Change> PerformChanges (RefactoringOptions options, object prop)
{
List<Change> result = new List<Change> ();
IResolver resolver = options.GetResolver ();
INRefactoryASTProvider provider = options.GetASTProvider ();
if (resolver == null || provider == null)
return result;
TextEditorData data = options.GetTextEditorData ();
TextReplaceChange insertNewMethod = new TextReplaceChange ();
insertNewMethod.InsertedText = "";
string indent = "";
MethodDeclaration methodDecl = new MethodDeclaration ();
bool isInInterface = false;
if (invoke.TargetObject is IdentifierExpression) {
insertNewMethod.FileName = options.Document.FileName;
insertNewMethod.Offset = options.Document.TextEditor.GetPositionFromLineColumn (options.ResolveResult.CallingMember.BodyRegion.End.Line, options.ResolveResult.CallingMember.BodyRegion.End.Column);
methodDecl.Name = ((IdentifierExpression)invoke.TargetObject).Identifier;
indent = options.GetIndent (options.ResolveResult.CallingMember);
insertNewMethod.InsertedText = Environment.NewLine;
if (options.ResolveResult.CallingMember.IsStatic)
methodDecl.Modifier |= ICSharpCode.NRefactory.Ast.Modifiers.Static;
} else {
methodDecl.Name = ((MemberReferenceExpression)invoke.TargetObject).MemberName;
string callingObject = provider.OutputNode (options.Dom, ((MemberReferenceExpression)invoke.TargetObject).TargetObject);
ResolveResult resolveResult = resolver.Resolve (new ExpressionResult (callingObject), resolvePosition);
IType type = options.Dom.GetType (resolveResult.ResolvedType);
insertNewMethod.FileName = type.CompilationUnit.FileName;
if (resolveResult.StaticResolve)
methodDecl.Modifier |= ICSharpCode.NRefactory.Ast.Modifiers.Static;
if (insertNewMethod.FileName == options.Document.FileName) {
indent = options.GetIndent (options.ResolveResult.CallingMember);
insertNewMethod.InsertedText = Environment.NewLine;
insertNewMethod.Offset = options.Document.TextEditor.GetPositionFromLineColumn (options.ResolveResult.CallingMember.BodyRegion.End.Line, options.ResolveResult.CallingMember.BodyRegion.End.Column);
} else {
TextEditorData otherFile = TextReplaceChange.GetTextEditorData (insertNewMethod.FileName);
if (otherFile == null) {
IdeApp.Workbench.OpenDocument (insertNewMethod.FileName);
otherFile = TextReplaceChange.GetTextEditorData (insertNewMethod.FileName);
}
methodDecl.Modifier |= ICSharpCode.NRefactory.Ast.Modifiers.Public;
isInInterface = type.ClassType == MonoDevelop.Projects.Dom.ClassType.Interface;
if (isInInterface)
methodDecl.Modifier = ICSharpCode.NRefactory.Ast.Modifiers.None;
if (otherFile == null)
throw new InvalidOperationException ("Can't open file:" + insertNewMethod.FileName);
try {
indent = otherFile.Document.GetLine (type.Location.Line - 1).GetIndentation (otherFile.Document) ?? "";
} catch (Exception) {
indent = "";
}
indent += "\t";
insertNewMethod.Offset = otherFile.Document.LocationToOffset (type.BodyRegion.End.Line - 1, 0);
}
}
methodDecl.Modifier = modifiers;
methodDecl.TypeReference = HelperMethods.ConvertToTypeReference (returnType);
if (!isInInterface) {
methodDecl.Body = new BlockStatement ();
methodDecl.Body.AddChild (new ThrowStatement (new ObjectCreateExpression (new TypeReference ("System.NotImplementedException"), null)));
}
insertNewMethod.Description = string.Format (GettextCatalog.GetString ("Create new method {0}"), methodDecl.Name);
int i = 0;
foreach (Expression expression in invoke.Arguments) {
i++;
string output = provider.OutputNode (options.Dom, expression);
string parameterName = "par" + i;
int idx = output.LastIndexOf ('.');
string lastName = output.Substring (idx + 1); // start from 0, if '.' wasn't found
if (IsValidIdentifier (lastName))
parameterName = lastName;
ResolveResult resolveResult2 = resolver.Resolve (new ExpressionResult (output), resolvePosition);
TypeReference typeReference = new TypeReference ((resolveResult2 != null && resolveResult2.ResolvedType != null) ? options.Document.CompilationUnit.ShortenTypeName (resolveResult2.ResolvedType, data.Caret.Line, data.Caret.Column).ToInvariantString () : "System.Object");
typeReference.IsKeyword = true;
ParameterDeclarationExpression pde = new ParameterDeclarationExpression (typeReference, parameterName);
methodDecl.Parameters.Add (pde);
}
insertNewMethod.InsertedText += Environment.NewLine + provider.OutputNode (options.Dom, methodDecl, indent);
result.Add (insertNewMethod);
fileName = insertNewMethod.FileName;
if (!isInInterface) {
int idx = insertNewMethod.InsertedText.IndexOf ("throw");
selectionStart = insertNewMethod.Offset + idx;
selectionEnd = insertNewMethod.Offset + insertNewMethod.InsertedText.IndexOf (';', idx) + 1;
} else {
selectionStart = selectionEnd = insertNewMethod.Offset;
}
return result;
}