22using System ;
33using System . Collections . Generic ;
44using System . Linq ;
5- using System . Text ;
65
76namespace DevExpress . Mvvm . CodeGenerators {
8- enum ChangeEventRaiseMode {
9- EventArgs , PropertyName
10- }
7+ enum ChangeEventRaiseMode { EventArgs , PropertyName }
118 static class ClassGenerator {
12- static readonly string defaultUsings =
9+ const string defaultUsings =
1310@"using System.Collections.Generic;
1411using System.ComponentModel;" ;
1512
@@ -38,13 +35,14 @@ public static void GenerateSourceCode(SourceBuilder source, ContextInfo contextI
3835 }
3936 if ( implISPVM ) {
4037 mvvmComponentsList . Add ( "ISupportParentViewModel" ) ;
41- bool shouldGenerateChangedMethod = ClassHelper . ShouldGenerateISPVMChangedMethod ( classSymbol ) ;
42- if ( contextInfo . IsMvvmAvailable && contextInfo . ISPVMSymbol != null && ! ClassHelper . IsInterfaceImplemented ( classSymbol , contextInfo . ISPVMSymbol , contextInfo ) )
38+ if ( contextInfo . IsMvvmAvailable && ! ClassHelper . IsInterfaceImplemented ( classSymbol , contextInfo . ISPVMSymbol ! , contextInfo ) ) {
39+ bool shouldGenerateChangedMethod = ClassHelper . ContainISPVMChangedMethod ( classSymbol ) ;
4340 interfaces . Add ( new ISupportParentViewModelGenerator ( shouldGenerateChangedMethod ) ) ;
41+ }
4442 }
4543 if ( implISS ) {
4644 mvvmComponentsList . Add ( "ISupportServices" ) ;
47- if ( contextInfo . IsMvvmAvailable && contextInfo . ISSSymbol != null && ! ClassHelper . IsInterfaceImplementedInCurrentClass ( classSymbol , contextInfo . ISSSymbol ) )
45+ if ( contextInfo . IsMvvmAvailable && ! ClassHelper . IsInterfaceImplementedInCurrentClass ( classSymbol , contextInfo . ISSSymbol ! ) )
4846 interfaces . Add ( new ISupportServicesGenerator ( ) ) ;
4947 }
5048
@@ -55,18 +53,17 @@ public static void GenerateSourceCode(SourceBuilder source, ContextInfo contextI
5553
5654 Dictionary < string , TypeKind > outerClasses = ClassHelper . GetOuterClasses ( classSymbol ) ;
5755
58- source = GenerateHeader ( classSymbol , interfaces ,
59- impelementRaiseChangedMethod ? inpcedInfo . RaiseMethodImplementation : null ,
60- impelementRaiseChangingMethod ? inpcingInfo . RaiseMethodImplementation : null ,
61- genericTypes , outerClasses , source ,
62- addDevExpressUsing : contextInfo . IsMvvmAvailable ) ;
56+ source = GenerateHeader ( source , classSymbol , interfaces ,
57+ impelementRaiseChangedMethod ? inpcedInfo . RaiseMethodImplementation : null ,
58+ impelementRaiseChangingMethod ? inpcingInfo . RaiseMethodImplementation : null ,
59+ genericTypes , outerClasses , contextInfo . IsMvvmAvailable ) ;
6360
6461
6562 bool needStaticChangedEventArgs = inpcedInfo . HasRaiseMethodWithEventArgsParameter || impelementRaiseChangedMethod ;
6663 bool needStaticChangingEventArgs = inpcingInfo . HasAttribute && ( inpcingInfo . HasRaiseMethodWithEventArgsParameter || impelementRaiseChangingMethod ) ;
67- IReadOnlyList < string > propertyNames = GenerateProperties ( contextInfo , classSymbol , inpcedInfo , inpcingInfo , needStaticChangedEventArgs , needStaticChangingEventArgs , source ) ;
64+ IReadOnlyList < string > propertyNames = GenerateProperties ( source , contextInfo , classSymbol , inpcedInfo , inpcingInfo , needStaticChangedEventArgs , needStaticChangingEventArgs ) ;
6865
69- GenerateCommands ( contextInfo , classSymbol , contextInfo . IsMvvmAvailable , source , out bool hasCommands ) ;
66+ GenerateCommands ( source , contextInfo , classSymbol , contextInfo . IsMvvmAvailable , out bool hasCommands ) ;
7067 if ( hasCommands )
7168 mvvmComponentsList . Add ( "Commands" ) ;
7269
@@ -80,7 +77,7 @@ public static void GenerateSourceCode(SourceBuilder source, ContextInfo contextI
8077 contextInfo . Context . ReportMVVMNotAvailable ( classSymbol , mvvmComponentsList ) ;
8178 }
8279
83- static SourceBuilder GenerateHeader ( INamedTypeSymbol classSymbol , List < IInterfaceGenerator > interfaces , string ? raiseChangedMethod , string ? raiseChangingMethod , List < ITypeSymbol > genericTypes , Dictionary < string , TypeKind > outerClasses , SourceBuilder source , bool addDevExpressUsing ) {
80+ static SourceBuilder GenerateHeader ( SourceBuilder source , INamedTypeSymbol classSymbol , List < IInterfaceGenerator > interfaces , string ? raiseChangedMethod , string ? raiseChangingMethod , List < ITypeSymbol > genericTypes , Dictionary < string , TypeKind > outerClasses , bool addDevExpressUsing ) {
8481 source . AppendLine ( defaultUsings ) ;
8582 if ( addDevExpressUsing )
8683 source . AppendLine ( "using DevExpress.Mvvm;" ) ;
@@ -126,16 +123,16 @@ static void AppendGenericArguments(SourceBuilder source, List<ITypeSymbol> gener
126123 source . Append ( '>' ) ;
127124 }
128125 }
129- static IReadOnlyList < string > GenerateProperties ( ContextInfo contextInfo , INamedTypeSymbol classSymbol , INPCInfo inpcedInfo , INPCInfo inpcingInfo , bool needStaticChangedEventArgs , bool needStaticChangingEventArgs , SourceBuilder source ) {
130- ChangeEventRaiseMode ? changedRaiseMode = needStaticChangedEventArgs
131- ? ChangeEventRaiseMode . EventArgs
132- : inpcedInfo . HasRaiseMethodWithStringParameter
133- ? ChangeEventRaiseMode . PropertyName
126+ static IReadOnlyList < string > GenerateProperties ( SourceBuilder source , ContextInfo contextInfo , INamedTypeSymbol classSymbol , INPCInfo inpcedInfo , INPCInfo inpcingInfo , bool needStaticChangedEventArgs , bool needStaticChangingEventArgs ) {
127+ ChangeEventRaiseMode ? changedRaiseMode = needStaticChangedEventArgs
128+ ? ChangeEventRaiseMode . EventArgs
129+ : inpcedInfo . HasRaiseMethodWithStringParameter
130+ ? ChangeEventRaiseMode . PropertyName
134131 : default ( ChangeEventRaiseMode ? ) ;
135- ChangeEventRaiseMode ? changingRaiseMode = needStaticChangingEventArgs
136- ? ChangeEventRaiseMode . EventArgs
137- : inpcingInfo . HasAttribute && inpcingInfo . HasRaiseMethodWithStringParameter
138- ? ChangeEventRaiseMode . PropertyName
132+ ChangeEventRaiseMode ? changingRaiseMode = needStaticChangingEventArgs
133+ ? ChangeEventRaiseMode . EventArgs
134+ : inpcingInfo . HasAttribute && inpcingInfo . HasRaiseMethodWithStringParameter
135+ ? ChangeEventRaiseMode . PropertyName
139136 : default ( ChangeEventRaiseMode ? ) ;
140137 bool generateProperties = true ;
141138 List < string > propertyNames = new ( ) ;
@@ -160,7 +157,7 @@ static IReadOnlyList<string> GenerateProperties(ContextInfo contextInfo, INamedT
160157 return propertyNames ;
161158 }
162159
163- static void GenerateCommands ( ContextInfo contextInfo , INamedTypeSymbol classSymbol , bool isMvvmAvailable , SourceBuilder source , out bool hasCommands ) {
160+ static void GenerateCommands ( SourceBuilder source , ContextInfo contextInfo , INamedTypeSymbol classSymbol , bool isMvvmAvailable , out bool hasCommands ) {
164161 IEnumerable < IMethodSymbol > commandCandidates = ClassHelper . GetCommandCandidates ( classSymbol , contextInfo . CommandAttributeSymbol ) ;
165162 hasCommands = commandCandidates . Any ( ) ;
166163 if ( isMvvmAvailable ) {
0 commit comments