Example #1
0
        public static ReflectionInfo <TObject> GetInfo <TObject>(System.Reflection.ConstructorInfo constructor = null)
        {
            var    type = typeof(TObject);
            object info;

            if (ReflectionInfoCache.TryGetValue(type, out info))
            {
                return((ReflectionInfo <TObject>)info);
            }
            else
            {
                var refInfo = new ReflectionInfo <TObject>(type);
                ReflectionInfoCache[type] = refInfo;
                return(refInfo);
            }
        }
Example #2
0
        internal static object DataReaderToObj <T>(IDictionary <string, int> columns, object[] values, ReflectionInfo <T> reflection, bool canTuple, object detailItem, IEnumerable <Attribute.FieldAttribute> typeArry, List <ActionItem <T> > actions, bool first) where T : class, new()
        {
            IModel obj2 = null;

            if (detailItem is IModel)
            {
                obj2             = detailItem as IModel;
                obj2.BoundChange = false;
            }
            //return detailItem;
            if (first)
            {
                #region foreach field
                foreach (Attribute.FieldAttribute info in typeArry)
                {
                    ActionItem <T> action;
                    string         fieldName;
                    if (info.FieldType == Attribute.FieldType.关联字段)//按外部字段
                    {
                        string tab = TypeCache.GetTableName(info.ConstraintType, null);
                        fieldName = info.GetTableFieldFormat(tab, info.ConstraintResultField).ToLower();
                    }
                    else
                    {
                        fieldName = info.MapingName.ToLower();
                    }
                    if (columns.ContainsKey(fieldName))
                    {
                        if (canTuple)
                        {
                            var accessor = reflection.GetAccessor(info.MemberName);
                            action = new ActionItem <T>()
                            {
                                Set = accessor.Set, Name = fieldName, ValueIndex = columns[fieldName]
                            };
                        }
                        else
                        {
                            action = new ActionItem <T>()
                            {
                                Set = info.SetValue, Name = fieldName, ValueIndex = columns[fieldName]
                            };
                        }
                        columns.Remove(fieldName);
                        actions.Add(action);
                        action.Set((T)detailItem, values[action.ValueIndex]);
                    }
                }
                #endregion
            }
            else
            {
                foreach (var item in actions)
                {
                    //ActionItem<T> item = actions[i];
                    item.Set((T)detailItem, values[item.ValueIndex]);
                }
            }

            if (obj2 != null && columns.Count > 0)
            {
                foreach (var item in columns)
                {
                    var col = item.Key;
                    var n   = col.LastIndexOf("__");
                    if (n == -1)
                    {
                        continue;
                    }
                    var mapingName = col.Substring(n + 2);
                    //obj2[mapingName] = values[item.Value];
                    obj2.SetIndexData(mapingName, values[item.Value]);
                }
                obj2.BoundChange = true;
            }
            return(detailItem);
        }