public static Func <object, object> GetWriteFunc(Type propertyFieldType) { Func <object, object> func = null; if (!m_writeFuncDic.TryGetValue(propertyFieldType, out func)) { if (propertyFieldType == typeof(Enum)) { func = (value) => string.Format(@"'{0}'", value.ToString()); } else if (propertyFieldType == typeof(Int32) || propertyFieldType == typeof(Int64)) { func = (value) => value; } else if (propertyFieldType == typeof(float)) { func = (value) => value; } else if (propertyFieldType == typeof(double)) { func = (value) => value; } else if (propertyFieldType == typeof(string)) { func = (value) => string.Format(@"'{0}'", null == value?@"":value.ToString()); } else if (propertyFieldType == typeof(bool)) { func = (value) => value.ToString(); } else { SqliteCustomSerializeFunc.CustomSerializeFunc serializeFunc = null; m_customSerializeFun.TryGetSerializaFunc(propertyFieldType, out serializeFunc); if (null == serializeFunc) { throw new USqliteException(string.Format("尚未注册此 [{0}] 类型的序列化方法", propertyFieldType)); } func = (value) => serializeFunc(value); } m_writeFuncDic.Add(propertyFieldType, func); } return(func); }
public static void RegisterCustomSerializeFunc(Type type, SqliteCustomSerializeFunc.CustomSerializeFunc serialize, SqliteCustomSerializeFunc.CustomDeserializeFunc deserialize) { RegisterSerializeFunc(type, serialize); RegisterDeserializeFunc(type, deserialize); }
public static void RegisterSerializeFunc(Type type, SqliteCustomSerializeFunc.CustomSerializeFunc serialize) { m_customSerializeFun.RegisterCustomSerializeFunc(type, serialize); }