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)); }
public void CreateSetField() { var contact = new ContactField { Id = Guid.NewGuid().ToString(), FirstName = "Jim", LastName = "Bob", }; var type = typeof(ContactField); var firstProperty = type.GetTypeInfo().GetField("FirstName"); Assert.NotNull(firstProperty); var firstDelegate = DynamicMethodFactory.CreateSet(firstProperty); Assert.NotNull(firstDelegate); firstDelegate(contact, "Jimmy"); Assert.Equal("Jimmy", contact.FirstName); }