Exemple #1
0
        public virtual DataContext CreateContext(object data)
        {
            //var type = DataContextAttribute.GetDataContextType(data, typeof(DataContext));
            var             type    = DataContextAttribute.GetDataContextType(this.GetDataType(), typeof(DataContext));
            bool            flag    = this.Session != null;
            ConstructorInfo cinfo   = null;
            DataContext     context = null;

            if (flag)
            {
                cinfo = type.GetConstructor(new Type[] { typeof(ISessionable) });
            }

            if (cinfo == null)
            {
                cinfo = type.GetConstructor(new Type[0]);
                flag  = false;
            }

            if (cinfo != null)
            {
                context        = (DataContext)(flag ? cinfo.Invoke(new object[] { this }) : cinfo.Invoke(new object[0]));
                context.parent = this;
                Type type1 = this.GetDataType();
                Type type2 = CoreTools.GetObjectType(data);
                context.SetData(type1, data);
                if (type1 != type2)
                {
                    context.AddData(type2, data);
                }
            }
            return(context);
        }
Exemple #2
0
        public virtual DataContext BeginEdit(object row)
        {
            if (!this.IsEditing)
            {
                base.BeginEdit();
                if (this.IsEditing)
                {
                    if (row == null)
                    {
                        row           = this.CreateData();
                        this.isNewRow = true;
                    }
                    var             type  = DataContextAttribute.GetDataContextType(row, typeof(DataContext));
                    bool            flag  = this.Session != null;
                    ConstructorInfo cinfo = null;
                    if (flag)
                    {
                        cinfo = type.GetConstructor(new Type[] { typeof(ISessionable) });
                    }

                    if (cinfo == null)
                    {
                        cinfo = type.GetConstructor(new Type[0]);
                        flag  = false;
                    }

                    if (cinfo != null)
                    {
                        this.childContext        = (DataContext)(flag ? cinfo.Invoke(new object[] { this }) : cinfo.Invoke(new object[0]));
                        this.childContext.parent = this;
                        this.childContext.SetData(row);
                        this.childContext.BeginEdit();
                        return(this.childContext);
                    }
                }
            }
            return(null);
        }