コード例 #1
0
ファイル: SqlHelper.cs プロジェクト: lisandropodesta/lit.net
        /// <summary>
        /// Creates a table.
        /// </summary>
        public static DataTable CreateTable(IDbBindingCache bindingCache, object data)
        {
            if (data != null)
            {
                var type = data.GetType();
                switch (TypeHelper.GetBindingMode(ref type, out _))
                {
                case BindingMode.Class:
                {
                    var bindingList = bindingCache.GetParametersBinding(type);
                    var table       = CreateTable(bindingList);
                    AddRecord(table, bindingList, data);
                    return(table);
                }

                case BindingMode.ClassList:
                {
                    var bindingList = bindingCache.GetParametersBinding(type);
                    var table       = CreateTable(bindingList);
                    var mi          = typeof(SqlHelper).GetMethod(nameof(AddRecords), BindingFlags.Static | BindingFlags.NonPublic);
                    mi.MakeGenericMethod(type).Invoke(null, new[] { table, bindingList, data });
                    return(table);
                }
                }
            }

            throw new NotImplementedException();
        }
コード例 #2
0
        public override object FromDb(IDbBindingCache bindingCache, DbDataType dataType, Type type, object value)
        {
            switch (dataType)
            {
            case DbDataType.Unknown:
            case DbDataType.Boolean:
            case DbDataType.Char:
            case DbDataType.UInt8:
            case DbDataType.SInt8:
            case DbDataType.UInt16:
            case DbDataType.SInt16:
            case DbDataType.UInt24:
            case DbDataType.SInt24:
            case DbDataType.UInt32:
            case DbDataType.SInt32:
            case DbDataType.UInt64:
            case DbDataType.SInt64:
            case DbDataType.Decimal:
            case DbDataType.Float:
            case DbDataType.Double:
            case DbDataType.Time:
            case DbDataType.Date:
            case DbDataType.DateTime:
            case DbDataType.Timestamp:
            case DbDataType.TimeSpan:
            case DbDataType.Text:
            case DbDataType.Blob:
            case DbDataType.Enumerated:
                return(ScalarFromDb(type, value));

            case DbDataType.Json:
                break;

            case DbDataType.Records:
            default:
                throw new NotImplementedException();
            }

            return(value);
        }
コード例 #3
0
 public override object ToDb(IDbBindingCache bindingCache, DbDataType dataType, Type type, object value)
 {
     return(MySqlDataType.TranslateToDb(dataType, type, value));
 }
コード例 #4
0
 /// <summary>
 /// Decodes a DB value into a C# value.
 /// </summary>
 public abstract object FromDb(IDbBindingCache bindingCache, DbDataType dataType, Type type, object value);