private static void SetValue(object host, Type type, string offset, VAL val) { object temp = ValizerScript.ToHost(val, type); if (temp == null) { temp = val.HostValue; } HostOperation.HostTypeAssign(host, offset, temp, true); }
public static object ToHost(VAL val, Type hostType) { ValizerScript engine = ValizerScript.Engine(hostType); if (engine != null) { return(engine.Devalize(val)); } return(null); }
public static VAL ToValor(object host) { if (host == null) { return(null); } ValizerScript engine = ValizerScript.Engine(host.GetType()); if (engine != null) { return(engine.Valize(host)); } return(null); }
/// <summary> /// Register Valizer by object interface /// </summary> /// <param name="type"></param> /// <param name="valizer"></param> /// <returns></returns> public static VAL Register(Type type, IValizer valizer) { return(ValizerScript.Register(type, valizer, null)); }
/// <summary> /// Register valizer script /// </summary> /// <param name="type"></param> /// <param name="valizerScript"></param> /// <returns></returns> public static VAL Register(Type type, string valizerScript) { return(ValizerScript.Register(type, valizerScript, null)); }
/// <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)); }
/// <summary> /// Register valizer by class's members /// </summary> /// <param name="type"></param> /// <param name="valizerMembers"></param> /// <returns></returns> public static VAL Register(Type type, string[] valizerMembers) { return(ValizerScript.Register(type, valizerMembers, null)); }
private static VAL Host2Valor(object host, VAL val) { if (host == null || host is System.DBNull) { val = new VAL(); } else if (host is string || host is char || host is byte || host is int || host is short || host is long || host is bool || host is double || host is float || host is decimal || host is DateTime) { val = VAL.Boxing1(host); } else if (host is IValizable) { val = ((IValizable)host).GetValData(); } else if (host is Type) { val = VAL.Script(string.Format("typeof({0})", ((Type)host).FullName)); } else if (host.GetType().IsEnum) { val = VAL.Script(HostOperation.EnumBitFlags(host)); } else if (host is ICollection) { val = VAL.Array(); foreach (object a in (ICollection)host) { val.Add(Host2Valor(a, new VAL())); } } else { VAL temp = ValizerScript.ToValor(host); if ((object)temp != null) { return(temp); } FieldInfo[] fields = host.GetType().GetFields(); foreach (FieldInfo fieldInfo in fields) { Attribute[] A = (Attribute[])fieldInfo.GetCustomAttributes(typeof(NonValizedAttribute), true); if (A.Length != 0) { continue; } object fieldValue = fieldInfo.GetValue(host); VAL persistent = ValizerScript.ToValor(fieldInfo, fieldValue); if ((object)persistent == null) { persistent = VAL.Boxing(fieldValue); if (!fieldInfo.FieldType.IsValueType && persistent.IsHostType) { persistent = Host2Valor(fieldValue, new VAL()); } } val[fieldInfo.Name] = persistent; } PropertyInfo[] properties = host.GetType().GetProperties(); foreach (PropertyInfo propertyInfo in properties) { ValizableAttribute[] attributes = (ValizableAttribute[])propertyInfo.GetCustomAttributes(typeof(ValizableAttribute), true); if (attributes.Length == 0 || !propertyInfo.CanRead) { continue; } object propertyValue = propertyInfo.GetValue(host, null); if (propertyValue == null) { continue; } VAL persistent = ValizerScript.ToValor(propertyInfo, propertyValue); if ((object)persistent == null) { if (propertyValue is ICollection) { ICollection collection = (ICollection)propertyValue; persistent = VAL.Array(); foreach (object obj in collection) { persistent.Add(VAL.Boxing(obj)); } } else { persistent = VAL.Boxing(propertyValue); if (!propertyInfo.PropertyType.IsValueType && persistent.IsHostType) { persistent = Host2Valor(propertyValue, new VAL()); } } } val[propertyInfo.Name] = persistent; } } val.Class = host.GetType().FullName; return(val); }