@@ -14,17 +14,19 @@ public class TypeMover
1414		AssemblyDefinition  Source  {  get ;  } 
1515		AssemblyDefinition  Destination  {  get ;  } 
1616		string  DestinationPath  {  get ;  } 
17+ 		List < Type >  DelegateTypes  {  get ;  } 
1718		Dictionary < string ,  System . Reflection . Emit . TypeBuilder >  Types  {  get ;  } 
1819		DirectoryAssemblyResolver  Resolver  {  get ;  } 
1920
2021		MethodReference  consoleWriteLine ; 
2122		TypeDefinitionCache  cache ; 
2223
23- 		public  TypeMover  ( AssemblyDefinition  source ,  AssemblyDefinition  destination ,  string  destinationPath ,  Dictionary < string ,  System . Reflection . Emit . TypeBuilder >  types ,  DirectoryAssemblyResolver  resolver ,  TypeDefinitionCache  cache ) 
24+ 		public  TypeMover  ( AssemblyDefinition  source ,  AssemblyDefinition  destination ,  string  destinationPath ,  List < Type >   delegateTypes ,   Dictionary < string ,  System . Reflection . Emit . TypeBuilder >  types ,  DirectoryAssemblyResolver  resolver ,  TypeDefinitionCache  cache ) 
2425		{ 
2526			Source  =  source ; 
2627			Destination  =  destination ; 
2728			DestinationPath  =  destinationPath ; 
29+ 			DelegateTypes  =  delegateTypes ; 
2830			Types  =  types ; 
2931			Resolver  =  resolver ; 
3032			this . cache  =  cache ; 
@@ -45,6 +47,11 @@ public void Move ()
4547			typeMap . Clear  ( ) ; 
4648			resolvedTypeMap . Clear  ( ) ; 
4749
50+ 			foreach  ( var  type  in  DelegateTypes )  { 
51+ 				MoveDelegate  ( type ) ; 
52+ 				movedTypesCount ++ ; 
53+ 			} 
54+ 
4855			foreach  ( var  type  in  Types . Values )  { 
4956				Move  ( type ) ; 
5057				movedTypesCount ++ ; 
@@ -71,6 +78,34 @@ bool TypeIsEmptyOrHasOnlyDefaultConstructor (TypeDefinition type)
7178			return  ! type . HasMethods  ||  ( type . Methods . Count  ==  1  &&  type . Methods  [ 0 ] . IsConstructor ) ; 
7279		} 
7380
81+ 		void  MoveDelegate  ( Type  type ) 
82+ 		{ 
83+ 			var  typeSrc  =  Source . MainModule . GetType  ( type . GetCecilName  ( ) ) ; 
84+ 			var  typeDst  =  new  TypeDefinition  ( "" ,  typeSrc . Name ,  typeSrc . Attributes ) ; 
85+ 			var  module  =  Destination . MainModule ; 
86+ 
87+ 			if  ( App . Verbose )  { 
88+ 				Console . Write  ( $ "Moving delegate type ") ; 
89+ 				App . ColorWrite  ( $ "{ typeSrc . FullName } ,{ typeSrc . Module . FileName } ",  ConsoleColor . Yellow ) ; 
90+ 				Console . Write  ( " to " ) ; 
91+ 				App . ColorWriteLine  ( $ "{ Destination . MainModule . FileName } ",  ConsoleColor . Yellow ) ; 
92+ 			} 
93+ 
94+ 			typeDst . BaseType  =  GetUpdatedType  ( typeSrc . BaseType ,  module ) ; 
95+ 
96+ 			foreach  ( var  m  in  typeSrc . Methods )  { 
97+ 				var  md  =  new  MethodDefinition  ( m . Name ,  m . Attributes ,  GetUpdatedType  ( m . ReturnType ,  module ) ) ; 
98+ 				md . ImplAttributes  =  m . ImplAttributes ; 
99+ 
100+ 				foreach  ( var  p  in  m . Parameters ) 
101+ 					md . Parameters . Add  ( new  ParameterDefinition  ( p . Name ,  p . Attributes ,  GetUpdatedType  ( p . ParameterType ,  module ) ) ) ; 
102+ 
103+ 				typeDst . Methods . Add  ( md ) ; 
104+ 			} 
105+ 
106+ 			Destination . MainModule . Types . Add  ( typeDst ) ; 
107+ 		} 
108+ 
74109		void  Move  ( Type  type ) 
75110		{ 
76111			var  typeSrc  =  Source . MainModule . GetType  ( type . GetCecilName  ( ) ) ; 
@@ -343,6 +378,7 @@ MethodReference GetActionConstructor (TypeReference type, ModuleDefinition modul
343378					var  mr  =  GetUpdatedMethod  ( m ,  module ) ; 
344379					if  ( type  is  GenericInstanceType ) 
345380						mr . DeclaringType  =  type ; 
381+ 
346382					return  mr ; 
347383				} 
348384			} 
0 commit comments