Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        // 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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public static Delegate PredicateForName(GrainInfo Info)
        {
            Delegate Proc = DelegateFromInfo(Info, DT => typeof(Func <, ,>).MakeGenericType(typeof(WgContext), DT, typeof(bool)));

            return(Proc);
        }
Esempio n. 5
0
        public static Delegate ActionForName(GrainInfo Info)
        {
            Delegate Proc = DelegateFromInfo(Info, DT => typeof(Action <,>).MakeGenericType(typeof(WgContext), DT));

            return(Proc);
        }