Beispiel #1
0
        public static ColumnAttribute GetColumnAttribute(PropertyInfo propertyInfo)
        {
            if (propertyInfo.PropertyType == typeof(DataRow))
            {
                return(null);
            }

            ColumnAttribute[] attributes = CustomAttributeProvider.GetAttributes <ColumnAttribute>(propertyInfo);

            foreach (ColumnAttribute attribute in attributes)
            {
                if (attribute.ColumnName == String.Empty)
                {
                    attribute.ColumnName = propertyInfo.Name;
                }

                if (attribute.CType == CType.Auto)
                {
                    attribute.CType = propertyInfo.PropertyType.ToCType();
                }

                return(attribute);
            }

            if (attributes.Length == 0)
            {
                Attribute[] non = CustomAttributeProvider.GetAttributes <NonPersistentAttribute>(propertyInfo);

                if (non.Length > 0)
                {
                    return(null);
                }

                non = CustomAttributeProvider.GetAttributes <AssociationAttribute>(propertyInfo);

                if (non.Length > 0)
                {
                    return(null);
                }

                //no other attribute defined.
                if (propertyInfo.CanRead && propertyInfo.CanWrite)
                {
                    try
                    {
                        return(new ColumnAttribute(propertyInfo.Name, propertyInfo.PropertyType.ToCType()));
                    }
                    catch (Exception)
                    {
                        return(null);    //some type is not supported
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
        private bool IsColumn1Identity()
        {
            ColumnAttribute[] attributes = CustomAttributeProvider.GetAttributes <ColumnAttribute>(propertyInfo1);
            if (attributes.Length == 0)
            {
                return(false);
            }

            return(attributes[0].Identity);
        }
Beispiel #3
0
        public static AssociationAttribute GetAssociationAttribute(PropertyInfo propertyInfo)
        {
            AssociationAttribute[] attributes = CustomAttributeProvider.GetAttributes <AssociationAttribute>(propertyInfo);

            foreach (AssociationAttribute attribute in attributes)
            {
                return(attribute);
            }

            return(null);
        }
Beispiel #4
0
        public virtual void SaveAssociations()
        {
            foreach (PropertyInfo propertyInfo in this.columnProperties)
            {
                Attribute[] association = CustomAttributeProvider.GetAttributes <AssociationAttribute>(propertyInfo);

                if (association.Length != 0)
                {
                    SaveAssociationCollection(propertyInfo);
                }
            }
        }
Beispiel #5
0
        public static VAL Class2VAL(object instance, VAL val)
        {
            val["ClassName"] = new VAL(instance.GetType().FullName);

            FieldInfo[] fields = instance.GetType().GetFields();
            foreach (FieldInfo fieldInfo in fields)
            {
                if (fieldInfo.IsStatic)
                {
                    continue;
                }

                Attribute[] attributes = CustomAttributeProvider.GetAttributes <NonValizedAttribute>(fieldInfo);
                if (attributes.Length != 0)
                {
                    continue;
                }

                attributes = CustomAttributeProvider.GetAttributes <AssociationAttribute>(fieldInfo);
                if (attributes.Length != 0)
                {
                    continue;
                }

                val[fieldInfo.Name] = VAL.Boxing(fieldInfo.GetValue(instance));
            }

            PropertyInfo[] properties = instance.GetType().GetProperties();
            foreach (PropertyInfo propertyInfo in properties)
            {
                ValizableAttribute[] attributes = CustomAttributeProvider.GetAttributes <ValizableAttribute>(propertyInfo);
                if (attributes.Length != 0 && propertyInfo.CanRead)
                {
                    val[propertyInfo.Name] = VAL.Boxing(propertyInfo.GetValue(instance, null));
                }
                else
                {
                    continue;
                }
            }

            return(val);
        }
Beispiel #6
0
 public T[] GetAttributes <T>() where T : Attribute
 {
     return(CustomAttributeProvider.GetAttributes <T>(this.GetType()));
 }