I am trying to extend the CSLA base classes in one of my projects and came to a bit of a problem. I tried to use the following syntax (found here: http://forums.lhotka.net/forums/thread/10972.aspx):
public abstract class MyBase<T>: Csla.BusinessBase<T> where T : MyBase<T>{ ... }
public class MyClass : MyBase<MyClass>{ ... }
In this class I have a method that looks like this: public abstract int GetPropertyMaxLength(string propertyName);
Now I am calling this from my UI (from within a textbox to be more specific) but the problem is that I can't upcast the datasource of my control because a type is needed. So what I am trying to do is this:
Library.
MyBase obj = ((BindingSource)this.DataBindings[0].DataSource).DataSource as Library.MyBase;Obviously this does not compile and although I tried a number of ways, I could not get this to work.I ended extending Csla.BusinessBase as follows:
public
abstract class MyBase : BusinessBase<MyBase>It works now but this is ugly... I can't help thinking I am doing somethnig obviously wrong but just can't spot it... Any ideas?
I feel your pain.
I think the key is to realize that generic classes are not really polymorphic.
So it is best to create an Interface in your project which all of your Base classes will use.
e.g.
Public Interface IMyCompanyBusinessObjectThen you can cast to your Interface and use the property or method.
Joe
I would add any Property you need to the Interface and then just "forward the call" in the implementation of the interface to the base method.
Joe
Copyright (c) Marimer LLC