Skip to content

Commit a724d06

Browse files
committed
Move methods
1 parent 4f46139 commit a724d06

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

WpfAnalyzers/CodeFixes/ImplementValueConverterFix.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ semanticModel is { } &&
7979
{
8080
context.RegisterCodeFix(
8181
"Implement IMultiValueConverter.ConvertBack for one way bindings.",
82-
(editor, _) => editor.AddMethod(classDeclaration, IMultiValueConverterConvertBack(classDeclaration.Identifier.ValueText)),
82+
(editor, _) => editor.AddMethod(classDeclaration, IMultiValueConverter.ConvertBack(classDeclaration.Identifier.ValueText)),
8383
"Implement IMultiValueConverter",
8484
diagnostic);
8585
}
@@ -108,17 +108,6 @@ private static bool HasInterface(ClassDeclarationSyntax classDeclaration, Qualif
108108
return false;
109109
}
110110

111-
private static MethodDeclarationSyntax IMultiValueConverterConvertBack(string containingTypeName)
112-
{
113-
var code = StringBuilderPool.Borrow()
114-
.AppendLine(" object[] System.Windows.Data.IMultiValueConverter.ConvertBack(object value, System.Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)")
115-
.AppendLine(" {")
116-
.AppendLine($" throw new System.NotSupportedException($\"{{nameof({containingTypeName})}} can only be used in OneWay bindings\");")
117-
.AppendLine(" }")
118-
.Return();
119-
return ParseMethod(code);
120-
}
121-
122111
private static TypeSyntax ParseTypeName(string text) => SyntaxFactory.ParseTypeName(text).WithSimplifiedNames();
123112

124113
private static TypeSyntax Object(NullableContext nullableContext) => nullableContext switch
@@ -127,14 +116,6 @@ private static MethodDeclarationSyntax IMultiValueConverterConvertBack(string co
127116
_ => SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.ObjectKeyword)),
128117
};
129118

130-
private static MethodDeclarationSyntax ParseMethod(string code)
131-
{
132-
return Parse.MethodDeclaration(code)
133-
.WithSimplifiedNames()
134-
.WithLeadingTrivia(SyntaxFactory.ElasticMarker)
135-
.WithTrailingTrivia(SyntaxFactory.ElasticMarker);
136-
}
137-
138119
private static class IValueConverter
139120
{
140121
internal static MethodDeclarationSyntax Convert(SyntaxGenerator generator, NullableContext nullableContext)
@@ -215,5 +196,24 @@ internal static MethodDeclarationSyntax Convert(SyntaxGenerator generator, Nulla
215196
},
216197
statements: new[] { generator.ThrowStatement(generator.ObjectCreationExpression(ParseTypeName("System.NotImplementedException"))) });
217198
}
199+
200+
internal static MethodDeclarationSyntax ConvertBack(string containingTypeName)
201+
{
202+
var code = StringBuilderPool.Borrow()
203+
.AppendLine(" object[] System.Windows.Data.IMultiValueConverter.ConvertBack(object value, System.Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)")
204+
.AppendLine(" {")
205+
.AppendLine($" throw new System.NotSupportedException($\"{{nameof({containingTypeName})}} can only be used in OneWay bindings\");")
206+
.AppendLine(" }")
207+
.Return();
208+
return ParseMethod(code);
209+
210+
static MethodDeclarationSyntax ParseMethod(string code)
211+
{
212+
return Parse.MethodDeclaration(code)
213+
.WithSimplifiedNames()
214+
.WithLeadingTrivia(SyntaxFactory.ElasticMarker)
215+
.WithTrailingTrivia(SyntaxFactory.ElasticMarker);
216+
}
217+
}
218218
}
219219
}

0 commit comments

Comments
 (0)