@@ -20,10 +20,6 @@ public class ModuleWeaver : BaseModuleWeaver
2020 MethodReference getEnumerator ;
2121 MethodReference getInvariantCulture ;
2222 MethodReference formatMethod ;
23- TypeDefinition stringType ;
24- TypeReference objectTypeRef ;
25- TypeDefinition objectTypeDef ;
26- TypeReference booleanType ;
2723
2824 public IEnumerable < TypeDefinition > GetMatchingTypes ( )
2925 {
@@ -42,18 +38,14 @@ public override IEnumerable<string> GetAssembliesForScanning()
4238 public override void Execute ( )
4339 {
4440 var stringBuildType = FindType ( "System.Text.StringBuilder" ) ;
45- objectTypeDef = FindType ( "System.Object" ) ;
46- objectTypeRef = ModuleDefinition . ImportReference ( objectTypeDef ) ;
47- booleanType = ModuleDefinition . ImportReference ( FindType ( "System.Boolean" ) ) ;
4841 stringBuilderType = ModuleDefinition . ImportReference ( stringBuildType ) ;
4942 appendString = ModuleDefinition . ImportReference ( stringBuildType . FindMethod ( "Append" , "Object" ) ) ;
5043 var enumeratorType = FindType ( "System.Collections.IEnumerator" ) ;
5144 moveNext = ModuleDefinition . ImportReference ( enumeratorType . FindMethod ( "MoveNext" ) ) ;
5245 current = ModuleDefinition . ImportReference ( enumeratorType . Properties . Single ( x => x . Name == "Current" ) . GetMethod ) ;
5346 var enumerableType = FindType ( "System.Collections.IEnumerable" ) ;
5447 getEnumerator = ModuleDefinition . ImportReference ( enumerableType . FindMethod ( "GetEnumerator" ) ) ;
55- stringType = FindType ( "System.String" ) ;
56- formatMethod = ModuleDefinition . ImportReference ( stringType . FindMethod ( "Format" , "IFormatProvider" , "String" , "Object[]" ) ) ;
48+ formatMethod = ModuleDefinition . ImportReference ( TypeSystem . StringDefinition . FindMethod ( "Format" , "IFormatProvider" , "String" , "Object[]" ) ) ;
5749
5850 var cultureInfoType = FindType ( "System.Globalization.CultureInfo" ) ;
5951 var invariantCulture = cultureInfoType . Properties . Single ( x => x . Name == "InvariantCulture" ) ;
@@ -69,9 +61,9 @@ void AddToString(TypeDefinition type)
6961 {
7062 var methodAttributes = MethodAttributes . Public | MethodAttributes . HideBySig | MethodAttributes . Virtual ;
7163
72- var method = new MethodDefinition ( "ToString" , methodAttributes , stringType ) ;
64+ var method = new MethodDefinition ( "ToString" , methodAttributes , TypeSystem . StringReference ) ;
7365 var variables = method . Body . Variables ;
74- variables . Add ( new VariableDefinition ( new ArrayType ( objectTypeRef ) ) ) ;
66+ variables . Add ( new VariableDefinition ( new ArrayType ( TypeSystem . ObjectReference ) ) ) ;
7567 var allProperties = type . GetProperties ( ) . Where ( x => ! x . HasParameters ) . ToArray ( ) ;
7668 var properties = RemoveIgnoredProperties ( allProperties ) ;
7769
@@ -89,9 +81,9 @@ void AddToString(TypeDefinition type)
8981 var enumeratorType = ModuleDefinition . ImportReference ( typeof ( IEnumerator ) ) ;
9082 variables . Add ( new VariableDefinition ( enumeratorType ) ) ;
9183
92- variables . Add ( new VariableDefinition ( booleanType ) ) ;
84+ variables . Add ( new VariableDefinition ( TypeSystem . BooleanReference ) ) ;
9385
94- variables . Add ( new VariableDefinition ( new ArrayType ( objectTypeRef ) ) ) ;
86+ variables . Add ( new VariableDefinition ( new ArrayType ( TypeSystem . ObjectReference ) ) ) ;
9587 }
9688
9789 var genericOffset = ! type . HasGenericParameters ? 0 : type . GenericParameters . Count ;
@@ -128,7 +120,7 @@ void AddGenericParameterNames(TypeDefinition type, Collection<Instruction> ins)
128120 {
129121 var typeType = ModuleDefinition . ImportReference ( typeof ( Type ) ) . Resolve ( ) ;
130122 var memberInfoType = ModuleDefinition . ImportReference ( typeof ( System . Reflection . MemberInfo ) ) . Resolve ( ) ;
131- var getTypeMethod = ModuleDefinition . ImportReference ( objectTypeDef . FindMethod ( "GetType" ) ) ;
123+ var getTypeMethod = ModuleDefinition . ImportReference ( TypeSystem . ObjectDefinition . FindMethod ( "GetType" ) ) ;
132124 var getGenericArgumentsMethod = ModuleDefinition . ImportReference ( typeType . FindMethod ( "GetGenericArguments" ) ) ;
133125 var nameProperty = memberInfoType . Properties . Single ( x => x . Name == "Name" ) ;
134126 var nameGet = ModuleDefinition . ImportReference ( nameProperty . GetMethod ) ;
@@ -161,8 +153,8 @@ void AddMethodAttributes(MethodDefinition method)
161153 var version = typeof ( ModuleWeaver ) . Assembly . GetName ( ) . Version . ToString ( ) ;
162154
163155 var generatedAttribute = new CustomAttribute ( generatedConstructor ) ;
164- generatedAttribute . ConstructorArguments . Add ( new CustomAttributeArgument ( stringType , "Fody.ToString" ) ) ;
165- generatedAttribute . ConstructorArguments . Add ( new CustomAttributeArgument ( stringType , version ) ) ;
156+ generatedAttribute . ConstructorArguments . Add ( new CustomAttributeArgument ( TypeSystem . StringReference , "Fody.ToString" ) ) ;
157+ generatedAttribute . ConstructorArguments . Add ( new CustomAttributeArgument ( TypeSystem . StringReference , version ) ) ;
166158 method . CustomAttributes . Add ( generatedAttribute ) ;
167159
168160 var debuggerConstructor = ModuleDefinition . ImportReference ( typeof ( DebuggerNonUserCodeAttribute ) . GetConstructor ( Type . EmptyTypes ) ) ;
@@ -182,7 +174,7 @@ void AddInitCode(Collection<Instruction> ins, string format, PropertyDefinition[
182174 ins . Add ( Instruction . Create ( OpCodes . Call , getInvariantCulture ) ) ;
183175 ins . Add ( Instruction . Create ( OpCodes . Ldstr , format ) ) ;
184176 ins . Add ( Instruction . Create ( OpCodes . Ldc_I4 , properties . Length + genericOffset ) ) ;
185- ins . Add ( Instruction . Create ( OpCodes . Newarr , objectTypeRef ) ) ;
177+ ins . Add ( Instruction . Create ( OpCodes . Newarr , TypeSystem . ObjectReference ) ) ;
186178 ins . Add ( Instruction . Create ( OpCodes . Stloc_0 ) ) ;
187179 }
188180
@@ -268,7 +260,7 @@ void AddPropertyCode(MethodBody body, int index, PropertyDefinition property, Ty
268260 t . Add ( Instruction . Create ( OpCodes . Ldstr , format ) ) ;
269261
270262 t . Add ( Instruction . Create ( OpCodes . Ldc_I4 , 1 ) ) ;
271- t . Add ( Instruction . Create ( OpCodes . Newarr , objectTypeRef ) ) ;
263+ t . Add ( Instruction . Create ( OpCodes . Newarr , TypeSystem . ObjectReference ) ) ;
272264 t . Add ( Instruction . Create ( OpCodes . Stloc , body . Variables [ 4 ] ) ) ;
273265 t . Add ( Instruction . Create ( OpCodes . Ldloc , body . Variables [ 4 ] ) ) ;
274266
0 commit comments