예제 #1
0
파일: IMapper.cs 프로젝트: radtek/Shop
        public ObjectMapper(ObjectSchema <T> schema)
        {
            _schema = schema;
            if (!_schema.IsReadonly)
            {
                _schema.Compile();
            }

            _propertyValues = new IPropertyValue <T> [schema.FieldMaps().Count];

            foreach (FieldMap <T> fieldMap in schema.FieldMaps())
            {
                _propertyValues[schema.IndexOf(fieldMap.Field)] = new PropertyValueForLambda <T>(fieldMap.Expression);
            }
            //

            if (this._schema.Name == null)
            {
                BlockExpression be = BlockExpression.Block(Expression.New(typeof(T)));
                _creator = Expression.Lambda <Func <T> >(be).Compile();
            }
            else
            {
                _Type = EntityBuilder.BuilderEntityClass <T>(schema.FieldMaps().Select(x => (FieldMap <T>)x), schema);
                BlockExpression be = BlockExpression.Block(Expression.New(_Type));
                _creator = Expression.Lambda <Func <T> >(be).Compile();
            }
        }