@@ -99,10 +99,10 @@ private static async Task<bool> Load(HotfixModule newModule, AppSetting setting,
9999 DoingHotfix = true ;
100100 var oldModuleHash = oldModule . GetHashCode ( ) ;
101101 OldModuleMap . TryAdd ( oldModuleHash , oldModule ) ;
102- // 延迟10分钟后清理旧模块
102+ // 延迟10分钟后清理旧模块
103103 _ = Task . Run ( async ( ) =>
104104 {
105- await Task . Delay ( TimeSpan . FromMinutes ( 10 ) ) ;
105+ await Task . Delay ( TimeSpan . FromMinutes ( 10 ) ) ;
106106 OldModuleMap . TryRemove ( oldModuleHash , out _ ) ;
107107 oldModule . Unload ( ) ;
108108 DoingHotfix = ! OldModuleMap . IsEmpty ;
@@ -133,14 +133,44 @@ public static Task Stop(string message = "")
133133 /// </summary>
134134 internal static Type GetAgentType ( Type compType )
135135 {
136+ if ( OldModuleMap . IsEmpty )
137+ {
138+ return _module . GetAgentType ( compType ) ;
139+ }
140+
141+ var compTypeAssembly = compType . Assembly ;
142+ foreach ( var kv in OldModuleMap )
143+ {
144+ var old = kv . Value ;
145+ if ( compTypeAssembly == old . HotfixAssembly )
146+ {
147+ return old . GetAgentType ( compType ) ;
148+ }
149+ }
150+
136151 return _module . GetAgentType ( compType ) ;
137152 }
138153
139154 /// <summary>
140155 /// 获取代理对应的组件类型
141156 /// </summary>
142- internal static Type GetCompType ( Type agentType )
157+ internal static Type GetComponentType ( Type agentType )
143158 {
159+ if ( OldModuleMap . IsEmpty )
160+ {
161+ return _module . GetComponentType ( agentType ) ;
162+ }
163+
164+ var agentTypeAssembly = agentType . Assembly ;
165+ foreach ( var kv in OldModuleMap )
166+ {
167+ var old = kv . Value ;
168+ if ( agentTypeAssembly == old . HotfixAssembly )
169+ {
170+ return old . GetComponentType ( agentType ) ;
171+ }
172+ }
173+
144174 return _module . GetComponentType ( agentType ) ;
145175 }
146176
@@ -153,17 +183,19 @@ internal static Type GetCompType(Type agentType)
153183 /// <returns>返回代理实例</returns>
154184 public static T GetAgent < T > ( BaseComponent component , Type refAssemblyType ) where T : IComponentAgent
155185 {
156- if ( ! OldModuleMap . IsEmpty )
186+ if ( OldModuleMap . IsEmpty )
157187 {
158- var asb = typeof ( T ) . Assembly ;
159- var asb2 = refAssemblyType ? . Assembly ;
160- foreach ( var kv in OldModuleMap )
188+ return _module . GetAgent < T > ( component ) ;
189+ }
190+
191+ var assembly = typeof ( T ) . Assembly ;
192+ var refAssembly = refAssemblyType ? . Assembly ;
193+ foreach ( var kv in OldModuleMap )
194+ {
195+ var old = kv . Value ;
196+ if ( assembly == old . HotfixAssembly || refAssembly == old . HotfixAssembly )
161197 {
162- var old = kv . Value ;
163- if ( asb == old . HotfixAssembly || asb2 == old . HotfixAssembly )
164- {
165- return old . GetAgent < T > ( component ) ;
166- }
198+ return old . GetAgent < T > ( component ) ;
167199 }
168200 }
169201
@@ -235,16 +267,18 @@ public static T GetInstance<T>(string typeName, Type refAssemblyType = null)
235267 return default ;
236268 }
237269
238- if ( OldModuleMap . Count > 0 )
270+ if ( OldModuleMap . IsEmpty )
271+ {
272+ return _module . GetInstance < T > ( typeName ) ;
273+ }
274+
275+ var asb = refAssemblyType ? . Assembly ;
276+ foreach ( var kv in OldModuleMap )
239277 {
240- var asb = refAssemblyType ? . Assembly ;
241- foreach ( var kv in OldModuleMap )
278+ var old = kv . Value ;
279+ if ( asb == old . HotfixAssembly )
242280 {
243- var old = kv . Value ;
244- if ( asb == old . HotfixAssembly )
245- {
246- return old . GetInstance < T > ( typeName ) ;
247- }
281+ return old . GetInstance < T > ( typeName ) ;
248282 }
249283 }
250284
0 commit comments