byte[] PackageValueDictionary(KeyEntry keyEntry, Entry entry, Type type) { bool isGeneric = IsTheTypes(type, typeof(System.Collections.Generic.IDictionary <,>)); TreePackage package = new TreePackage(); package.Attributes.Add("IsGeneric", isGeneric); if (isGeneric) { Type[] types = GetTheTypes(type, typeof(System.Collections.Generic.IDictionary <,>)).GetGenericArguments(); package.Attributes.Add("T1", types[0].AssemblyQualifiedName); package.Attributes.Add("T2", types[1].AssemblyQualifiedName); Type typeX = GetTheTypes(type, typeof(System.Collections.Generic.Dictionary <,>)); if (typeX != null && typeX.GetGenericArguments()[0] == typeof(string)) { package.Attributes.Add("KeyIsString", true); System.Collections.Generic.IEqualityComparer <string> comparer = (System.Collections.Generic.IEqualityComparer <string>)FastWrapper.Get(entry.Value, "Comparer"); package.Attributes.Add("ComparerIgnoreCase", (comparer == StringComparer.CurrentCultureIgnoreCase || comparer == StringComparer.InvariantCultureIgnoreCase || comparer == StringComparer.OrdinalIgnoreCase)); } } int index = -1; foreach (object item in (System.Collections.IEnumerable)entry.Value) { index++; package.Add(index.ToString(), FastWrapper.Get(item, "Value")); Entry itemEntry = package.Entries[index.ToString()]; itemEntry.Attributes.Add("Key", FastWrapper.Get(item, "Key")); } return(package.Save()); }
/// <summary> /// 创建 System.Data.SQLite.SQLiteConnectionStringBuilder /// </summary> /// <param name="connectionString">连接字符串</param> /// <returns></returns> public static System.Data.Common.DbConnectionStringBuilder CreateConnectionStringBuilder(string connectionString) { FastWrapper wrapper = GetType("System.Data.SQLite.SQLiteConnectionStringBuilder"); if (wrapper == null) { return(null); } System.Data.Common.DbConnectionStringBuilder builder; if (string.IsNullOrEmpty(connectionString)) { builder = FastWrapper.CreateInstance(wrapper.Type) as System.Data.Common.DbConnectionStringBuilder; } else { builder = FastWrapper.CreateInstance(wrapper.Type, connectionString) as System.Data.Common.DbConnectionStringBuilder; string file = (string)FastWrapper.Get(builder, "DataSource"); if (!string.IsNullOrEmpty(file) && !file.Equals(":memory:", StringComparison.OrdinalIgnoreCase)) { CreateFile(file); } } FastWrapper.Set(builder, "Pooling", true); FastWrapper.Set(builder, "FailIfMissing", false); builder["journal mode"] = "Off"; return(builder); }
/// <summary> /// 预处理:字段值-字典 /// </summary> /// <param name="builder">构造缓存。</param> /// <param name="name">字段名称。</param> /// <param name="nodeValue">值包装</param> /// <param name="i">顺序。</param> /// <param name="pIndex">参数顺序。</param> /// <returns>返回是否过滤。</returns> protected virtual bool PreFieldValue_Dictionary(System.Text.StringBuilder builder, string name, NoSQL.NodeValue nodeValue, ref int i, ref int pIndex) { if (nodeValue.Type == NoSQL.NodeValueTypes.Null) { return(false); } foreach (object item in (System.Collections.IEnumerable)nodeValue.Value) { string key = FastWrapper.Get(item, "Key") as string; if (string.IsNullOrEmpty(key)) { continue; } NoSQL.NodeValue value = new NoSQL.NodeValue(FastWrapper.Get(item, "Value")); if ( string.Equals(key, "$add", System.StringComparison.OrdinalIgnoreCase) || string.Equals(key, "$+", System.StringComparison.OrdinalIgnoreCase)) { i++; if (i > 1) { builder.AppendLine(","); } builder.AppendFormat(" {0}={0}+@p{1}", PreName(name), ++pIndex); _fields[name] = value.Value; return(true); } else if ( string.Equals(key, "$minus", System.StringComparison.OrdinalIgnoreCase) || string.Equals(key, "$-", System.StringComparison.OrdinalIgnoreCase)) { i++; if (i > 1) { builder.AppendLine(","); } builder.AppendFormat(" {0}={0}-@p{1}", PreName(name), ++pIndex); _fields[name] = value.Value; return(true); } else if ( string.Equals(key, "$now", System.StringComparison.OrdinalIgnoreCase)) { i++; if (i > 1) { builder.AppendLine(","); } builder.Append(" ").Append(PreName(name)).Append('=').Append(DateTimeNowGrammar()); _fields.Remove(name); return(true); } } return(false); }
NodeValueTypes GetNodeType() { if (_value == null) { _valueType = typeof(object); return(NodeValueTypes.Null); } _valueType = _value.GetType(); NodeValueTypes nodeType; if (_types.TryGetValue(_valueType, out nodeType)) { _isValue = true; return(nodeType); } if (_valueType.IsValueType) { _isValue = true; return(NodeValueTypes.Number); } if (_valueType.IsArray) { _length = ((System.Array)_value).Length; return(NodeValueTypes.Array); } if (TypeExtensions.IsAnonymousType(_valueType)) { return(NodeValueTypes.Object); } if (TypeExtensions.IsInheritFrom(_valueType, typeof(System.Collections.IDictionary)) || TypeExtensions.IsInheritFrom(_valueType, typeof(System.Collections.Generic.IDictionary <string, object>))) { return(NodeValueTypes.Dictionary); } if (TypeExtensions.IsInheritFrom(_valueType, typeof(System.Collections.IList)) || TypeExtensions.IsInheritFrom(_valueType, typeof(System.Collections.Generic.IList <object>))) { _length = TypeExtensions.Convert <int>(FastWrapper.Get(_value, "Count"), 0); return(NodeValueTypes.Array); } if (_valueType.IsGenericType) { if (_valueType.GetGenericTypeDefinition() == typeof(System.Collections.Generic.List <>)) { _length = TypeExtensions.Convert <int>(FastWrapper.Get(_value, "Count"), 0); return(NodeValueTypes.Array); } if (_valueType.GetGenericTypeDefinition() == typeof(System.Collections.Generic.Dictionary <,>)) { return(NodeValueTypes.Dictionary); } } return(NodeValueTypes.Object); }
/// <summary> /// 获取对象的成员值(属性或字段)。 /// </summary> /// <param name="instance">对象实例。</param> /// <param name="name">成员名称。</param> /// <param name="indexs">索引序列(普通属性和字段不传)。</param> /// <returns>返回成员的值。</returns> public static object Get( #if !net20 this #endif object instance, string name, object[] indexs = null) { if (indexs == null) { return(FastWrapper.Get(instance, name)); } return(FastWrapper.Get(instance, name, indexs)); }
/// <summary> /// 执行查询,并返回查询的第一条记录的第一个列。 /// </summary> /// <param name="dbCommandCache">DbCommandCache对象。</param> /// <returns>返回查询结果。</returns> protected override object ExecuteScalar(AdoCommandCache dbCommandCache) { var result = base.ExecuteScalar(dbCommandCache); var dbCommand = dbCommandCache.DbCommand; bool insert = dbCommand.CommandText.IndexOf("insert ", System.StringComparison.OrdinalIgnoreCase) > -1; if (insert) { result = FastWrapper.Get(dbCommand, "LastInsertedId"); } return(result); }
private static void SetUseUnsafeHeaderParsing() { System.Type type = FastWrapper.GetWarpperType("System.Net.Configuration.SettingsSectionInternal,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); if (type == null) { return; } object instance = FastWrapper.Get(type, "Section"); if (instance == null) { return; } FastWrapper.Set(instance, "useUnsafeHeaderParsing", true); }
Sorter Parse_Dictionary(NodeValue jsonValue) { Sorter result = new Sorter(); foreach (object item in (System.Collections.IEnumerable)jsonValue.Value) { string key = FastWrapper.Get(item, "Key") as string; if (string.IsNullOrEmpty(key)) { continue; } if (!Filter_Name(key)) { continue; } NodeValue value = new NodeValue(FastWrapper.Get(item, "Value")); result._values[key] = WrapValue(value); } return(result); }
void Next_Dictionary(Condition parent, NodeValue jsonValue) { foreach (object item in (System.Collections.IEnumerable)jsonValue.Value) { string key = FastWrapper.Get(item, "Key") as string; if (string.IsNullOrEmpty(key)) { continue; } ConditionTypes type = GetType(key); if (type == ConditionTypes.Root) { continue; } object value = FastWrapper.Get(item, "Value"); Condition pair = new Condition(key, type); if (Check_Pair(pair, value)) { parent.Children.Add(pair); } } }
void Parse_Dictionary(Refer refer, NodeValue jsonValue) { string[] pairs = new string[5]; foreach (object item in (System.Collections.IEnumerable)jsonValue.Value) { string key = FastWrapper.Get(item, "Key") as string; if (string.IsNullOrEmpty(key)) { continue; } object value = FastWrapper.Get(item, "Value"); if (string.Equals(key, "by", StringComparison.OrdinalIgnoreCase)) { Parse_Pairs(pairs, 3, new NodeValue(value)); } else { pairs[0] = key; Parse_Pairs(pairs, 1, new NodeValue(value)); } } refer.Add(Create_Pairs(pairs)); }
/// <summary> /// 检测函数是否存在 /// </summary> /// <param name="name"></param> /// <returns></returns> public static bool ExistsFunction(string name) { if (string.IsNullOrEmpty(name)) { return(false); } FastWrapper wrapper = GetType("System.Data.SQLite.SQLiteFunction"); if (wrapper == null) { return(false); } foreach (object item in (System.Collections.IEnumerable)wrapper.Get("_registeredFunctions")) { string name2 = (string)FastWrapper.Get(item, "Name"); if (name == name2) { return(true); } } return(false); }
static void UnPackageValueDictionary(KeyEntry keyEntry, Entry entry, byte[] buffer) { TreePackage package = Load(buffer); if (package == null || package.Count == 0) { entry.Value = new System.Collections.Hashtable(); return; } bool isGeneric = (bool)package.Attributes["IsGeneric"]; System.Collections.IDictionary result = null; if (isGeneric) { Type t1 = FastWrapper.GetWarpperType((string)package.Attributes["T1"]); Type t2 = FastWrapper.GetWarpperType((string)package.Attributes["T2"]); object comparer = FastWrapper.Get(typeof(System.Collections.Generic.EqualityComparer <>).MakeGenericType(t1), "Default"); if (package.Attributes.ContainsKey("KeyIsString") && (bool)package.Attributes["KeyIsString"]) { comparer = (bool)package.Attributes["ComparerIgnoreCase"] ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal; } result = (System.Collections.IDictionary)FastWrapper.CreateInstance(typeof(System.Collections.Generic.Dictionary <,>).MakeGenericType(t1, t2), package.Count, comparer); } else { result = new System.Collections.Hashtable(package.Count); } Entry entry2 = null; for (int index = 0; index < package.Count; index++) { entry2 = package.Entries[index.ToString()]; result.Add(entry2.Attributes["Key"], entry2.Value); } entry.Value = result; }
bool Parse_Pairs(string[] pairs, int offset, NodeValue jsonValue) { bool b = true; lb_Retury: if (jsonValue.Type == NodeValueTypes.Object) { foreach (System.Reflection.PropertyInfo propertyInfo in jsonValue.ValueType.GetProperties()) { string key = propertyInfo.Name; object value = propertyInfo.GetValue(jsonValue.Value, new object[0]); pairs[offset] = key; pairs[offset + 1] = value as string; goto lb_Result; } return(false); } if (jsonValue.Type == NodeValueTypes.Dictionary) { foreach (object item in (System.Collections.IEnumerable)jsonValue.Value) { string key = FastWrapper.Get(item, "Key") as string; if (string.IsNullOrEmpty(key)) { continue; } object value = FastWrapper.Get(item, "Value"); pairs[offset] = key; pairs[offset + 1] = value as string; goto lb_Result; } return(false); } if (jsonValue.Type == NodeValueTypes.Array) { int n = 0; foreach (object element in (System.Collections.IEnumerable)jsonValue.Value) { pairs[offset + n] = element as string; n++; if (n == 2) { goto lb_Result; } } return(false); } if (!b) { return(false); } if (jsonValue.Type == NodeValueTypes.String) { string text = jsonValue.Value as string; if (string.IsNullOrEmpty(text)) { return(false); } if (text[0] == '[' || text[0] == '{') { jsonValue = new NodeValue(JSON.Parse(text)); b = false; goto lb_Retury; } } lb_Result: return(!string.IsNullOrEmpty(pairs[offset]) && !string.IsNullOrEmpty(pairs[offset + 1])); }
/// <summary> /// /// </summary> /// <returns></returns> protected CollationSequence GetCollationSequence() { return(new CollationSequence(_fun.Get("GetCollationSequence"))); }