@@ -74,29 +74,35 @@ public MapOption() {
7474 this . GenericParameterMap = [ ] ;
7575 }
7676 public MapOption (
77+ bool ignoreParams ,
7778 Dictionary < TypeDefinition , TypeDefinition > ? typeReplace = null ,
7879 Dictionary < MethodDefinition , MethodDefinition > ? methodReplace = null ,
7980 Dictionary < IGenericParameterProvider , IGenericParameterProvider > ? providers = null ,
8081 Dictionary < GenericParameter , TypeReference > ? genericParameterMap = null ) {
82+ this . IgnoreMethodParameter = ignoreParams ;
8183 this . MethodReplaceMap = methodReplace ?? [ ] ;
8284 this . TypeReplaceMap = typeReplace ?? [ ] ;
8385 this . GenericProvider = providers ?? [ ] ;
8486 this . GenericParameterMap = genericParameterMap ? . ToDictionary ( kv => GenerateKeyForGenericParameter ( kv . Key ) , kv => kv . Value ) ?? [ ] ;
8587 }
8688 public static MapOption Create (
89+ bool ignoreParams ,
8790 ( TypeDefinition from , TypeDefinition to ) [ ] ? replaceType = null ,
8891 ( MethodDefinition from , MethodDefinition to ) [ ] ? replaceMethod = null ,
8992 ( IGenericParameterProvider provideFrom , IGenericParameterProvider provideTo ) [ ] ? providers = null ,
9093 ( GenericParameter paramFrom , TypeReference typeTo ) [ ] ? genericParameterMap = null ) {
9194 return new MapOption (
95+ ignoreParams ,
9296 replaceType ? . ToDictionary ( x => x . from , x => x . to ) ?? [ ] ,
9397 replaceMethod ? . ToDictionary ( x => x . from , x => x . to ) ?? [ ] ,
9498 providers ? . ToDictionary ( x => x . provideFrom , x => x . provideTo ) ?? [ ] ,
9599 genericParameterMap ? . ToDictionary ( x => x . paramFrom , x => x . typeTo ) ?? [ ] ) ;
96100 }
97101 public static MapOption CreateGenericProviderMap (
102+ bool ignoreParams = false ,
98103 ( IGenericParameterProvider provideFrom , IGenericParameterProvider provideTo ) [ ] ? providers = null ) {
99104 return new MapOption (
105+ ignoreParams ,
100106 [ ] ,
101107 [ ] ,
102108 providers ? . ToDictionary ( x => x . provideFrom , x => x . provideTo ) ?? [ ] ) ;
@@ -105,6 +111,7 @@ public static MapOption CreateGenericProviderMap(
105111 public readonly Dictionary < MethodDefinition , MethodDefinition > MethodReplaceMap ;
106112 public readonly Dictionary < IGenericParameterProvider , IGenericParameterProvider > GenericProvider ;
107113 public readonly Dictionary < string , TypeReference > GenericParameterMap ;
114+ public readonly bool IgnoreMethodParameter ;
108115 }
109116 public static GenericInstanceType DeepMapGenericInstanceType ( GenericInstanceType instance , MapOption option ) {
110117 var pattern = instance . ElementType ;
@@ -237,7 +244,12 @@ public static MethodReference DeepMapMethodReference(MethodReference method, Map
237244 declaringType ) {
238245 HasThis = method . HasThis
239246 } ;
240- mref . Parameters . AddRange ( method . Parameters . Select ( p => new ParameterDefinition ( DeepMapTypeReference ( p . ParameterType , option ) ) ) ) ;
247+ mref . Parameters . AddRange ( method . Parameters . Select ( p => new ParameterDefinition (
248+ p . Name ,
249+ p . Attributes ,
250+ option . IgnoreMethodParameter
251+ ? p . ParameterType
252+ : DeepMapTypeReference ( p . ParameterType , option ) ) ) ) ;
241253
242254 return mref ;
243255 }
@@ -254,7 +266,7 @@ public static MethodDefinition DeepMapMethodDef(MethodDefinition method, MapOpti
254266 if ( option . MethodReplaceMap . TryGetValue ( method , out var mappedMethod ) ) {
255267 return mappedMethod ;
256268 }
257- MethodDefinition result = new MethodDefinition ( method . Name , method . Attributes , method . Module . TypeSystem . Void ) ;
269+ var result = new MethodDefinition ( method . Name , method . Attributes , method . Module . TypeSystem . Void ) ;
258270
259271 result . CustomAttributes . AddRange ( method . CustomAttributes . Select ( c => c . Clone ( ) ) ) ;
260272
@@ -278,7 +290,9 @@ public static MethodDefinition DeepMapMethodDef(MethodDefinition method, MapOpti
278290
279291 foreach ( var param in method . Parameters ) {
280292 var clonedParam = param . Clone ( ) ;
281- clonedParam . ParameterType = DeepMapTypeReference ( param . ParameterType , option ) ;
293+ if ( ! option . IgnoreMethodParameter ) {
294+ clonedParam . ParameterType = DeepMapTypeReference ( param . ParameterType , option ) ;
295+ }
282296 result . Parameters . Add ( clonedParam ) ;
283297 }
284298
@@ -424,11 +438,11 @@ Instruction ResolveInstrOff(int off) {
424438
425439 return copied ;
426440 }
427- public static TypeDefinition MemberClonedType ( TypeDefinition type , string newName , Dictionary < TypeDefinition , TypeDefinition > ? mappedTypes = null , Dictionary < MethodDefinition , MethodDefinition > ? mappedMethods = null ) {
441+ public static TypeDefinition MemberClonedType ( TypeDefinition type , string newName , bool ignoreMethodParameters , Dictionary < TypeDefinition , TypeDefinition > ? mappedTypes = null , Dictionary < MethodDefinition , MethodDefinition > ? mappedMethods = null ) {
428442 mappedTypes ??= [ ] ;
429443 mappedMethods ??= [ ] ;
430444 Dictionary < TypeDefinition , TypeDefinition > inputTypes = mappedTypes . ToDictionary ( ) ;
431- MapOption mapCondition = new MonoModCommon . Structure . MapOption ( mappedTypes , mappedMethods , [ ] , [ ] ) ;
445+ var mapCondition = new MapOption ( ignoreMethodParameters , mappedTypes , mappedMethods , [ ] , [ ] ) ;
432446
433447 static TypeDefinition ClonedType ( TypeDefinition type , string newName , Dictionary < TypeDefinition , TypeDefinition > mappedTypes ) {
434448
@@ -456,7 +470,7 @@ static TypeDefinition ClonedType(TypeDefinition type, string newName, Dictionary
456470 return copied ;
457471 }
458472 static void ClonedMember ( TypeDefinition from ,
459- MonoModCommon . Structure . MapOption mapContext ) {
473+ MapOption mapContext ) {
460474 var copied = mapContext . TypeReplaceMap [ from ] ;
461475
462476 foreach ( var interfaceImpl in from . Interfaces ) {
@@ -548,7 +562,7 @@ public static MethodReference CreateInstantiatedMethod(MethodReference impl) {
548562 return impl ;
549563 }
550564
551- MapOption option = new MapOption ( genericParameterMap : map ) ;
565+ MapOption option = new MapOption ( false , genericParameterMap : map ) ;
552566 return DeepMapMethodReference ( patten , option ) ;
553567 }
554568 /// <summary>
@@ -575,7 +589,7 @@ public static MethodReference CreateInstantiatedMethod(MethodDefinition methodDe
575589 return methodDef ;
576590 }
577591
578- MapOption option = new MapOption ( genericParameterMap : map ) ;
592+ var option = new MapOption ( false , genericParameterMap : map ) ;
579593 return DeepMapMethodReference ( methodDef , option ) ;
580594 }
581595 }
0 commit comments