예제 #1
0
        private VAL Valize(object host)
        {
            VAL val;

            if (this.valizer is string)
            {
                val = Script.Run(host, (string)valizer, new Memory());
                goto L1;
            }


            if (this.valizer is Valizer)
            {
                Valizer valizer = (Valizer)this.valizer;
                val = valizer(host);
                goto L1;
            }

            if (this.valizer is IValizer)
            {
                IValizer I = (IValizer)this.valizer;
                val = I.Valizer(host);
                goto L1;
            }

            if (this.valizer is string[])
            {
                string[] members = (string[])this.valizer;
                string   script  = "";
                for (int i = 0; i < members.Length; i++)
                {
                    if (i != 0)
                    {
                        script += ",";
                    }
                    script += string.Format("{0} : this.{0}", members[i]);
                }

                script = "{" + script + "}";

                val = Script.Run(host, script, new Memory());
                goto L1;
            }

            return(null);

L1:
            if (val.ty == VALTYPE.stringcon)
            {
                val.ty = VALTYPE.scriptcon;
            }

            val.Class = host.GetType().FullName;

            return(val);
        }
예제 #2
0
        public static Memory Encode(this object obj)
        {
            if (obj == null)
            {
                return(new Memory());
            }

            VAL val = Valizer.Valize(obj);

            return(new Memory(val));
        }
예제 #3
0
        public static T ReadObject <T>(this string json)
        {
            if (json == null)
            {
                return(default(T));
            }

            var val = Script.Evaluate(json);

            return(Valizer.Devalize <T>(val));
        }
예제 #4
0
        public static VAL functions(string func, VAL parameters, Memory DS)
        {
            if (func != "devalize" && parameters.Size != 2)
            {
                return(null);
            }

            var L0 = parameters[0];
            var L1 = parameters[1];

            Valizer.Devalize(L0, L1.Value);
            return(L1);
        }
예제 #5
0
        public static void Init()
        {
            Script.FunctionChain.Add(RemoteExtension.functions);

            Constant.MAX_STRING_SIZE = 20 * 1024 * 1024;

            Valizer.Register <DataSet>(
                ds => RemoteExtension.ToVal(ds),
                (host, type, xml) => RemoteExtension.ToDataSet(host, type, xml)
                );

            Valizer.Register <DataTable>(
                dt => RemoteExtension.ToVal(dt),
                (host, type, xml) => RemoteExtension.ToDataTable(host, type, xml)
                );
        }
예제 #6
0
        public bool TryGetValue <T>(string variable, VAL val, out T result)
        {
            Type type = typeof(T);

            if (typeof(T) == typeof(VAL))
            {
                result = (T)(object)val;
                return(true);
            }
            else if (val.Undefined || val.IsNull)
            {
                result = default(T);
                return(false);
            }
            else if (typeof(T) == typeof(Guid) && val.Value is string)
            {
                string s = (string)val.Value;
                if (Guid.TryParse(s, out Guid uid))
                {
                    result = (T)(object)uid;
                    return(true);
                }
            }
            else if (val.HostValue is T)
            {
                result = (T)val.HostValue;
                return(true);
            }
            else if (typeof(T).IsEnum && val.HostValue is int)
            {
                result = (T)val.HostValue;
                return(true);
            }

            try
            {
                object obj = Valizer.Devalize(val, type);
                result = (T)obj;
                return(true);
            }
            catch (Exception ex)
            {
                clog.WriteLine($"cannot cast key={variable} value {val} to type {typeof(T).FullName}: {ex.Message}");
                result = default(T);
                return(true);
            }
        }
예제 #7
0
파일: HostType.cs 프로젝트: liusj666/AxNew
 /// <summary>
 /// Register valizer and devalizer
 /// </summary>
 /// <param name="type"></param>
 /// <param name="valizer"></param>
 /// <param name="devalizer"></param>
 /// <returns></returns>
 public static VAL Register(Type type, Valizer valizer, Devalizer devalizer)
 {
     return(ValizerScript.Register(type, valizer, devalizer));
 }
예제 #8
0
        public static string WriteObject <T>(this T graph)
        {
            var val = Valizer.Valize(graph);

            return(val.ToJson());
        }