コード例 #1
0
        private dynamic GetRefObjectClss(Type t, IReadContext r)
        {
            var     pis = t.GetProperties();
            dynamic nm  = t.Assembly.CreateInstance(t.FullName);

            for (int i = 0; i < pis.Length; i++)
            {
                var    pi      = pis[i];
                string colName = pi.Name;
                switch (pi.PropertyType.FullName)
                {
                case "System.String":
                    pi.SetValue(nm, Read(r, colName), null);
                    break;

                case "System.Int16":
                    pi.SetValue(nm, Convert.ToInt16(Read(r, colName)), null);
                    break;

                case "System.Int32":
                    pi.SetValue(nm, Conv.ToInt(Read(r, colName)), null);
                    break;

                case "System.Int64":
                    pi.SetValue(nm, Convert.ToInt64(Read(r, colName)), null);
                    break;

                case "System.Decimal":
                    pi.SetValue(nm, Conv.ToDecimal(Read(r, colName)), null);
                    break;

                case "System.Double":
                    pi.SetValue(nm, Convert.ToDouble(Read(r, colName)), null);
                    break;

                case "System.Float":
                    pi.SetValue(nm, Convert.ToSingle(Read(r, colName)), null);
                    break;

                //case "System.Guid":
                //    if (row[colName] != DBNull.Value) pi.SetValue(r, (Guid)row[colName], null);
                //    break;
                case "System.DateTime":
                    pi.SetValue(nm, Conv.ToDateTime(Read(r, colName)), null);
                    break;

                case "System.Char":
                    pi.SetValue(nm, Conv.ToChar(Read(r, colName)), null);
                    break;
                    //case "System.Boolean":
                    //    if (row[colName] != DBNull.Value) pi.SetValue(r, (bool)row[colName], null);
                    //    break;
                    //case "System.Byte":
                    //    if (row[colName] != DBNull.Value) pi.SetValue(r, (byte)row[colName], null);
                    //    break;
                }
            }

            return(nm);
        }
コード例 #2
0
        public T GetObject <T>(string key)
        {
            var t   = typeof(T);
            var pis = t.GetProperties();
            T   nm  = (T)Activator.CreateInstance(t);

            for (int i = 0; i < pis.Length; i++)
            {
                var    pi      = pis[i];
                string colName = pi.Name;

                switch (pi.PropertyType.FullName)
                {
                case "System.String":
                    pi.SetValue(nm, Read(key, colName), null);
                    break;

                case "System.Int16":
                    pi.SetValue(nm, Convert.ToInt16(Read(key, colName)), null);
                    break;

                case "System.Int32":
                    pi.SetValue(nm, Conv.ToInt(Read(key, colName)), null);
                    break;

                case "System.Int64":
                    pi.SetValue(nm, Convert.ToInt64(Read(key, colName)), null);
                    break;

                case "System.Decimal":
                    pi.SetValue(nm, Conv.ToDecimal(Read(key, colName)), null);
                    break;

                case "System.Double":
                    pi.SetValue(nm, Convert.ToDouble(Read(key, colName)), null);
                    break;

                case "System.Float":
                    pi.SetValue(nm, Convert.ToSingle(Read(key, colName)), null);
                    break;

                //case "System.Guid":
                //    if (row[colName] != DBNull.Value) pi.SetValue(r, (Guid)row[colName], null);
                //    break;
                case "System.DateTime":
                    pi.SetValue(nm, Conv.ToDateTime(Read(key, colName)), null);
                    break;

                case "System.Char":
                    pi.SetValue(nm, Conv.ToChar(Read(key, colName)), null);
                    break;
                    //case "System.Boolean":
                    //    if (row[colName] != DBNull.Value) pi.SetValue(r, (bool)row[colName], null);
                    //    break;
                    //case "System.Byte":
                    //    if (row[colName] != DBNull.Value) pi.SetValue(r, (byte)row[colName], null);
                    //    break;
                }
            }

            return(nm);
        }