RegisterProperty(lambdaExpression) with abstract classes

RegisterProperty(lambdaExpression) with abstract classes

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


decius posted on Wednesday, September 09, 2009

I have some abstract classes I created that extend from BusinessBase<T> like so:

public class MyClass<T> : Csla.BusinessBase<MyClass<T>>

This model has worked for me in the past, but now with the RegisterProperty methods this model breaks the lambda expressions because when implementing the above in concrete classes the inferred type of the lambdaExpression is MyClass<T> rather than just the T. 

I've also noticed that it breaks the return type of the save because of the same problem (in the past I simply used the new keyword and added my own implementation).

Is this incorrect? Should I instead be extending from Csla.Core.BusinessBase rather than Csla.BusinessBase<T>????

tmg4340 replied on Wednesday, September 09, 2009

Typically, the class construct recommended would be something like this:

public abstract class MyClass<T> : Csla.BusinessBase<T>

Which should solve your issues.

Was there a specific reason you chose "Csla.BusinessBase<MyClass<T>>"?

- Scott

JoeFallon1 replied on Wednesday, September 09, 2009

The recommendation is to create your own set of Base classes which your BOs can inherit from.

So MyClass<T> is exactly right.

But only if it is used as your Base class that concrete BOs inherit from.

So it is better to name it MyBusinessBass<T> and to put your common company specific code in it.

HTH

Joe

 

decius replied on Wednesday, September 09, 2009

Thanks! I don't know why I didn't realize that! That's really obvious now that I see it. 

Copyright (c) Marimer LLC