예제 #1
0
        public ObjectDescription(Type type, PersistentStorage ps)
        {
            if (ps == null)
            {
                throw new ApplicationException("PS is null");
            }
            _ps                   = ps;
            _type                 = type;
            _properties           = new PropertyDescriptionCollection(this);
            _allProperties        = new PropertyDescriptionCollection(this);
            _relations            = new PropertyDescriptionCollection(this);
            _mappedProperties     = new PropertyDescriptionCollection(this);
            _oneToOneProperties   = new PropertyDescriptionCollection(this);
            _oneToManyProperties  = new PropertyDescriptionCollection(this);
            _manyToManyProperties = new PropertyDescriptionCollection(this);

            Configuration.EntityConfiguration ec = null;
            if (ps.PsComfiguration != null && ps.PsComfiguration.Entities.ContainsKey(type.Name))
            {
                ec = ps.PsComfiguration.Entities[type.Name];
            }

            foreach (PropertyInfo prop in _type.GetProperties())
            {
                Configuration.EntityPropertyConfiguration epc = null;
                if (ec != null && ec.Properties.ContainsKey(prop.Name))
                {
                    epc = ec.Properties[prop.Name];
                }
                PropertyDescription pd = new PropertyDescription(this, prop, epc);

                //// This is incorrect
                if (pd.Name == "Item")
                {
                    continue;
                }
                ////

                _allProperties.Add(pd);
                if (!pd.IsInternal)
                {
                    _properties.Add(pd);
                }
                if (pd.IsRelation)
                {
                    _relations.Add(pd);
                }
                if (pd.IsMapped)
                {
                    _mappedProperties.Add(pd);
                }
                if (pd.IsId)
                {
                    _idField = pd;
                }
                if (pd.IsManyToManyRelation)
                {
                    _manyToManyProperties.Add(pd);
                }
                if (pd.IsOneToManyRelation)
                {
                    _oneToManyProperties.Add(pd);
                }
                if (pd.IsOneToOneRelation)
                {
                    _oneToOneProperties.Add(pd);
                }
            }

            _attributes = new Attribute[_type.GetCustomAttributes(false).Length];
            for (int i = 0; i < _type.GetCustomAttributes(false).Length; i++)
            {
                _attributes.SetValue(_type.GetCustomAttributes(false)[i], i);
            }
            _isEntity = IsDescendentFrom(typeof(IEntity));
            //_factoryDescription = new ObjectFactoryDescription(new DefaultObjectFactory());

            if (ec != null && ec.Attributes.ContainsKey("AgregatedClass"))
            {
                _isAggregated = Convert.ToBoolean(ec.Attributes["AgregatedClass"]);
            }
            else
            {
                _isAggregated = GetAttribute <AgregatedClassAttribute>() != null;
            }

            if (ec != null && ec.Attributes.ContainsKey("DenyLoadAllOnGetById"))
            {
                _isDenyGetAllOnGetById = true;
            }
            else
            {
                _isDenyGetAllOnGetById = GetAttribute <DenyLoadAllOnGetByIdAttribute>() != null;
            }

            if (ec != null && ec.Attributes.ContainsKey("Table"))
            {
                if (string.IsNullOrEmpty(ec.Attributes["Table"].Paramaters))
                {
                    throw new Exception("Invalid TableAttribute format");
                }
                string[] param = ec.Attributes["Table"].Paramaters.Split(',');
                if (param.Length == 1)
                {
                    _tableAttribute = new TableAttribute(param[0]);
                }
                else if (param.Length == 4)
                {
                    ConditionOperation op;
                    if (param[2] == "Equals")
                    {
                        op = ConditionOperation.Equals;
                    }
                    else
                    {
                        op = ConditionOperation.NotEquals;
                    }
                    _tableAttribute = new TableAttribute(param[0], param[1], op, param[3]);
                }
                else
                {
                    throw new Exception("Invalid TableAttribute format");
                }
            }
            else
            {
                _tableAttribute = GetAttribute <TableAttribute>();
            }

            IdFieldTypeAttribute idTypeAttr = GetAttribute <IdFieldTypeAttribute>();

            if (idTypeAttr == null)
            {
                _idFiledType = typeof(Guid);
            }
            else
            {
                _idFiledType = idTypeAttr.IdType;
            }

            ClassCaptionAttribute attr = GetAttribute <ClassCaptionAttribute>();

            if (ec != null && ec.Attributes.ContainsKey("ClassCaption"))
            {
                _caption = ec.Attributes["ClassCaption"].Paramaters;
            }
            else
            {
                if (attr != null)
                {
                    _caption = attr.Caption;
                }
                else
                {
                    _caption = type.Name;
                }
            }

            WrappedClassAttribute wattr = GetAttribute <WrappedClassAttribute>();

            if (wattr != null)
            {
                if (!IsDescendentFrom(typeof(IWrapObject)))
                {
                    throw new Exception("A class marked with WrappedClass attribute must implement the IWrapObject interface");
                }
                _isWrapped    = true;
                _wrappedClass = wattr.WrappedType;
            }
            else
            {
                _isWrapped = false;
            }

            VirtualObjectAttribute vattr = GetAttribute <VirtualObjectAttribute>();

            if (vattr != null)
            {
                _isVirtual        = true;
                _getAllMethodName = vattr.GetAllMethodName;
            }


            //foreach ( PropertyDescription pd in Properties )
            //{
            //    DataColumn col = new DataColumn(pd.Name, pd.PropertyType);
            //    //if ( col.DataType == typeof(int) )
            //    //    col.DefaultValue = default(int);
            //    //else if ( col.DataType == typeof(double) )
            //    //    col.DefaultValue = default(double);
            //    //else if ( col.DataType == typeof(byte) )
            //    //    col.DefaultValue = default(byte);
            //    //else if ( col.DataType == typeof(char) )
            //    //    col.DefaultValue = default(char);
            //    //else if ( col.DataType == typeof(DateTime) )
            //    //    col.DefaultValue = default(DateTime);
            //    //else if ( col.DataType == typeof(Guid) )
            //    //    col.DefaultValue = default(Guid);
            //    //else if ( col.DataType == typeof(float) )
            //    //    col.DefaultValue = default(float);
            //    //else if ( col.DataType == typeof(uint) )
            //    //    col.DefaultValue = default(uint);
            //    //else if ( col.DataType == typeof(bool) )
            //    //    col.DefaultValue = default(bool);
            //    //else if ( col.DataType == typeof(string) )
            //    //    col.DefaultValue = default(string);
            //    //else if ( col.DataType.IsEnum )
            //    //    col.DefaultValue = col.DataType.
            //    //else if ( col.DataType.IsEnum )
            //    //    col.DefaultValue = default(int);
            //    col.DefaultValue = pd.PropertyDefaultValue;
            //    Table.Columns.Add(col);
            //}
        }
예제 #2
0
 internal PropertyDescriptionCollectionEnumerator(PropertyDescriptionCollection owner)
 {
     _owner = owner;
 }