this injection is going to fill all the properties of an object of type string with "a" and of type DateTime with DateTime.Now

    public class FillObject : NoSourceValueInjection
    {
        protected override void Inject(object target)
        {
            var targetProps = target.GetProps();

            for (var i = 0; i < targetProps.Count; i++)
            {
                var prop = targetProps[i];
                object val = null;
                if (prop.PropertyType == typeof(string)) val = "a";
                if (prop.PropertyType == typeof(DateTime)) val = DateTime.Now;
                if (val != null)
                    prop.SetValue(target, val);
            }
        }
    }

usage

foo.InjectFrom<FillObject>();

Last edited Aug 11, 2010 at 12:54 PM by o, version 2

Comments

No comments yet.