Esempio n. 1
0
        /// <summary>
        /// 映射为实体对象:实体尝试。
        /// </summary>
        /// <param name="type">类型,为空则尝试失败。</param>
        /// <param name="result">输出结果。</param>
        /// <returns>返回是否尝试成功。</returns>
        protected virtual bool ToObject_Try_Entity(System.Type type, out object result)
        {
            result = FastWrapper.CreateInstance(type);
            //没有字段?
            if (FieldCount == 0)
            {
                return(true);
            }

            for (int i = 0; i < FieldCount; i++)
            {
                string name = GetName(i);

                var propertyInfo = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
                if (propertyInfo != null)
                {
                    object value = GetValue(i, propertyInfo.PropertyType);
                    propertyInfo.SetValue(result, value, null);
                    continue;
                }

                var fieldInfo = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
                if (fieldInfo != null)
                {
                    object value = GetValue(i, fieldInfo.FieldType);
                    fieldInfo.SetValue(result, value);
                    continue;
                }
            }
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取类型
        /// </summary>
        /// <param name="name">类型名称</param>
        /// <returns></returns>
        public static FastWrapper GetType(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }
            FastWrapper wrapper;

            if (_types.TryGetValue(name, out wrapper))
            {
                return(wrapper);
            }
            if (_types.TryGetValue(name, out wrapper))
            {
                return(wrapper);
            }
            try {
                System.Type type = _assemblies[0].GetType(name);
                if (type == null)
                {
                    return(null);
                }
                wrapper = new FastWrapper(type, false);
                _types.Add(name, wrapper);
                return(wrapper);
            } catch {
                return(null);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 创建DbCommand参数。
        /// </summary>
        /// <param name="dbCommand">DbCommand对象。</param>
        /// <param name="commandParameter">命令参数对象。</param>
        /// <returns>返回ADO.NET命令参数对象。</returns>
        protected virtual System.Data.IDbDataParameter CreateDbCommandParameter(System.Data.IDbCommand dbCommand, CommandParameter commandParameter)
        {
            var result = dbCommand.CreateParameter();

            if (commandParameter.IsReturn)
            {
                result.Direction = ParameterDirection.ReturnValue;
            }
            else
            {
                result.ParameterName = commandParameter.Name;
                if (commandParameter.IsOut)
                {
                    result.Direction = ParameterDirection.Output;
                }
                if (commandParameter.Value == null)
                {
                    result.Value = System.DBNull.Value;
                    goto lb_Properties;
                }
                if (commandParameter.RealType.IsArray && commandParameter.RealType.GetElementType() == typeof(byte))
                {
                    result.DbType = DbType.Binary;
                    result.Value  = commandParameter.Value;
                    goto lb_Properties;
                }
                result.Value = commandParameter.Value;
            }
lb_Properties:
            foreach (System.Collections.Generic.KeyValuePair <string, object> p in commandParameter.Properties)
            {
                FastWrapper.Set(result, p.Key, p.Value);
            }
            return(result);
        }
Esempio n. 4
0
 /// <summary>
 /// 设置构造器的参数。
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="name">参数名称。</param>
 /// <param name="value">参数值,为null时,自动跳过。</param>
 /// <param name="filter">过滤器。</param>
 /// <returns>返回是否操作成功。</returns>
 protected bool SetBuilderValue(System.Data.Common.DbConnectionStringBuilder builder, string name, object value, ValueFilter filter = null)
 {
     if (value == null)
     {
         return(false);
     }
     try {
         if (filter != null)
         {
             value = filter(value);
             if (value == null)
             {
                 return(false);
             }
         }
         if (value is string)
         {
             if (string.IsNullOrEmpty((string)value))
             {
                 return(false);
             }
         }
         if (name.IndexOf(' ') > -1)
         {
             builder[name] = value;
         }
         else
         {
             FastWrapper.Set(builder, name, value, System.Reflection.BindingFlags.IgnoreCase);
         }
         return(true);
     } catch (System.Exception) {
         return(false);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// 绑定数据。
        /// </summary>
        /// <param name="dataContext">数据上下文对象。</param>
        /// <param name="dataReader">数据读取对象。</param>
        /// <param name="entity">当前实体对象。</param>
        /// <param name="field">当前字段。</param>
        /// <param name="type">实体中字段的类型。</param>
        /// <param name="cache">缓存。</param>
        /// <returns>返回绑定的数据。</returns>
        public override object Bind(IDataContext dataContext, System.Data.IDataReader dataReader, object entity, string field, Type type, IDataBinderObjectCache cache)
        {
            var  elementType   = type.IsArray ? type.GetElementType() : type.GetGenericArguments()[0];
            bool isSingleValue = (elementType == typeof(string) || elementType.IsValueType || TypeExtensions.IsNullableType(elementType));

            if (isSingleValue && (string.IsNullOrEmpty(Field) || Field == "*"))
            {
                Field = "id";
            }

            using (var builder = dataContext.CreateSelect(SourceName)) {
                PreSelectBuilder(dataContext, dataReader, entity, builder, cache);
                if (isSingleValue)
                {
                    builder.Select(Field);
                }
                builder.Query(Condition).Sort(Sorter);
                return(CacheFunc(cache, builder, "list", type, () => {
                    var q = dataContext.CreateQuery(elementType, builder.CommandText, builder.Parameters);
                    q.DataBinderObjectCache = cache;
                    var list = (System.Collections.IList)FastWrapper.CreateInstance(type);
                    foreach (var item in q)
                    {
                        list.Add(item);
                    }
                    if (type.IsArray)
                    {
                        var array = Array.CreateInstance(elementType, list.Count);
                        list.CopyTo(array, 0);
                        return array;
                    }
                    return list;
                }));
            }
        }
Esempio n. 6
0
        /// <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);
        }
Esempio n. 7
0
        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());
        }
Esempio n. 8
0
        /// <summary>
        /// 注册类型。
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public DatabaseSchemaHandler RegisterType(System.Type type)
        {
            if (type == null || !type.IsClass || type.IsAbstract ||
                !TypeExtensions.IsInheritFrom(type, typeof(DatabaseSchemaHandler)))
            {
                return(null);
            }
            DatabaseSchemaHandler handler = null;
            string key = type.FullName;

            if (_caches.TryGetValue(key, out handler))
            {
                return(handler);
            }
            string fullName = TypeExtensions.FullName2(type);

            try {
                _log.Info("创建实例:{0}", fullName);
                handler = (DatabaseSchemaHandler)FastWrapper.CreateInstance(type);
                _caches.Add(key, handler);
                _list.Add(handler);
                ClassOrder(handler.Attribute.TableName, handler.Attribute.Order);
                CacheRef(type.Assembly, handler);
                return(handler);
            } catch (System.Exception error) {
                _log.Warning("创建实例失败:{0}\r\n{1}", fullName, LogBase.ExceptionToString(error));
                return(null);
            }
        }
Esempio n. 9
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            //Symbol.Forms.SelectedItem<Funds> fundsItem = (Symbol.Forms.SelectedItem<Funds>)cbFundsId.SelectedItem;
            Symbol.Forms.SelectedItem <ConsumeType> consumeTypeItem = (Symbol.Forms.SelectedItem <ConsumeType>)cbConsumeTypeId.SelectedItem;
            if (!UIValidtion.Create()
                .Next(cbConsumeTypeId, p => p.SelectedIndex != -1, p => consumeTypeItem == null ? "" : consumeTypeItem.Text, "消费方式", true)
                .Next(dtByDate, p => p.Value.HasValue, p => p.Value == null ? "" : p.Value.Value.ToString(p.Format), "日期")
                .Null(txtMoney, "金额")
                .NumDec(0)
                .Null(txtRelatedPerson, "相关人")
                .Len(1, 10)
                .Result)
            {
                return;
            }

            _model = new FundsLog()
            {
                UserId    = Program.CurrentUser.Id,
                ByDate    = dtByDate.Value.Value,
                ByDateDay = dtByDate.DayNumber,
                //FundsId = fundsItem.Value.Id,
                ConsumeTypeId = consumeTypeItem.Value.Id,
                Money         = Math.Abs(TypeExtensions.Convert <decimal>(txtMoney.Text, 0M)),
                //LastMoney= fundsItem.Value.Money,
                RelatedPerson = txtRelatedPerson.Text,
                Comment       = txtComment.Text,
                IsOut         = consumeTypeItem.Value.IsOut,
            };
            Program.DataStore.Add(_model);
            //Symbol.FastWrapper.Set(_model, "FundsName", fundsItem.Value.Name);
            FastWrapper.Set(_model, "ConsumeTypeName", consumeTypeItem.Value.Name);

            DialogResult = System.Windows.Forms.DialogResult.OK;
        }
Esempio n. 10
0
    /// <summary>
    /// 调用类型的 实例 方法。
    /// </summary>
    /// <param name="type">当前类型。</param>
    /// <param name="name">方法名称。</param>
    /// <param name="instance">当前实例。</param>
    /// <param name="args">参数列表。</param>
    /// <returns>返回方法调用的结果。</returns>
    public static object MethodInvoke(
#if !net20
        this
#endif
        object instance, string name, System.Type type, params object[] args)
    {
        return(FastWrapper.MethodInvoke(type, name, instance, args));
    }
Esempio n. 11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="o"></param>
 public CollationSequence(object o)
 {
     SQLiteHelper.LoadAssembly(o.GetType().Assembly);
     _wraaper = new FastWrapper(SQLiteHelper.GetType("System.Data.SQLite.CollationSequence").Type, false)
     {
         Instance = o
     };
 }
Esempio n. 12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="o"></param>
 /// <param name="ex"></param>
 public void Init(object o, bool ex)
 {
     SQLiteHelper.LoadAssembly(o.GetType().Assembly);
     _fun = new FastWrapper(SQLiteHelper.GetType(ex ? "System.Data.SQLite.SQLiteFunctionEx" : "System.Data.SQLite.SQLiteFunction").Type, false)
     {
         Instance = o
     };
 }
Esempio n. 13
0
        /// <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);
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        static void DatabaseCRUD(IDataContext db)
        {
            //常规测试
            {
                //删除数据
                db.BeginTransaction();
                Console.WriteLine("delete count={0}", db.Delete("test", new {
                    name = "xxxxxxxxx",         //name为xxxxxxxxx
                    id   = "{ '$gt': 200000 }"  //id大于200000,C#语法不支持JSON,但我们支持嵌套JSON语句 :)
                }));
                db.CommitTransaction();

                //插入数据
                db.BeginTransaction();
                var id = db.Insert("test", new {
                    name  = "xxxxxxxxx",
                    count = 9999,
                    data  = new {//JSON类型测试
                        url      = "https://www.baidu.com/",
                        guid     = System.Guid.NewGuid(),
                        datetime = DateTime.Now,
                        values   = FastWrapper.As(new {//嵌套复杂对象测试
                            nickName = "昵尔",
                            account  = "test"
                        })
                    }
                });
                Console.WriteLine($"insert id={id}");
                db.CommitTransaction();

                //查询数据
                Console.WriteLine("select");
                Console.WriteLine(JSON.ToNiceJSON(db.Find("test", new { name = "xxxxxxxxx" })));
                //更新数据
                db.BeginTransaction();
                var updated = db.Update("test", new { name = "fsafhakjshfksjhf", count = 88 }, new { id }) == 1;
                Console.WriteLine($"update {updated}");
                db.CommitTransaction();

                //验证是否真的修改到
                Console.WriteLine("select new value");
                Console.WriteLine(JSON.ToNiceJSON(db.Find("test", new { id })));
            }
            Console.ReadKey();
            {
                //枚举测试
                var id = db.Insert("t_user", new {
                    account  = "admin",
                    type     = UserTypes.Manager,
                    password = "******"
                });
                Console.WriteLine(JSON.ToNiceJSON(db.Find("t_user", new { id })));
            }
            Console.ReadKey();
        }
Esempio n. 16
0
        bool TryGetValue_Any(int p1, IParameterInfo p2, object p3, out object value)
        {
            var p10 = p3.GetType();

            if (p2.Type == p10 || TypeExtensions.IsInheritFrom(p2.Type, p10))
            {
                value = p3;
                return(true);
            }
            return(FastWrapper.TryGet(p10, p2.Name, p3, new object[0], out value));
        }
Esempio n. 17
0
    /// <summary>
    /// 设置对象的成员值(属性或字段)。
    /// </summary>
    /// <param name="instance">对象实例。</param>
    /// <param name="name">成员名称。</param>
    /// <param name="value">成员的值。</param>
    /// <param name="indexs">索引序列(普通属性和字段不传)。</param>
    public static void Set(
#if !net20
        this
#endif
        object instance, string name, object value, object[] indexs = null)
    {
        if (indexs == null)
        {
            FastWrapper.Set(instance, name, value, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.SetProperty | System.Reflection.BindingFlags.SetField);
        }
        FastWrapper.Set(instance, name, value, indexs, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.SetProperty | System.Reflection.BindingFlags.SetField);
    }
Esempio n. 18
0
    /// <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));
    }
Esempio n. 19
0
        /// <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);
        }
Esempio n. 20
0
        /// <summary>
        /// 创建数据库连接。
        /// </summary>
        /// <param name="connectionOptions">连接参数。</param>
        /// <returns>返回数据库连接。</returns>
        public override IConnection CreateConnection(object connectionOptions)
        {
            {
                if (connectionOptions is string connectionString)
                {
                    connectionString = connectionString.Trim();
                    if (connectionString.StartsWith("{"))
                    {
                        connectionOptions = JSON.Parse(connectionString);
                        goto lb_Object;
                    }
                    return(CreateConnection(connectionString));
                }
                if (connectionOptions is ConnectionOptions connectionOptions2)
                {
                    connectionOptions = connectionOptions2.ToObject();
                    goto lb_Object;
                }
            }
lb_Object:
            System.Data.Common.DbConnectionStringBuilder builder = FastWrapper.CreateInstance <System.Data.Common.DbConnectionStringBuilder>(GetType("MySql.Data.MySqlClient.MySqlConnectionStringBuilder", true));
            builder["pooling"] = true;
            //builder["MaxPoolSize"] = 1024;
            //builder["Port"] = 5432;
            builder["Charset"] = "utf8";
            Collections.Generic.NameValueCollection <object> values = new Collections.Generic.NameValueCollection <object>(connectionOptions);
            SetBuilderValue(builder, "SslMode", "None");
            SetBuilderValue(builder, values, "port", "Port");
            SetBuilderValue(builder, values, "host", "Data Source", p => {
                string p10 = p as string;
                if (string.IsNullOrEmpty(p10))
                {
                    return(p);
                }
                if (p10.IndexOf(':') > -1)
                {
                    string[] pair = p10.Split(':');
                    SetBuilderValue(builder, "Port", pair[1]);
                    return(pair[0]);
                }
                return(p);
            });
            SetBuilderValue(builder, values, "name", "Database");
            SetBuilderValue(builder, values, "account", "User ID");
            SetBuilderValue(builder, values, "password", "Password");
            foreach (System.Collections.Generic.KeyValuePair <string, object> item in values)
            {
                //builder[item.Key] = item.Value;
                SetBuilderValue(builder, item.Key, item.Value);
            }
            return(CreateConnection(builder.ConnectionString));
        }
Esempio n. 21
0
        /// <summary>
        /// 创建参数,仅创建对象,不会追加到参数列表。
        /// </summary>
        /// <param name="name">参数名称,必须以@开头。</param>
        /// <param name="value">参数的值。</param>
        /// <param name="properties">属性列表。</param>
        /// <returns>返回参数实例。</returns>
        public virtual CommandParameter Create(string name, object value, object properties)
        {
            var dialect             = Provider?.Dialect;
            CommandParameter result = value as CommandParameter;

            if (result != null)
            {
                if (string.IsNullOrEmpty(result.Name))
                {
                    result.Name = NextName();
                }
                else
                {
                    result.Name = dialect?.ParameterNameGrammar(result.Name);
                }
                if (!result.Created)
                {
                    OnCreate(result);
                    result.Created = true;
                }
                return(result);
            }
            result = new CommandParameter()
            {
                Value    = value,
                RealType = value == null ? typeof(object) : value.GetType(),
            };
            if (string.IsNullOrEmpty(name))
            {
                result.Name = NextName();
            }
            else
            {
                if (name.StartsWith("out_", System.StringComparison.OrdinalIgnoreCase))
                {
                    result.Name  = dialect?.ParameterNameGrammar(name.Substring(4));
                    result.IsOut = true;
                }
                else
                {
                    result.Name = dialect?.ParameterNameGrammar(name);
                }
            }
            if (properties != null)
            {
                result.Properties = FastWrapper.As(properties);
            }
            OnCreate(result);
            result.Created = true;
            return(result);
        }
Esempio n. 22
0
        /// <summary>
        /// 创建 System.Data.SQLite.SQLiteConnectionStringBuilder
        /// </summary>
        /// <returns></returns>
        public static System.Data.Common.DbConnectionStringBuilder CreateConnectionStringBuilder()
        {
            FastWrapper wrapper = GetType("System.Data.SQLite.SQLiteConnectionStringBuilder");

            if (wrapper == null)
            {
                return(null);
            }
            System.Data.Common.DbConnectionStringBuilder builder = FastWrapper.CreateInstance(wrapper.Type) as System.Data.Common.DbConnectionStringBuilder;
            FastWrapper.Set(builder, "Pooling", true);
            FastWrapper.Set(builder, "FailIfMissing", false);
            builder["journal mode"] = "Off";
            return(builder);
        }
Esempio n. 23
0
 bool TryProperty(PathNode node, string name)
 {
     try {
         System.Reflection.PropertyInfo propertyInfo = FastWrapper.GetProperty(node.model.GetType(), name);
         if (propertyInfo == null)
         {
             return(false);
         }
         node.value = propertyInfo.GetValue(node.model, new object[0]);// TypeExtensions.Get(node.model, property);
         return(true);
     } catch {
         node.value = null;
         return(false);
     }
 }
Esempio n. 24
0
        /// <summary>
        /// 将绑定后的参数以抽象对象方式输出
        /// </summary>
        /// <returns></returns>
        public Symbol.Collections.Generic.NameValueCollection <object> ToObject()
        {
            var list = FastWrapper.As(null);

            if (_paramters == null || _paramters.Count == 0)
            {
                return(list);
            }
            Init();
            for (int i = 0; i < _paramters.Count; i++)
            {
                list[_paramters[i].Name] = TryGetValue(i, _paramters[i]);
            }
            return(list);
        }
Esempio n. 25
0
 bool TryField(PathNode node, string name)
 {
     try {
         System.Reflection.FieldInfo fieldInfo = FastWrapper.GetField(node.model.GetType(), name);
         if (fieldInfo == null)
         {
             return(false);
         }
         node.value = fieldInfo.GetValue(node.model);// TypeExtensions.Get(node.model, property);
         return(true);
     } catch {
         node.value = null;
         return(false);
     }
 }
Esempio n. 26
0
        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);
        }
Esempio n. 27
0
 /// <summary>
 /// 创建 System.Data.SQLite.SQLiteConnectionStringBuilder
 /// </summary>
 /// <param name="file">文件</param>
 /// <param name="password">密码</param>
 /// <returns></returns>
 public static System.Data.Common.DbConnectionStringBuilder CreateConnectionStringBuilder(string file, string password)
 {
     System.Data.Common.DbConnectionStringBuilder builder = CreateConnectionStringBuilder();
     if (!string.IsNullOrEmpty(file))
     {
         CreateFile(file);
         FastWrapper.Set(builder, "DataSource", file);
     }
     FastWrapper.Set(builder, "Pooling", true);
     FastWrapper.Set(builder, "FailIfMissing", false);
     builder["journal mode"] = "Off";
     if (!string.IsNullOrEmpty(password))
     {
         FastWrapper.Set(builder, "Password", password);
     }
     return(builder);
 }
Esempio n. 28
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="assembly">程序集实例。</param>
        public static void Register(System.Reflection.Assembly assembly)
        {
            if (assembly == null)
            {
                return;
            }
            var attributes = AttributeExtensions.GetCustomAttributes <ProviderAttribute>(assembly, true);

            foreach (var item in attributes)
            {
                if (string.IsNullOrEmpty(item.Name) || item.Type == null)
                {
                    continue;
                }
                _list_cache.TryAdd(item.Name, FastWrapper.CreateInstance <IProvider>(item.Type, new object[0]));
            }
        }
Esempio n. 29
0
 /// <summary>
 /// 加载。
 /// </summary>
 /// <param name="list">用于存储的列表。</param>
 /// <param name="attributeProvider">特性提供者。</param>
 public static void Load(ParameterInfoList list, System.Reflection.ICustomAttributeProvider attributeProvider)
 {
     if (list == null || attributeProvider == null)
     {
         return;
     }
     foreach (var attribute in AttributeExtensions.GetCustomAttributes <CloudArgsAttribute>(attributeProvider, true))
     {
         if (attribute.Type == null)
         {
             continue;
         }
         list.AddRange(PropertyParameterInfo.As(
                           FastWrapper.GetProperties(attribute.Type, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, true, true)
                           )
                       );
     }
 }
Esempio n. 30
0
 /// <summary>
 /// 获取 PostgreSQL.Data 类型
 /// </summary>
 /// <param name="typeFullName">类型全名。</param>
 /// <param name="throw">是否报错</param>
 /// <returns></returns>
 public static System.Type GetType(string typeFullName, bool @throw = false)
 {
     if (string.IsNullOrEmpty(typeFullName))
     {
         return(null);
     }
     System.Type type = _types[typeFullName];
     if (type == null)
     {
         string typeName = typeFullName + ", Npgsql";
         type = FastWrapper.GetWarpperType(typeName, "Npgsql.dll");
         if (type == null && @throw)
         {
             CommonException.ThrowTypeLoad(typeName);
         }
         _types[typeFullName] = type;
     }
     return(type);
 }