|  |  | @ -13,8 +13,6 @@ namespace TNodeCore.Runtime.RuntimeCache{ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public class PortAccessor<T1, T2>:IModelPortAccessor{ |  |  |  |     public class PortAccessor<T1, T2>:IModelPortAccessor{ | 
			
		
	
		
		
			
				
					
					|  |  |  |         public readonly Func<T1, T2> Get; |  |  |  |         public readonly Func<T1, T2> Get; | 
			
		
	
		
		
			
				
					
					|  |  |  |         public readonly Action<T1, T2> Set; |  |  |  |         public readonly Action<T1, T2> Set; | 
			
		
	
		
		
			
				
					
					|  |  |  |         private readonly Action<T1> _resetFunc; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         private readonly T2 _defaultValue; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         public PortAccessor(string name,bool property){ |  |  |  |         public PortAccessor(string name,bool property){ | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (property){ |  |  |  |             if (property){ | 
			
		
	
		
		
			
				
					
					|  |  |  |                 Type t = typeof(T1); |  |  |  |                 Type t = typeof(T1); | 
			
		
	
	
		
		
			
				
					|  |  | @ -22,21 +20,10 @@ namespace TNodeCore.Runtime.RuntimeCache{ | 
			
		
	
		
		
			
				
					
					|  |  |  |                 MethodInfo getter = t.GetMethod("get_" + name); |  |  |  |                 MethodInfo getter = t.GetMethod("get_" + name); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 MethodInfo setter = t.GetMethod("set_" + name); |  |  |  |                 MethodInfo setter = t.GetMethod("set_" + name); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 Type = getter?.ReturnType??setter?.GetParameters()[0].ParameterType; |  |  |  |                 Type = getter?.ReturnType??setter?.GetParameters()[0].ParameterType; | 
			
		
	
		
		
			
				
					
					|  |  |  |                  |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if(getter!=null) |  |  |  |                 if(getter!=null) | 
			
		
	
		
		
			
				
					
					|  |  |  |                     Get = (Func<T1, T2>)Delegate.CreateDelegate(typeof(Func<T1, T2>), null, getter); |  |  |  |                     Get = (Func<T1, T2>)Delegate.CreateDelegate(typeof(Func<T1, T2>), null, getter); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if(setter!=null) |  |  |  |                 if(setter!=null) | 
			
		
	
		
		
			
				
					
					|  |  |  |                     Set = (Action<T1, T2>)Delegate.CreateDelegate(typeof(Action<T1, T2>), null, setter); |  |  |  |                     Set = (Action<T1, T2>)Delegate.CreateDelegate(typeof(Action<T1, T2>), null, setter); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (Set != null){ |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     var dummy = Activator.CreateInstance<T1>(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |          |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if (Get != null) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         _defaultValue = Get(dummy); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     _resetFunc += (obj) => { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         Set(obj, _defaultValue); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     }; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |             else{ |  |  |  |             else{ | 
			
		
	
		
		
			
				
					
					|  |  |  |                 Type t = typeof(T1); |  |  |  |                 Type t = typeof(T1); | 
			
		
	
	
		
		
			
				
					|  |  | @ -59,12 +46,6 @@ namespace TNodeCore.Runtime.RuntimeCache{ | 
			
		
	
		
		
			
				
					
					|  |  |  |         public void SetValue(object model, object value){ |  |  |  |         public void SetValue(object model, object value){ | 
			
		
	
		
		
			
				
					
					|  |  |  |             Set((T1)model,(T2)value); |  |  |  |             Set((T1)model,(T2)value); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         public void Reset(object model){ |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             //Get  |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             _resetFunc?.Invoke((T1)model); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         public Type Type{ get; set; } |  |  |  |         public Type Type{ get; set; } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -233,21 +214,19 @@ namespace TNodeCore.Runtime.RuntimeCache{ | 
			
		
	
		
		
			
				
					
					|  |  |  |          |  |  |  |          | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         private void CachingImplicitConversion(Type baseType, Type targetType){ |  |  |  |         private void CachingImplicitConversion(Type baseType, Type targetType){ | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (!HasImplicitConversion(baseType, targetType)) return; |  |  |  |             if (HasImplicitConversion(baseType, targetType)) return; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             if (CachedPortConverters.ContainsKey(baseType)&&CachedPortConverters[baseType].ContainsKey(targetType)) return; |  |  |  |              | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             //Create Implicit Conversion Helper that caches the implicit cast function |  |  |  |             //Create Implicit Conversion Helper that caches the implicit cast function | 
			
		
	
		
		
			
				
					
					|  |  |  |             var typeConverter = Activator.CreateInstance(typeof(ImplicitConversionHelper<,>).MakeGenericType(baseType, targetType)) as IPortConverterHelper; |  |  |  |             var typeConverter = Activator.CreateInstance(typeof(ImplicitConversionHelper<,>).MakeGenericType(baseType, targetType)) as IPortConverterHelper; | 
			
		
	
		
		
			
				
					
					|  |  |  |              |  |  |  |              | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (!CachedPortConverters.ContainsKey(baseType)){ |  |  |  |             if (!CachedPortConverters.ContainsKey(baseType)){ | 
			
		
	
		
		
			
				
					
					|  |  |  |                 CachedPortConverters.Add(baseType,new Dictionary<Type,IPortConverterHelper>()); |  |  |  |                 CachedPortConverters.Add(baseType,new Dictionary<Type,IPortConverterHelper>()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |       |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             CachedPortConverters[baseType].Add(targetType,typeConverter); |  |  |  |             CachedPortConverters[baseType].Add(targetType,typeConverter); | 
			
		
	
		
		
			
				
					
					|  |  |  |            |  |  |  |            | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |          |  |  |  |          | 
			
		
	
		
		
			
				
					
					|  |  |  |         public object GetConvertedValue(Type from,Type to,object value){ |  |  |  |         public object GetConvertedValue(Type from,Type to,object value){ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             if(!CachedPortConverters.ContainsKey(from)){ |  |  |  |             if(!CachedPortConverters.ContainsKey(from)){ | 
			
		
	
		
		
			
				
					
					|  |  |  |                 //Find the cached port failed ,check if there is an implicit conversion |  |  |  |                 //Find the cached port failed ,check if there is an implicit conversion | 
			
		
	
		
		
			
				
					
					|  |  |  |                 //This inner cache method would only run once,so add a guard to prevent it run again,even though the function itself has a guard statement. |  |  |  |                 //This inner cache method would only run once,so add a guard to prevent it run again,even though the function itself has a guard statement. | 
			
		
	
	
		
		
			
				
					|  |  | @ -405,20 +384,14 @@ namespace TNodeCore.Runtime.RuntimeCache{ | 
			
		
	
		
		
			
				
					
					|  |  |  |             var method = typeof(T2).GetMethod("op_Implicit", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(T1) }, null); |  |  |  |             var method = typeof(T2).GetMethod("op_Implicit", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(T1) }, null); | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (method == null){ |  |  |  |             if (method == null){ | 
			
		
	
		
		
			
				
					
					|  |  |  |                 //Search it in T1 |  |  |  |                 //Search it in T1 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 Debug.Log($"{typeof(T1)}"); |  |  |  |                 method = typeof(T1).GetMethod("op_Implicit", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(T2) }, null); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 method = typeof(T1).GetMethods(BindingFlags.Public | BindingFlags.Static).FirstOrDefault(x => x.ReturnType==typeof(T2) && x.Name=="op_Implicit"); |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |             //Create the delegate |  |  |  |             //Create the delegate | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (method != null)  |  |  |  |             if (method != null)  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 ConvertFunc = (Func<T1, T2>) Delegate.CreateDelegate(typeof(Func<T1, T2>), method); |  |  |  |                 ConvertFunc = (Func<T1, T2>) Delegate.CreateDelegate(typeof(Func<T1, T2>), method); | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (ConvertFunc == null){ |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 Debug.Log($"{method==null}"); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         public object Convert(object value){ |  |  |  |         public object Convert(object value){ | 
			
		
	
		
		
			
				
					
					|  |  |  |        |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             return ConvertFunc((T1) value); |  |  |  |             return ConvertFunc((T1) value); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |