Esempio n. 1
0
 public static PropertyInfo GetDataProviderField(object obj, DataProviderKeyType keyType)
 {
     return(obj.GetType()
            .GetProperties()
            .Where(p => DataProviderResultField.IsDefined(p, typeof(DataProviderResultField)))
            .Where(p => ((DataProviderResultField)DataProviderResultField.GetCustomAttribute(p, typeof(DataProviderResultField))).KeyType == keyType).FirstOrDefault());
 }
Esempio n. 2
0
        public static T BindFormValues <T>(T obj, string prefix, DataProviderKeyType ignoreKeyType)
        {
            Dictionary <string, string> formValues = null;

            formValues = GetFormValues(prefix);

            if (formValues?.Count > 0)
            {
                List <PropertyInfo> objPropertyInfo = null;

                objPropertyInfo = obj.GetType().GetProperties().ToList();

                if (objPropertyInfo?.Count > 0)
                {
                    foreach (PropertyInfo property in objPropertyInfo)
                    {
                        object objProperty = null;

                        objProperty = property.GetValue(obj);

                        if (ProviderBase.Data.Utility.HasDataProviderKeyType(property, ignoreKeyType) == false)
                        {
                            string objValue = "";

                            if (formValues.TryGetValue(prefix + property.Name, out objValue))
                            {
                                if (property.PropertyType.IsEnum)
                                {
                                    int objValueInt = 0;

                                    objValueInt = ProviderBase.Data.Utility.TryParse <int>(objValue);

                                    property.SetValue(obj, objValueInt);
                                }
                                else
                                {
                                    object value = null;

                                    value = ProviderBase.Data.Utility.ChangeType(objValue, property.PropertyType);

                                    property.SetValue(obj, value);
                                }
                            }
                        }
                    }
                }
            }

            return(obj);
        }
Esempio n. 3
0
 public static bool HasDataProviderKeyType(PropertyInfo objectPropertyInfo, DataProviderKeyType keyType)
 {
     return(((DataProviderResultField)objectPropertyInfo.GetCustomAttribute(typeof(DataProviderResultField))).KeyType == keyType);
 }
Esempio n. 4
0
        public static List <PropertyInfo> GetDataProviderKeyTypeList(List <object> objectList, DataProviderKeyType keyType, bool filterValueNotSet)
        {
            List <PropertyInfo> propertyInfoList = new List <PropertyInfo>();

            foreach (object obj in objectList)
            {
                List <PropertyInfo> propertyInfoListTemp = null;

                propertyInfoListTemp = GetDataProviderKeyTypeList(obj, keyType);

                if (filterValueNotSet)
                {
                    foreach (PropertyInfo primaryKey in propertyInfoListTemp)
                    {
                        int    primaryKeyValueInt    = 0;
                        string primaryKeyValueString = primaryKey.GetValue(obj).ToString();

                        if (int.TryParse(primaryKeyValueString, out primaryKeyValueInt))
                        {
                            if (primaryKeyValueInt == 0)
                            {
                                propertyInfoList.Add(primaryKey);
                            }
                        }
                    }
                }
                else
                {
                    propertyInfoList.AddRange(GetDataProviderKeyTypeList(obj, keyType));
                }
            }

            return(propertyInfoList);
        }
Esempio n. 5
0
 public static List <PropertyInfo> GetDataProviderKeyTypeList(List <object> objectList, DataProviderKeyType keyType)
 {
     return(GetDataProviderKeyTypeList(objectList, keyType, false));
 }
 public DataProviderResultField(string field, DataProviderKeyType keyType, params DataProviderResultFieldAction[] actions)
 {
     this.Field   = field;
     this.KeyType = keyType;
     this.Actions = actions;
 }