Example #1
0
 private void ParseFieldType(DataFieldInfo dataFieldInfo, DataFieldAttribute dataFieldAttribute)
 {
     if (dataFieldAttribute != null)
     {
         dataFieldInfo.DataFieldType = dataFieldAttribute.FieldType;
     }
 }
Example #2
0
        /// <summary>
        /// If a field has a primary key type defined, gets the information for it
        /// </summary>
        /// <param name="dataFieldInfo">The field to check</param>
        /// <param name="propertyInfor">The property information for the field</param>
        protected void ParsePrimaryFieldType(DataFieldInfo dataFieldInfo, PropertyInfo propertyInfor)
        {
            dataFieldInfo.PrimaryKey = false;

            KeyAttribute ka = propertyInfor.GetCustomAttributes(typeof(KeyAttribute), true).FirstOrDefault() as KeyAttribute;
            if (ka != null)
                dataFieldInfo.PrimaryKey = true;
        }
Example #3
0
        /// <summary>
        /// Determines if a field should be loaded
        /// </summary>
        /// <param name="datafieldInfo">The field to check</param>
        /// <param name="dataFieldAttribute">The data attribute if present, null otherwise</param>
        protected void ParseLoad(DataFieldInfo datafieldInfo, DataFieldAttribute dataFieldAttribute)
        {
            datafieldInfo.SelectField = true;

            if (dataFieldAttribute != null)
                datafieldInfo.SelectField = dataFieldAttribute.LoadField;
        }   
Example #4
0
 /// <summary>
 /// Gets some stuff out of the property info
 /// </summary>
 /// <param name="dfi">The field to check</param>
 /// <param name="pi">The property information for the field</param>
 protected void ParsePropertyInfo(DataFieldInfo dfi, PropertyInfo pi)
 {
     dfi.Setter = pi.SetValue;
     dfi.Getter = pi.GetValue;
     dfi.PropertyName = pi.Name;
 }
Example #5
0
 protected void ParseSetNull(DataFieldInfo dataFieldInfo,List<string> setNullFields)
 {
     if (setNullFields != null && !dataFieldInfo.PrimaryKey && setNullFields.Contains(dataFieldInfo.FieldName))
     {
         dataFieldInfo.SetNull = true;
     }
     else
     {
         dataFieldInfo.SetNull = false;
     }
 }
Example #6
0
        /// <summary>
        /// Determines a fields name to use on the data store
        /// </summary>
        /// <param name="datafieldInfo">The field to check</param>
        /// <param name="dataFieldAttribute">The data attribute if present, null otherwise</param>
        /// <param name="propertyInfo">The property information for the field</param>
        protected void ParseFieldName(DataFieldInfo datafieldInfo, DataFieldAttribute dataFieldAttribute, PropertyInfo propertyInfo)
        {
            if (dataFieldAttribute != null)
                datafieldInfo.FieldName = dataFieldAttribute.FieldName;

            if (string.IsNullOrEmpty(datafieldInfo.FieldName))
                datafieldInfo.FieldName = propertyInfo.Name;

            datafieldInfo.EscapedFieldName = string.Concat(_DataManager.Connection.LeftEscapeCharacter, datafieldInfo.FieldName, _DataManager.Connection.RightEscapeCharacter);
        }
Example #7
0
        protected void ParseSetOnInsert(DataFieldInfo dataFieldInfo, DataFieldAttribute dataFieldAttribute)
        {
            dataFieldInfo.SetOnInsert = true;

            if (dataFieldAttribute != null)
            {
                dataFieldInfo.SetOnInsert = dataFieldAttribute.SetOnInsert;
            }
            else if (dataFieldInfo.PrimaryKey)// by default keys are not inserted
            {
                dataFieldInfo.SetOnInsert = false;
            }
        }
Example #8
0
        /// <summary>
        /// Parses data field information from a type
        /// </summary>
        /// <param name="type">The type to parse</param>
        /// <param name="toAdd">What to add the data to</param>
        protected void ParseDataFields(Type type, TypeInfo toAdd,object item)
        {
            toAdd.DataFields = new List<DataFieldInfo>();
            PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.Public);
            List<string> setNullFields = null;
            if (toAdd.BaseTypeName.Equals("TypeBase"))
            {
                dynamic dynObj = item;
                setNullFields = dynObj.SetNullObjects;
            }
            foreach (PropertyInfo pi in properties)
            {
                DataFieldAttribute dataFieldAttribute;

                dataFieldAttribute = pi.GetCustomAttributes(typeof(DataFieldAttribute), true).FirstOrDefault() as DataFieldAttribute;
                IgnoredFieldAttribute ignoredField = pi.GetCustomAttributes(typeof(IgnoredFieldAttribute), true).FirstOrDefault() as IgnoredFieldAttribute;

                if (ignoredField == null)
                {
                    DataFieldInfo dataFieldInfo = new DataFieldInfo();

                    if (pi.PropertyType.IsEnum) 
                    {
                        dataFieldInfo.PropertyType = Enum.GetUnderlyingType(pi.PropertyType); 
                    }
                    else 
                    { 
                        dataFieldInfo.PropertyType = pi.PropertyType; 
                    }

                    if (dataFieldAttribute != null && !string.IsNullOrEmpty(dataFieldAttribute.DefaultValue))
                    {
                        string defaultValue = dataFieldAttribute.DefaultValue;
                        if (dataFieldInfo.PropertyType == typeof(string) && !defaultValue.Contains("("))
                            dataFieldInfo.DefaultValue = string.Concat("'", defaultValue, "'");
                        else
                            dataFieldInfo.DefaultValue = defaultValue;
                    }

                    ParseFieldType(dataFieldInfo, dataFieldAttribute);
                    ParseFieldName(dataFieldInfo, dataFieldAttribute, pi);
                    ParsePrimaryFieldType(dataFieldInfo, pi);
                    ParseSetOnInsert(dataFieldInfo, dataFieldAttribute);
                    ParseLoad(dataFieldInfo, dataFieldAttribute);
                    ParsePropertyInfo(dataFieldInfo, pi);
                    ParseSetNull(dataFieldInfo, setNullFields);
                    toAdd.DataFields.Add(dataFieldInfo);
                }
            }

        }