public void ExpressionFactoryGeneratesSetterWithCastFromPropertyName()
        {
            var setterWithCastFunc =
                CompiledExpressionFactory.CreatePropertySetterCast <CompiledExpTestEntity, object>("Name");

            Assert.IsNotNull(setterWithCastFunc);
        }
        public void ExpressionFactoryGeneratesGetterFromPropertyInfo()
        {
            PropertyInfo property = typeof(CompiledExpTestEntity).GetProperty("Id");

            var getterFunc = CompiledExpressionFactory.CreatePropertyGetter <CompiledExpTestEntity, int>(property);

            Assert.IsNotNull(getterFunc);
        }
        public void ExpressionFactoryGeneratesSetterWithCastFromPropertyInfo()
        {
            PropertyInfo property = typeof(CompiledExpTestEntity).GetProperty("Name");

            var setterWithCastFunc =
                CompiledExpressionFactory.CreatePropertySetterCast <CompiledExpTestEntity, object>(property);

            Assert.IsNotNull(setterWithCastFunc);
        }
        public void ExpressionFactoryGetterFromPropertySupportsCasting()
        {
            var item = new CompiledExpTestEntity
            {
                Id   = 1,
                Name = "foo"
            };

            var getterFunc = CompiledExpressionFactory.CreatePropertyGetterWithCast <CompiledExpTestEntity, double>("Id");

            Assert.AreEqual(1.0, getterFunc(item));
        }
        public void ExpressionFactoryGetterFromPropertyNameGetPropertyValue()
        {
            var item = new CompiledExpTestEntity
            {
                Id   = 1,
                Name = "foo"
            };

            var getterFunc = CompiledExpressionFactory.CreatePropertyGetter <CompiledExpTestEntity, int>("Id");

            Assert.AreEqual(1, getterFunc(item));
        }
        public void ExpressionFactorySetterFromPropertyNameSetsPropertyValue()
        {
            var item = new CompiledExpTestEntity
            {
                Id   = 1,
                Name = "foo"
            };

            var setterFunc = CompiledExpressionFactory.CreatePropertySetter <CompiledExpTestEntity, int>("Id");

            setterFunc(item, 2);

            Assert.AreEqual(2, item.Id);
        }
Beispiel #7
0
        /// <summary> Create an instance of a type assuming a set of parameters. </summary>
        public object CreateInstance(Type type, object[] args)
        {
            if (args == null || args.Length == 0)
            {
                return(CreateInstance(type));
            }

            // activator
            if (!_activators.TryGetValue(type, out var activator))
            {
                _activators[type] = activator = CompiledExpressionFactory.Build(GetOrCacheConstructorForType(type));
            }

            return(activator(args));
        }
        public void ExpressionFactorySetterFromPropertyNameWithCastSetsPropertyValue()
        {
            var item = new CompiledExpTestEntity
            {
                Id   = 1,
                Name = "foo"
            };

            var setterWithCastFunc =
                CompiledExpressionFactory.CreatePropertySetterCast <CompiledExpTestEntity, object>("Name");

            object o = "bar";

            setterWithCastFunc(item, o);

            Assert.AreEqual("bar", item.Name);
        }
        public void ExpressionFactoryGeneratesSetterFromPropertyName()
        {
            var setterFunc = CompiledExpressionFactory.CreatePropertySetter <CompiledExpTestEntity, int>("Id");

            Assert.IsNotNull(setterFunc);
        }