Esempio n. 1
0
        public void CheckSubProperty(Type mainType)
        {
            for (int index = SubPropertyMeta.Count - 1; index >= 0; index--)
            {
                SearchMetaSubProperty sub = SubPropertyMeta[index];
                bool keep = false;

                //PropertyInfo pi = mainType.GetProperty(sub.PropertyName);
                PropertyInfo pi = SerializableData.GetObjPro(sub.PropertyName, mainType);
                if (pi != null && pi.PropertyType.IsGenericType)
                {
                    sub.SubProperty  = pi;
                    sub.PropertyType = pi.PropertyType;

                    foreach (Type tParam in pi.PropertyType.GetGenericArguments())
                    {
                        if (tParam.IsSubclassOf(typeof(SerializableData)))
                        {
                            sub.PropertyGenericType = tParam;
                            keep = true;
                            break;
                        }
                    }
                }

                if (!keep)
                {
                    SubPropertyMeta.RemoveAt(index);
                }
            }
        }
Esempio n. 2
0
        public void SetValue(string key, object value)
        {
            PropertyInfo _p = SerializableData.GetObjPro(key, this.GetType());

            if (_p != null)
            {
                TypeCode tc = Type.GetTypeCode(_p.PropertyType);
                SetValue(key, value, tc);
            }
            else
            {
                SetValue(key, value, TypeCode.Empty);//默认 不处理
            }
        }
Esempio n. 3
0
        public bool AddMapp(FieldMapping map)
        {
            bool result = false;

            if (!_Properties.ContainsKey(map.PropertyName))
            {
                // map.PropertyInfo = EntityType.GetProperty(map.PropertyName);
                map.PropertyInfo = SerializableData.GetObjPro(map.PropertyName, EntityType);
                if (null != map.PropertyInfo)
                {
                    _Properties.Add(map.PropertyName, map);
                    result = true;
                }
            }
            return(result);
        }
Esempio n. 4
0
        private static T LoadRecord <T>(DataRow row)
        {
            Type EntityType = typeof(T);
            T    newObject  = (T)Activator.CreateInstance(EntityType);

            foreach (DataColumn itme in row.Table.Columns)
            {
                var objValue = row[itme.ColumnName];
                if (objValue != null && objValue != DBNull.Value)
                {
                    /*lxt 20140925 原来的代码可能有问题,先让程序运行
                     * //var Property = EntityType.GetProperty(itme.ColumnName,BindingFlags.IgnoreCase );
                     * //PropertyInfo Property = SerializableData.GetObjPro(itme.ColumnName, EntityType);
                     * //if (Property != null)
                     * //{
                     * //    SetPropertyValue(newObject, Property, objValue);
                     * //}
                     * //else
                     * //{
                     * //    if (newObject is EntityBase)
                     * //    {
                     * //        (newObject as EntityBase)[itme.ColumnName] = objValue;
                     * //    }
                     * //}
                     */
                    if (EntityType == typeof(EntityBase))
                    {
                        (newObject as EntityBase)[itme.ColumnName] = objValue;
                    }
                    else
                    {
                        PropertyInfo Property = SerializableData.GetObjPro(itme.ColumnName, EntityType);
                        DataProvider.SetPropertyValue(newObject, Property, objValue);
                    }
                }
            }
            if (newObject is IEntity)
            {
                (newObject as IEntity).ResetStatus(EntityStatus.Original);
            }
            return(newObject);
        }