RegisterPropery( Type, PropertyInfo )

RegisterPropery( Type, PropertyInfo )

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


ajj3085 posted on Friday, September 18, 2009

Hi,

I have a abstract business class which doesn't inherit Csla.BusinessBase, instead inheriting Csla.Core.BusinessBase. Other classes then inhert this class.

For the first time in this class (its fairly old), I'm trying to setup a managed property, and I only have the method RegisterProperty( Type, PropertyInfo ).

My question is this: What are the effects of specifying the abstract class' type vs. the "final" subclass type? Here's some sample code:

public abstract Document : Csla.Core.BusinessBase {
private static readonly PropertyInfo ChildProperty =
RegisterProperty( typeof( Document ), "Child" );

public MyChild Child { get; private set; }
}

public sealed Quote : Document {

}

So will that setup cause any problems? Most of the UI code only deals with the abstract,and in the case of the Child property, this will always be true.

Thanks
Andy

RockfordLhotka replied on Friday, September 18, 2009

If you don't reuse that abstact base type as a base class for other final subclass types it should work fine.

SonOfPirate replied on Saturday, September 19, 2009

The other option is to make your base class generic and use the generic type in the RegisterProperty call.  For example:

public abstract Document<T> : Csla.Core.BusinessBase
    where T : Document<T>
{
private static readonly PropertyInfo ChildProperty =
    RegisterProperty(typeof(T), "Child");
 
public MyChild Child { get; private set; }
}
 
public sealed Quote : Document<Quote>
{
}

 

rsbaker0 replied on Sunday, September 20, 2009

RockfordLhotka:

If you don't reuse that abstact base type as a base class for other final subclass types it should work fine.

Why would this cause a problem? (Sorry if I'm missing something obvious, but I don't see why you would ever have an abstract base if you planned on deriving only one class from it)

RockfordLhotka replied on Sunday, September 20, 2009

Well let me put it another way.

 

Properties are registered to types. If you register your properties with the type in which the property is actually declared you won’t have a problem (inheritance or not). If you register a property for a type in which it isn’t declared then things will break.

 

So declaring properties in an abstract base class, using the RegisterProperty() overload that takes an explicit type is fine – as long as the type you provide is the type of the abstract base class, and the property is actually declared/implemented in that abstract base class.

ajj3085 replied on Monday, September 21, 2009

RockfordLhotka:

So declaring properties in an abstract base class, using the
RegisterProperty() overload that takes an explicit type is fine – as long as
the type you provide is the type of the abstract base class, and the property
is actually declared/implemented in that abstract base class.


Yes, that's exactly what I'm doing. The subclasses only differ in their AddAuthorizationRules overrides, but the property registration and the implementation of the property is all in the abstract class.

Copyright (c) Marimer LLC