Example #1
0
        public static T Clone <T>(T source) where T : IEntityState, new()
        {
            T item = new T();

            Mappings.ObjectMapper om = Mappings.ObjectMapper.GetOM(typeof(T));
            OnClone(source, item, om);
            return(item);
        }
Example #2
0
        public static int SaveAsClone(IConnectinContext cc, Mappings.DataObject data)
        {
            Type type = data.GetType();

            Mappings.ObjectMapper om     = Mappings.ObjectMapper.GetOM(type);
            Mappings.DataObject   result = (Mappings.DataObject)Activator.CreateInstance(type);
            OnClone(data, result, om);
            return(Save(cc, result));
        }
Example #3
0
        internal static object Load(Type type, object id, IConnectinContext cc)
        {
            Mappings.ObjectMapper     om = Mappings.ObjectMapper.GetOM(type);
            Mappings.SelectDataReader sr = om.GetSelectReader(type);
            if (om.ID == null)
            {
                throw new PeanutException(DataMsg.ID_MAP_NOTFOUND);
            }
            Expression exp = new Expression();

            exp.SqlText.Append(om.ID.ColumnName + "=@p1");
            exp.Parameters.Add(new Command.Parameter {
                Name = "p1", Value = id
            });
            return(EntityBase.ExOnListFirst(type, cc, om.GetSelectTable(sr), exp, null, null));
        }
Example #4
0
        public static IList <ValidaterError> Verify(object data, IConnectinContext cc)
        {
            Mappings.ObjectMapper om     = Mappings.ObjectMapper.GetOM(data.GetType());
            List <ValidaterError> errors = new List <ValidaterError>(om.Properties.Count);

            for (int i = 0; i < om.Properties.Count; i++)
            {
                PropertyMapper pm    = om.Properties[i];
                object         value = pm.Handler.Get(data);
                for (int k = 0; k < pm.Validaters.Length; k++)
                {
                    ValidaterAttribute val = pm.Validaters[k];

                    if (!val.Validating(value, data, pm, cc))
                    {
                        errors.Add(new ValidaterError {
                            Name = pm.ColumnName, Error = val.Message
                        });
                    }
                }
            }
            return(errors);
        }
Example #5
0
        private static void OnClone(object source, object newobj, Mappings.ObjectMapper om)
        {
            object value = null;

            Mappings.PropertyMapper pm = om.ID;
            if (pm != null)
            {
                value = pm.Handler.Get(source);
                if (value != null)
                {
                    pm.Handler.Set(newobj, value);
                }
            }
            for (int i = 0; i < om.Properties.Count; i++)
            {
                Mappings.PropertyMapper p = om.Properties[i];
                value = p.Handler.Get(source);
                if (value != null)
                {
                    p.Handler.Set(newobj, value);
                }
            }
        }