Exemplo n.º 1
0
 /// <summary>
 /// 将src中各属性的值复制到des中
 /// </summary>
 /// <param name="src"></param>
 /// <param name="des"></param>
 public static void MembersClone(DomainObject src, DomainObject des)
 {
     foreach (MemberInfo info in DomainObjectUtility.GetMemberInfos(src))
     {
         DomainObjectUtility.SetValue(des, info.Name, DomainObjectUtility.GetValue(src, info, null));
     }
 }
Exemplo n.º 2
0
 public static Hashtable GetAttributeMemberInfos(Type type)
 {
     lock (hashtableAttributeMember)
     {
         if (hashtableAttributeMember.ContainsKey(type.FullName) == false)
         {
             hashtableAttributeMember.Add(type.FullName, DomainObjectUtility.GetAttributeMemberInfos(DomainObjectUtility.GetMemberInfos(type)));
         }
     }
     return((Hashtable)hashtableAttributeMember[type.FullName]);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 获得DomainObject中定义了FieldMapAttribute,且为主键的属性名或字段名
        /// </summary>
        /// <param name="type">DomainObject的类型</param>
        /// <returns></returns>
        public static string[] GetDomainObjectKeyScheme(Type type)
        {
            Hashtable ht     = DomainObjectUtility.GetKeyAttributeMemberInfos(type);
            ArrayList scheme = new ArrayList(ht.Count);

            foreach (MemberInfo info in ht.Values)
            {
                scheme.Add(info.Name);
            }

            return((string[])scheme.ToArray(typeof(string)));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获得DomainObject对应的所有数据库字段名
        /// </summary>
        /// <param name="type">DomainObject的类型</param>
        /// <returns></returns>
        public static ArrayList GetDomainObjectFieldsName(Type type)
        {
            Hashtable hs    = DomainObjectUtility.GetAttributeMemberInfos(type);
            ArrayList array = new ArrayList(hs.Count);

            foreach (FieldMapAttribute attr in hs.Keys)
            {
                array.Add(attr.FieldName);
            }

            return(array);
        }
Exemplo n.º 5
0
        /// <summary>
        ///  获得DomainObject中定义了FieldMapAttribute的属性名或字段名的值
        /// </summary>
        /// <param name="obj">DomainObject</param>
        /// <returns></returns>
        public static ArrayList GetDomainObjectValues(DomainObject obj)
        {
            ArrayList array  = DomainObjectUtility.GetMemberInfos(obj);
            ArrayList values = new ArrayList(array.Count);

            foreach (MemberInfo info in array)
            {
                values.Add(DomainObjectUtility.GetValue(obj, info, null));
            }

            return(values);
        }
Exemplo n.º 6
0
        /// <summary>
        ///  获得DomainObject中定义了FieldMapAttribute,且为主键的属性名或字段名的值
        /// </summary>
        /// <param name="obj">DomainObject</param>
        /// <returns></returns>
        public static object[] GetDomainObjectKeyValues(DomainObject obj)
        {
            Hashtable ht     = DomainObjectUtility.GetKeyAttributeMemberInfos(obj);
            ArrayList values = new ArrayList(ht.Count);

            foreach (MemberInfo info in ht.Values)
            {
                values.Add(DomainObjectUtility.GetValue(obj, info, null));
            }

            return((object[])values.ToArray(typeof(object)));
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获得DomainObject中定义了FieldMapAttribute的属性名或字段名
        /// </summary>
        /// <param name="type">DomainObject的类型</param>
        /// <returns></returns>
        public static ArrayList GetDomainObjectScheme(Type type)
        {
            ArrayList array  = DomainObjectUtility.GetMemberInfos(type);
            ArrayList scheme = new ArrayList(array.Count);

            foreach (MemberInfo info in array)
            {
                scheme.Add(info.Name);
            }

            return(scheme);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 获得DomainObject对应的 数据库表名.字段名,用','拼成的字符串
        /// </summary>
        /// <param name="type">DomainObject的类型</param>
        /// <returns></returns>
        public static string GetDomainObjectFieldsStringWithTableName(Type type)
        {
            string tableName = DomainObjectUtility.GetTableMapAttribute(type).TableName;

            string[] fieldNames = (string[])DomainObjectUtility.GetDomainObjectFieldsName(type).ToArray(typeof(string));

            for (int i = 0; i < fieldNames.Length; i++)
            {
                fieldNames[i] = string.Format("{0}.{1}", tableName, fieldNames[i]);
            }

            return(String.Join(", ", fieldNames));
        }
Exemplo n.º 9
0
        private static DomainObject[] FillDomainObject(Type type, DataTable table)
        {
            DomainObject[] domainObjects = new DomainObject[table.Rows.Count];
            int            num1          = 0;

            foreach (DataRow dr in table.Rows)
            {
                domainObjects[num1] = DomainObjectUtility.FillDomainObject(type.Assembly.CreateInstance(type.FullName), dr);
                num1 = num1 + 1;
            }

            return(domainObjects);
        }
Exemplo n.º 10
0
        public static DomainObject[] FillDomainObject(Type type, DataSet ds)
        {
            if (ds == null)
            {
                return(null);
            }

            if (ds.Tables[0].Rows.Count < 1)
            {
                return(null);
            }

            return(DomainObjectUtility.FillDomainObject(type, ds.Tables[0]));
        }
Exemplo n.º 11
0
        public static DomainObject FillDomainObject(object obj, DataRow dataRow)
        {
            Hashtable hs       = DomainObjectUtility.GetAttributeMemberInfos(obj);
            Hashtable hsFields = GetFieldNameMapAttribute(obj.GetType().FullName, hs);

            foreach (DataColumn column in dataRow.Table.Columns)
            {
                if (hsFields.Contains(column.ColumnName.ToUpper()))
                {
                    DomainObjectUtility.SetValue(obj, (MemberInfo)hsFields[column.ColumnName.ToUpper()], dataRow[column.ColumnName]);
                }
            }

            return((DomainObject)obj);
        }
Exemplo n.º 12
0
        public static void SetValue(object domainObject, string propertyName, object value)
        {
            ArrayList  infos = DomainObjectUtility.GetMemberInfos(domainObject);
            MemberInfo info1 = null;

            foreach (MemberInfo info in infos)
            {
                if (info.Name == propertyName)
                {
                    info1 = info;
                    break;
                }
            }

            if (info1 == null)
            {
                throw new Exception("$Error_Property_Name_Not_Exist");
            }

            DomainObjectUtility.SetValue(domainObject, info1, value);
        }
Exemplo n.º 13
0
 public static Hashtable GetNonKeyAttributeMemberInfos(Type type)
 {
     return(DomainObjectUtility.GetNonKeyAttributeMemberInfos(DomainObjectUtility.GetTableMapAttribute(type), DomainObjectUtility.GetMemberInfos(type)));
 }
Exemplo n.º 14
0
 public static Hashtable GetNonKeyAttributeMemberInfos(object obj)
 {
     return(DomainObjectUtility.GetNonKeyAttributeMemberInfos(DomainObjectUtility.GetTableMapAttribute(obj), DomainObjectUtility.GetMemberInfos(obj)));
 }
Exemplo n.º 15
0
 /// <summary>
 /// 获得DomainObject对应的所有数据库字段名,用','拼成的字符串
 /// </summary>
 /// <param name="type">DomainObject的类型</param>
 /// <returns></returns>
 public static string GetDomainObjectFieldsString(Type type)
 {
     return(String.Join(", ", (string[])DomainObjectUtility.GetDomainObjectFieldsName(type).ToArray(typeof(string))));
 }
Exemplo n.º 16
0
 public static TableMapAttribute GetTableMapAttribute(object obj)
 {
     return(DomainObjectUtility.GetTableMapAttribute(obj.GetType()));
 }
Exemplo n.º 17
0
 public static ArrayList GetMemberInfos(object obj)
 {
     return(DomainObjectUtility.GetMemberInfos(obj.GetType()));
 }
Exemplo n.º 18
0
        private static void SetValue(object domainObject, MemberInfo info, object value)
        {
            if (info == null)
            {
                return;
            }

            FieldMapAttribute fa = (FieldMapAttribute)System.Attribute.GetCustomAttribute(info, typeof(FieldMapAttribute));

            if (fa == null)
            {
                return;
            }

            Type type1 = (info is FieldInfo) ? ((FieldInfo)info).FieldType : ((PropertyInfo)info).PropertyType;

            if (fa.BlobType == BlobTypes.Binary)
            {
                if (!((DomainObject)domainObject).IsBlobIgnored)
                {
                    DomainObjectUtility.SetValue(domainObject, info, value, null);
                    return;
                }
            }

            if (type1 == typeof(int))
            {
                if (value is System.DBNull)
                {
                    return;
                }
                else
                {
                    DomainObjectUtility.SetValue(domainObject, info, System.Int32.Parse(value.ToString()), null);
                    return;
                }
            }

            if (type1 == typeof(long))
            {
                if (value is System.DBNull)
                {
                    return;
                }

                DomainObjectUtility.SetValue(domainObject, info, System.Int64.Parse(value.ToString()), null);
                return;
            }

            if (type1 == typeof(double))
            {
                if (value is System.DBNull)
                {
                    return;
                }

                DomainObjectUtility.SetValue(domainObject, info, System.Double.Parse(value.ToString()), null);
                return;
            }

            if (type1 == typeof(float))
            {
                if (value is System.DBNull)
                {
                    return;
                }

                DomainObjectUtility.SetValue(domainObject, info, System.Single.Parse(value.ToString()), null);
                return;
            }

            if (type1 == typeof(decimal))
            {
                if (value is System.DBNull)
                {
                    return;
                }

                //DomainObjectUtility.SetValue(domainObject, info, System.Decimal.Parse(DomainObjectUtility.GetValueString(value)), null);
                //说明: 以前的方法在高精度的double数据转换成decimal数据的时候,报参数类型不对的错误,原因是高精度的double的数据在ToString之后会编程科学记数法,因此decimal.parse的时候会出错
                //解决方法: 私有方法专门对
                DomainObjectUtility.SetValue(domainObject, info, DomainObjectUtility.Getdecimal(value), null);
                return;
            }

            if (type1 == typeof(bool))
            {
                DomainObjectUtility.SetValue(domainObject, info, value.ToString() == "Y", null);
                return;
            }
            if (type1 == typeof(string))
            {
                DomainObjectUtility.SetValue(domainObject, info, value.ToString(), null);
                return;
            }

            if (type1 == typeof(DateTime))
            {
                DateTime result;
                DateTime.TryParse(value.ToString(), out result);
                DomainObjectUtility.SetValue(domainObject, info, result, null);

                return;
            }

            if (type1.IsEnum)
            {
                DomainObjectUtility.SetValue(domainObject, info, Enum.Parse(type1, value.ToString()), null);
                return;
            }

            DomainObjectUtility.SetValue(domainObject, info, value, null);
        }