An ObjectFactory for ROLB

An ObjectFactory for ROLB

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


rfcdejong posted on Friday, January 30, 2009

Hmm... Insert failed when doing ROLB.Add(ROB)

Ok, thats because ROLB.IsReadOnly should be false while adding the list items.
But.... "cannot be used in this context because the set accessor is inaccessible"

public RelatieInfoList Fetch(RelatieInfoCriteria criteria)
...
   
RelatieInfoList
result = (RelatieInfoList)Activator.CreateInstance(typeof(RelatieInfoList), true);
   result.IsReadOnly =
false;
   foreach (var item in queryResult)
   {
      
RelatieInfo relatie = (RelatieInfo)Activator.CreateInstance(typeof(RelatieInfo), true);
      LoadProperty(relatie,
RelatieInfo.databronProperty, BusinessObjectDatabron.DiasDataBase);
      LoadProperty(relatie,
RelatieInfo.naamProperty, item.Naam);
      LoadProperty(relatie,
RelatieInfo.kenmerkProperty, item.Kenmerk);
      result.Add(relatie);
   }
   result.IsReadOnly =
true;
}

Kevin Fairclough replied on Friday, January 30, 2009

One possible solution would be to use the MethodCaller from Csla.Reflection.

MethodCaller.CallMethod(result, "Add", relate);

or.. you could expose an Add method on the ROLB specifically for the factory that takes in the queryResult

Kevin Fairclough replied on Friday, January 30, 2009

Probably best to only have the reflection call once, so I would add a method to a derivative of ReadOnlyListBase that takes in the list to add to itself.

Then either that method would be public or you can use CallMethod to call that Add once.


rfcdejong replied on Friday, January 30, 2009

I've reintroduced the Add method in my base class for ROLB and made it internal so the ObjectFactory's can access it.

In our base class i wrote something like:

IsReadOnly = false;
base.Add(item);
IsReadOnly = true;

Works ok ;)

Copyright (c) Marimer LLC