예제 #1
0
        public void GetMethodInfoInstanceFunctionVariableTest()
        {
            Expression <Func <Test8, int> > expression = methodObject => methodObject.Method1();
            var result = ReflectionExpressions.GetMethodInfo(expression);

            Assert.AreEqual("Method1", result.Name);
        }
예제 #2
0
        public void GetMethodInfoStaticFunctionVariableTest()
        {
            Expression <Func <int> > expression = () => Test8.Method5();
            var result = ReflectionExpressions.GetMethodInfo(expression);

            Assert.AreEqual("Method5", result.Name);
        }
예제 #3
0
        // When using interface and new() generic constraints, expression contains Convert to the interface.
        private void TryGetPropertyNameGeneric <T>()
            where T : ITest1, new()
        {
            Expression <Func <T, object> > expression = test => test.Y;

            Assert.AreEqual("Y", ReflectionExpressions.TryGetPropertyName(expression));
        }
예제 #4
0
        public void GetMethodInfoInstanceFunctionWithArgumentsTest()
        {
            var result = ReflectionExpressions.GetMethodInfo <Test8>(methodObject =>
                                                                     methodObject.Method2(default(string), default(int)));

            Assert.AreEqual("Method2", result.Name);
        }
예제 #5
0
            private static void ValidateMethod(Expression node, MethodInfo method)
            {
                if (node == null)
                {
                    throw new ArgumentNullException("node");
                }
                if (method == null)
                {
                    throw new ArgumentNullException("method");
                }

                if ((method.DeclaringType == typeof(Extensions)) &&
                    (method.Name == ReflectionExpressions.GetMethodName <Expression <Func <object> > >(
                         expression => expression.Evaluate())))
                {
                    Assert.Fail("The expression body has evaluation: \"{0}\".", node);
                }
                if ((method.DeclaringType != null) &&
#if NET35 || SL3 || WINDOWS_PHONE || PORTABLE36 || PORTABLE88 || PORTABLE328
                    (method.DeclaringType.BaseType ==
#else
                    (method.DeclaringType.GetTypeInfo().BaseType ==
#endif
                     typeof(MulticastDelegate)) &&
                    (method.Name == ReflectionExpressions.GetMethodName <Action>(action => action.Invoke())))
                {
                    Assert.Fail("The expression body has invokation: \"{0}\".", node);
                }
            }
예제 #6
0
        /// <summary>
        /// Configures the primary key property(s) for this entity type.
        /// </summary>
        /// <typeparam name="TKey"> The type of the key. </typeparam>
        /// <param name="keyExpression"> A lambda expression representing the property to be used as the primary key.
        /// C#: t => t.Id VB.Net: Function(t) t.Id
        /// If the primary key is made up of multiple properties then specify an anonymous type including the properties.
        /// C#: t => new { t.Id1, t.Id2 } VB.Net: Function(t) New With { t.Id1, t.Id2 } </param>
        /// <returns> The same EntityTypeConfiguration instance so that multiple calls can be chained. </returns>
        public EntityTypeConfiguration <TEntityType> HasKey <TKey>(Expression <Func <TEntityType, TKey> > keyExpression)
        {
            if (keyExpression == null)
            {
                throw new ArgumentNullException("keyExpression");
            }

            primaryKeyProperty = ReflectionExpressions.GetPropertyInfo(keyExpression);
            return(this);
        }
예제 #7
0
        /// <summary>
        /// Configures the relationship to use foreign key property(s) that are exposed in the object model.
        /// If the foreign key property(s) are not exposed in the object model then use the Map method.
        /// </summary>
        /// <typeparam name="TKey"> The type of the key. </typeparam>
        /// <param name="foreignKeyExpression"> A lambda expression representing the property to be used as the foreign key. If the foreign key is made up of multiple properties then specify an anonymous type including the properties. When using multiple foreign key properties, the properties must be specified in the same order that the the primary key properties were configured for the principal entity type. </param>
        /// <returns> A configuration object that can be used to further configure the relationship. </returns>
        public CascadableNavigationPropertyConfiguration HasForeignKey <TKey>(
            Expression <Func <TDependentEntityType, TKey> > foreignKeyExpression)
        {
            if (foreignKeyExpression == null)
            {
                throw new ArgumentNullException("foreignKeyExpression");
            }

            foreignKeyProperty = ReflectionExpressions.GetPropertyInfo(foreignKeyExpression);
            return(this);
        }
예제 #8
0
        /// <summary>
        /// Configures a <see cref="T:System.byte[]" /> property that is defined on this type.
        /// </summary>
        /// <param name="propertyExpression"> A lambda expression representing the property to be configured. C#: t => t.MyProperty VB.Net: Function(t) t.MyProperty </param>
        /// <returns> A configuration object that can be used to configure the property. </returns>
        public BinaryPropertyConfiguration Property(Expression <Func <TStructuralType, byte[]> > propertyExpression)
        {
            if (propertyExpression == null)
            {
                throw new ArgumentNullException("propertyExpression");
            }

            var property = ReflectionExpressions.GetPropertyInfo(propertyExpression);
            PrimitivePropertyConfiguration propertyConfiguration;

            if (!PropertyConfigurationsByProperty.TryGetValue(property, out propertyConfiguration))
            {
                propertyConfiguration = new BinaryPropertyConfiguration(property);
                PropertyConfigurationsByProperty.Add(property, propertyConfiguration);
            }
            return((BinaryPropertyConfiguration)propertyConfiguration);
        }
예제 #9
0
        /// <summary>
        /// Configures a required relationship from this entity type.
        /// Instances of the entity type will not be able to be saved to the database unless this relationship is specified.
        /// The foreign key in the database will be non-nullable.
        /// </summary>
        /// <typeparam name="TTargetEntity"> The type of the entity at the other end of the relationship. </typeparam>
        /// <param name="navigationPropertyExpression"> A lambda expression representing the navigation property
        /// for the relationship. C#: t => t.MyProperty VB.Net: Function(t) t.MyProperty </param>
        /// <returns> A configuration object that can be used to further configure the relationship. </returns>
        public RequiredNavigationPropertyConfiguration <TEntityType, TTargetEntity> HasRequired <TTargetEntity>(
            Expression <Func <TEntityType, TTargetEntity> > navigationPropertyExpression)
            where TTargetEntity : class
        {
            if (navigationPropertyExpression == null)
            {
                throw new ArgumentNullException("navigationPropertyExpression");
            }

            var navigationProperty = ReflectionExpressions.GetPropertyInfo(navigationPropertyExpression);
            IRequiredNavigationPropertyConfiguration propertyConfiguration;

            if (!requiredAssociationsByProperty.TryGetValue(navigationProperty, out propertyConfiguration))
            {
                propertyConfiguration =
                    new RequiredNavigationPropertyConfiguration <TEntityType, TTargetEntity>(navigationProperty);
                requiredAssociationsByProperty.Add(navigationProperty, propertyConfiguration);
            }
            return((RequiredNavigationPropertyConfiguration <TEntityType, TTargetEntity>)propertyConfiguration);
        }
예제 #10
0
        public void ExpandExpressionsExpand1QuoteTest()
        {
            Expression <Func <int, int> > f1 = y => y + 2;

            var x = Expression.Parameter(typeof(int), "x");
            Expression <Func <int, int> > f2 = Expression.Lambda <Func <int, int> >(
                Expression.Multiply(
                    Expression.Call(
                        ReflectionExpressions.GetMethodInfo <Expression <Func <int, int> > >(expression =>
                                                                                             expression.Evaluate(default(int))),
                        Expression.Quote(f1),
                        x),
                    Expression.Constant(3)),
                new[]
            {
                x
            });
            var result = f2.ExpandExpressions();

            NoDuplicateParameterAssertion.AssertNoDuplicateParameters(result);
            Assert.AreEqual(9, result.Compile()(1));
            NoEvaluationsAssertion.AssertNoEvaluations(result);
        }
예제 #11
0
        public void GetMethodInfoInstanceVoidTest()
        {
            var result = ReflectionExpressions.GetMethodInfo <Test8>(methodObject => methodObject.Method3());

            Assert.AreEqual("Method3", result.Name);
        }
예제 #12
0
 public void TryGetMethodNameNullTest4()
 {
     Assert.IsNull(ReflectionExpressions.TryGetMethodName((Expression <Action>)null));
 }
예제 #13
0
        public void TryGetFieldNameTest()
        {
            Expression <Func <Test2, object> > expression = test => test.y;

            Assert.AreEqual("y", ReflectionExpressions.TryGetFieldName(expression));
        }
예제 #14
0
 public void TryGetPropertyNameNullTest1()
 {
     Assert.IsNull(ReflectionExpressions.TryGetPropertyName((Expression <Func <object, object> >)null));
 }
예제 #15
0
        public void TryGetIndexedPropertyNameTest()
        {
            Expression <Func <Test2, object> > expression = test => test[default(string)];

            Assert.AreEqual("Item", ReflectionExpressions.TryGetPropertyName(expression));
        }
예제 #16
0
        public void TryGetPropertyNameTest()
        {
            Expression <Func <Test2, object> > expression = test => test.X;

            Assert.AreEqual("X", ReflectionExpressions.TryGetPropertyName(expression));
        }
예제 #17
0
 public void TryGetFieldNameNullTest2()
 {
     Assert.IsNull(ReflectionExpressions.TryGetFieldName((Expression <Func <object> >)null));
 }
예제 #18
0
        public void GetMethodInfoStaticFunctionTest()
        {
            var result = ReflectionExpressions.GetMethodInfo(() => Test8.Method5());

            Assert.AreEqual("Method5", result.Name);
        }
예제 #19
0
 public void TryGetFieldNameNullTest3()
 {
     Assert.IsNull(ReflectionExpressions.TryGetFieldName((LambdaExpression)null));
 }