Пример #1
0
 public static DataRow PopulateDataRow(object entity, DataRow row, bool shapePropertyNames, Type entityType)
 {
     foreach (PropertyInfo p in entityType.GetProperties())
     {
         object propertyValue = GetPropertyValue(p.Name, entity, true);
         string propertyName  = shapePropertyNames ? DataShaper.ShapeCamelCaseString(p.Name) : p.Name;
         row[propertyName] = propertyValue;
     }
     return(row);
 }
Пример #2
0
        public EntityCacheGeneric(string name)
        {
            Type type = this.GetType();

            _name            = string.IsNullOrEmpty(name) ? DataShaper.ShapeCamelCaseString(type.Name) : name;
            _defaultFilePath = Path.Combine(Information.GetExecutingDirectory(), string.Format("{0}.xml", type.Name));

            _entities        = new Dictionary <K, E>();
            _addedEntities   = new Dictionary <K, E>();
            _deletedEntities = new Dictionary <K, E>();
            _updatedEntities = new Dictionary <K, E>();
        }
Пример #3
0
        public EntityCache(Type entityType)
        {
            Type type = this.GetType();

            _name            = DataShaper.ShapeCamelCaseString(type.Name);
            _defaultFilePath = Path.Combine(Information.GetExecutingDirectory(), string.Format("{0}.xml", type.Name));
            _entityType      = entityType;

            _entities        = new List <object>();
            _addedEntities   = new List <object>();
            _deletedEntities = new List <object>();
        }
Пример #4
0
        public static string GetPropertyName <TProp>(Expression <Func <E, TProp> > expression, bool shapePropertyName)
        {
            var body = expression.Body as MemberExpression;

            if (body == null)
            {
                throw new ArgumentException("'expression' should be a member expression");
            }
            if (shapePropertyName)
            {
                return(DataShaper.ShapeCamelCaseString(body.Member.Name));
            }
            return(body.Member.Name);
        }
Пример #5
0
        /// <summary>
        /// Gets a the names of properties of the specified entity type whose types match are in the specified list of propertyTypes.
        /// </summary>
        /// <param name="entityType">The type of the property to reflect against.</param>
        /// <param name="propertyTypes">The types of which the properties of the entity should be.</param>
        /// <returns></returns>
        public static List <string> GetPropertyNamesByType(Type entityType, List <Type> propertyTypes, bool shapeColumnNames)
        {
            List <string>             result = new List <string>();
            Dictionary <string, Type> propertyTypesLookup = new Dictionary <string, Type>();

            propertyTypes.ForEach(p => propertyTypesLookup.Add(p.FullName, p));
            foreach (PropertyInfo p in entityType.GetProperties())
            {
                if (propertyTypesLookup.ContainsKey(p.PropertyType.FullName)) //Name of property should be included.
                {
                    string columnName = shapeColumnNames ? DataShaper.ShapeCamelCaseString(p.Name) : p.Name;
                    result.Add(columnName);
                }
            }
            return(result);
        }
Пример #6
0
        public static List <string> GetAllPropertyNames(
            bool shapeColumnNames,
            Type entityType,
            List <string> hiddenProperties,
            List <string> unmanagedProperies)
        {
            List <string> result = new List <string>();

            foreach (PropertyInfo p in entityType.GetProperties())
            {
                string columnName = shapeColumnNames ? DataShaper.ShapeCamelCaseString(p.Name) : p.Name;
                if ((hiddenProperties != null && hiddenProperties.Contains(columnName)) ||
                    (unmanagedProperies != null && unmanagedProperies.Contains(columnName)))
                {
                    continue; //This column name should not be added to the result list.
                }
                result.Add(columnName);
            }
            return(result);
        }
Пример #7
0
        public static DataTable GetDataTable(bool shapeColumnNames, Type entityType, List <string> topColumnNames)
        {
            string    tableName = shapeColumnNames ? DataShaper.ShapeCamelCaseString(entityType.Name) : entityType.Name;
            DataTable result    = new DataTable(tableName);
            Dictionary <string, DataColumn> columns = new Dictionary <string, DataColumn>();

            foreach (PropertyInfo p in entityType.GetProperties())
            {
                Type propertyType = p.PropertyType;
                if (p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    propertyType = p.PropertyType.GetGenericArguments()[0];
                }
                if (propertyType == typeof(Boolean))
                {
                    propertyType = typeof(String);
                }
                string columnName = shapeColumnNames ? DataShaper.ShapeCamelCaseString(p.Name) : p.Name;
                columns.Add(columnName, new DataColumn(columnName)
                {
                    Caption  = p.Name,
                    DataType = propertyType
                });
            }
            if (topColumnNames != null)
            {
                foreach (string c in topColumnNames) //Add the top columns to the DataTable.
                {
                    if (!columns.ContainsKey(c))
                    {
                        continue;
                    }
                    result.Columns.Add(columns[c]);
                    columns.Remove(c);
                }
            }
            columns.Keys.ToList().ForEach(c => result.Columns.Add(columns[c])); //Add the remaining columns that were not mentioned in the list of top columns.
            columns.Clear();
            return(result);
        }