objectfactory wish

objectfactory wish

Old forum URL: forums.lhotka.net/forums/t/7141.aspx


rfcdejong posted on Monday, June 22, 2009

The internal IManageProperties interface offers the posibility of loading a property without a strictly typed argument. Can the ObjectFactory be extended with an overloaded LoadProperty?

This because we don't know the type at designtime, being dynamic.

protected void LoadProperty(object obj, IPropertyInfo propertyInfo, object newValue)
{
      
var target = obj as Core.IManageProperties;
      
if (target != null)
            target.LoadProperty(propertyInfo, newValue);
      
else
            
throw new ArgumentException(Resources.IManagePropertiesRequiredException);
}

JonnyBee replied on Monday, June 22, 2009

Hi,

The ObjectFactory baseclass exposes the BypassPropertyChecks that essentially changes the behaviour of SetProperty to LoadProperty. Code sample:

      var result =
        (Business.ProductEdit)Activator.CreateInstance(typeof(Business.ProductEdit), true);
             //  data access code omitted for clarity
            using (BypassPropertyChecks(result))
            {
              // set properties here acts like LoadProperty
              result.Id = dr.GetString("Id");
              result.Name = dr.GetString("Name");
            }

/jonnybee

rfcdejong replied on Monday, June 22, 2009

I know about the BypassPropertyChecks, but with readonly businessobjects that isn't enough. Then u'll have to create an constructor with parameters which results into 2 differend ways and our monkeys see two differend bananas..

Just using 1 way: LoadProperty

And even with using reflection it still requires a property setter.

JonnyBee replied on Monday, June 22, 2009

Hi,

You could create a internal Set method that uses LoadProperty on a ReadOnly object.
(and if your ObjectFactory is in another assembly - use the "InternalsVisibleTo" attribute to make it a friend assembly).

/jonny


rfcdejong replied on Monday, June 22, 2009

Thanks jonny,

They are all posibilities, but we decided to use the LoadProperty methods from within the ObjectFactory, just missing the less-strict LoadProperty method described as above. Every new version of Csla i just copy paste it in the Csla code.

Greetings,
Raymond de Jong

rfcdejong replied on Friday, July 17, 2009

Can this be put on the wish list or shall i implement this in our own layer?

I did forgot this after upgrading to 3.7 it and i got a new "bug" work item from an TFS build agent on my name :)
This is the only modification i need to make in the Csla code, maybe i should implement it on our own layer but that's just more work since i don't have access to Core.IManageProperties.

Anyway since the source is included in the tfs build solution it results into version numbering the Csla.dll into our own version, which is not really wrong, but could stay the original Csla version. Including the source also means alot of warnings, for silverlight with a reason but for WPF the C5 stuff is being our warning friend.. However, lowering the warning lvl to 0 does solve that :)

RockfordLhotka replied on Friday, July 17, 2009

I'll add this to the wish list.

Copyright (c) Marimer LLC