public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { Type ValueType = value.GetType(); Type DataType = WgContext.GetIfAction(ValueType) ?? WgContext.GetIfPredicate(ValueType); GrainInfo Info = WgContext.InfoFromDelegate((Delegate)value, DataType); serializer.Serialize(writer, Info); }
// delegate deserialization protected static Delegate DelegateFromInfo(GrainInfo Info, Func <Type, Type> DelTypeMaker) { if (Info == null) { return(null); } Assembly MethodAssembly = Assembly.Load(Info.MethodAssembly); Type MethodClass = MethodAssembly.GetType(Info.MethodClass); Assembly DataAssembly = Assembly.Load(Info.DataAssembly); Type DataType = DataAssembly.GetType(Info.DataType); Type ActionType = DelTypeMaker(DataType); Delegate Proc = Delegate.CreateDelegate(ActionType, MethodClass, Info.MethodName, false, false); return(Proc); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { GrainInfo Info = serializer.Deserialize <GrainInfo> (reader); Delegate Proc = null; Type DataType = null; DataType = WgContext.GetIfAction(objectType); if (objectType == typeof(Delegate) || DataType != null) // if Action<WgContext,T> or a generic delegate { Proc = WgContext.ActionForName(Info); } else { DataType = WgContext.GetIfPredicate(objectType); // if predicate if (DataType != null) { Proc = WgContext.PredicateForName(Info); } } return(Proc); }
public static Delegate PredicateForName(GrainInfo Info) { Delegate Proc = DelegateFromInfo(Info, DT => typeof(Func <, ,>).MakeGenericType(typeof(WgContext), DT, typeof(bool))); return(Proc); }
public static Delegate ActionForName(GrainInfo Info) { Delegate Proc = DelegateFromInfo(Info, DT => typeof(Action <,>).MakeGenericType(typeof(WgContext), DT)); return(Proc); }