Exemplo n.º 1
0
        public ReflectionTechnique()
        {
            _firstNameProperty      = new Lazy <PropertyInfo>(() => typeof(Contact).GetProperty("FirstName"));
            _firstNameSetDynamic    = new Lazy <Action <object, object> >(() => DynamicMethodFactory.CreateSet(_firstNameProperty.Value));
            _firstNameGetDynamic    = new Lazy <Func <object, object> >(() => DynamicMethodFactory.CreateGet(_firstNameProperty.Value));
            _firstNameSetExpression = new Lazy <Action <object, object> >(() => ExpressionFactory.CreateSet(_firstNameProperty.Value));
            _firstNameGetExpression = new Lazy <Func <object, object> >(() => ExpressionFactory.CreateGet(_firstNameProperty.Value));

            _firstNameDelegate = new Lazy <IPropertyDelegate>(() => new PropertyDelegate <Contact, string>(_firstNameProperty.Value));
        }
Exemplo n.º 2
0
        public void CreateGetField()
        {
            var contact = new ContactField
            {
                Id        = Guid.NewGuid().ToString(),
                FirstName = "Jim",
                LastName  = "Bob",
            };

            var type       = typeof(ContactField);
            var firstField = type.GetTypeInfo().GetField("FirstName");

            Assert.NotNull(firstField);

            var firstDelegate = ExpressionFactory.CreateGet(firstField);

            Assert.NotNull(firstDelegate);

            var firstName = firstDelegate(contact) as string;

            Assert.Equal(contact.FirstName, firstName);
        }