本文整理汇总了C#中RefactoringContext.StartScript方法的典型用法代码示例。如果您正苦于以下问题:C# RefactoringContext.StartScript方法的具体用法?C# RefactoringContext.StartScript怎么用?C# RefactoringContext.StartScript使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RefactoringContext
的用法示例。
在下文中一共展示了RefactoringContext.StartScript方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run (RefactoringContext context)
{
var property = context.GetNode<PropertyDeclaration> ();
string backingStoreName = context.GetNameProposal (property.Name);
// create field
var backingStore = new FieldDeclaration ();
backingStore.ReturnType = property.ReturnType.Clone ();
var initializer = new VariableInitializer (backingStoreName);
backingStore.Variables.Add (initializer);
// create new property & implement the get/set bodies
var newProperty = (PropertyDeclaration)property.Clone ();
var id1 = new IdentifierExpression (backingStoreName);
var id2 = new IdentifierExpression (backingStoreName);
newProperty.Getter.Body = new BlockStatement () {
new ReturnStatement (id1)
};
newProperty.Setter.Body = new BlockStatement () {
new ExpressionStatement (new AssignmentExpression (id2, AssignmentOperatorType.Assign, new IdentifierExpression ("value")))
};
using (var script = context.StartScript ()) {
script.Replace (property, newProperty);
script.InsertBefore (property, backingStore);
script.Link (initializer, id1, id2);
}
}
示例2: Run
public void Run (RefactoringContext context)
{
var switchStatement = GetSwitchStatement (context);
var result = context.Resolve (switchStatement.Expression);
var type = result.Type;
var newSwitch = (SwitchStatement)switchStatement.Clone ();
var target = new TypeReferenceExpression (context.CreateShortType (result.Type.Resolve (context.TypeResolveContext)));
foreach (var field in type.GetFields (context.TypeResolveContext)) {
if (field.IsSynthetic || !field.IsConst)
continue;
newSwitch.SwitchSections.Add (new SwitchSection () {
CaseLabels = {
new CaseLabel (new MemberReferenceExpression (target.Clone (), field.Name))
},
Statements = {
new BreakStatement ()
}
});
}
newSwitch.SwitchSections.Add (new SwitchSection () {
CaseLabels = {
new CaseLabel ()
},
Statements = {
new ThrowStatement (new ObjectCreateExpression (context.CreateShortType ("System", "ArgumentOutOfRangeException")))
}
});
using (var script = context.StartScript ()) {
script.Replace (switchStatement, newSwitch);
}
}
示例3: Run
public void Run (RefactoringContext context)
{
var expr = GetEmptyString (context);
using (var script = context.StartScript ()) {
script.Replace (expr, new MemberReferenceExpression (new TypeReferenceExpression (new PrimitiveType ("string")), "Empty"));
}
}
示例4: Run
public void Run (RefactoringContext context)
{
var identifier = GetIdentifier (context);
using (var script = context.StartScript ()) {
script.InsertWithCursor ("Create property", GeneratePropertyDeclaration (context, identifier), Script.InsertPosition.Before);
}
}
示例5: Run
public void Run (RefactoringContext context)
{
var varDecl = GetVariableDeclarationStatement (context);
using (var script = context.StartScript ()) {
script.Replace (varDecl.Type, new SimpleType ("var"));
}
}
示例6: Run
public void Run (RefactoringContext context)
{
var foreachStatement = GetForeachStatement (context);
var result = context.ResolveType (foreachStatement.InExpression);
var countProperty = GetCountProperty (result);
var initializer = new VariableDeclarationStatement (new PrimitiveType ("int"), "i", new PrimitiveExpression (0));
var id1 = new IdentifierExpression ("i");
var id2 = id1.Clone ();
var id3 = id1.Clone ();
var forStatement = new ForStatement () {
Initializers = { initializer },
Condition = new BinaryOperatorExpression (id1, BinaryOperatorType.LessThan, new MemberReferenceExpression (foreachStatement.InExpression.Clone (), countProperty)),
Iterators = { new ExpressionStatement (new UnaryOperatorExpression (UnaryOperatorType.PostIncrement, id2)) },
EmbeddedStatement = new BlockStatement {
new VariableDeclarationStatement (foreachStatement.VariableType.Clone (), foreachStatement.VariableName, new IndexerExpression (foreachStatement.InExpression.Clone (), id3))
}
};
if (foreachStatement.EmbeddedStatement is BlockStatement) {
foreach (var child in ((BlockStatement)foreachStatement.EmbeddedStatement).Statements) {
forStatement.EmbeddedStatement.AddChild (child.Clone (), BlockStatement.StatementRole);
}
} else {
forStatement.EmbeddedStatement.AddChild (foreachStatement.EmbeddedStatement.Clone (), BlockStatement.StatementRole);
}
using (var script = context.StartScript ()) {
script.Replace (foreachStatement, forStatement);
script.Link (initializer.Variables.First ().NameToken, id1, id2, id3);
}
}
示例7: Run
public void Run (RefactoringContext context)
{
var varDecl = GetVariableDeclarationStatement (context);
using (var script = context.StartScript ()) {
script.Replace (varDecl.Type, context.ResolveType (varDecl.Variables.First ().Initializer));
}
}
示例8: Run
public void Run (RefactoringContext context)
{
var pexpr = context.GetNode<PrimitiveExpression> ();
using (var script = context.StartScript ()) {
script.Replace (pexpr, new PrimitiveExpression (pexpr.Value, string.Format ("0x{0:x}", pexpr.Value)));
}
}
示例9: Run
public void Run (RefactoringContext context)
{
var pexpr = context.GetNode<PrimitiveExpression> ();
int offset = context.GetOffset (context.Location);
using (var script = context.StartScript ()) {
script.InsertText (offset, pexpr.LiteralValue.StartsWith ("@") ? "\" + @\"" : "\" + \"");
}
}
示例10: Run
public void Run (RefactoringContext context)
{
var stmt = context.GetNode<Statement> ();
var unresolvedArguments = GetUnresolvedArguments (context);
if (unresolvedArguments.Count > 0) {
using (var script = context.StartScript ()) {
foreach (var id in unresolvedArguments) {
script.InsertBefore (stmt, GenerateLocalVariableDeclaration (context, id));
}
}
return;
}
using (var script = context.StartScript ()) {
script.InsertBefore (stmt, GenerateLocalVariableDeclaration (context, CreateField.GetIdentifier (context)));
}
}
示例11: Run
public void Run (RefactoringContext context)
{
var binop = GetBinaryOperatorExpression (context);
using (var script = context.StartScript ()) {
script.Replace (binop.Left, binop.Right);
script.Replace (binop.Right, binop.Left);
}
}
示例12: Run
public void Run (RefactoringContext context)
{
var initializer = GetVariableInitializer (context);
var field = initializer.Parent as FieldDeclaration;
using (var script = context.StartScript ()) {
script.InsertWithCursor ("Create getter", GeneratePropertyDeclaration (context, field, initializer), Script.InsertPosition.After);
}
}
示例13: Run
public void Run (RefactoringContext context)
{
var block = GetBlockStatement (context);
using (var script = context.StartScript ()) {
script.Remove (block.LBraceToken);
script.Remove (block.RBraceToken);
script.FormatText (ctx => ctx.Unit.GetNodeAt (block.Parent.StartLocation));
}
}
示例14: Run
public void Run (RefactoringContext context)
{
using (var script = context.StartScript ()) {
var varDecl = GetVariableDeclarationStatement (context);
if (varDecl != null) {
script.Replace (varDecl.Type, new SimpleType ("var"));
} else {
script.Replace (GetForeachStatement (context).VariableType, new SimpleType ("var"));
}
}
}
示例15: AddFormatCallToInvocation
void AddFormatCallToInvocation (RefactoringContext context, PrimitiveExpression pExpr, InvocationExpression invocation)
{
var newInvocation = (InvocationExpression)invocation.Clone ();
newInvocation.Arguments.First ().ReplaceWith (CreateFormatString (context, pExpr, newInvocation.Arguments.Count () - 1));
newInvocation.Arguments.Add (CreateFormatArgument (context));
using (var script = context.StartScript ()) {
script.Replace (invocation, newInvocation);
}
}