PropertyInfo in abstract classes

PropertyInfo in abstract classes

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


RealMrTea posted on Monday, April 07, 2008

I have run into a snag with the new PropertyInfo objects added in 3.5 when a property info object is added to an inheritance chain.  What I want to do is 'base out' all of the common properies for my senario (ID, LastChanged, etc...).  If I do this with PropertyInfo objects the first problem I ran into is that you need to include a static constructor on the base class otherwise the order in which the static PropertyInfo objects is created will be out of order and sometimes it will work and sometimes it will not.  If you do not create the static constructor you will often times that when you call GetProperty the FieldManager thinks the property does not exist.  Add the static constructor and it works fine.

The second problem I have not been able to work around yet. It has to do with deserializing the property object back on the client.  I retrieve an objet from the database on the server (using WCF) and everything is fine.  Then the object moves to the client and the problems start happening.  Inside of the FieldDataManager there is a method called CreateConsolidatedList.  This method has some code in the beginning to walk through the inheritance hierarchy and pull the PropertyInfo objects out of those objects.  The problem is that if that object has never been used before this point there are not PropertyInfo object registered so it will always return an empty list (count=0).  You might get 5 objects in the _fieldData list but only 1 in the _propertyList where 4 objects are in the base class and 1 object is in your child class.  This throws the indexes off and the thing crashes and burns pretty quickly.

I have temporarily turned off the PropertyInfo objects in my base classes but I would like to know why this is happenening and if I am doing something wrong here.  I modified the Project object from the ProjectTracker example to duplicate this problem.  I added the following code and based Project on BaseClass rather than on BusinessBase directly. Also remove the Id Property and anything else you base out from the Project object.

[Serializable()]

public class BaseClass<C> : BusinessBase<C> where C : BusinessBase<C>

{

static BaseClass()

{

}

internal static PropertyInfo<Guid> IdProperty =

RegisterProperty<Guid>(typeof(C), new PropertyInfo<Guid>("Id"));

[DataObjectField(true, true)]

public Guid Id

{

get { return GetProperty<Guid>(IdProperty); }

}

public override string ToString()

{

return Id.ToString();

}

}

 

public class Project : BaseClass<Project>

.

.

.

 

If anyone has any ideas please let me know.

 

Thanks,

Eric

RealMrTea replied on Friday, April 11, 2008

I found the following article relating to this issue...after trying it I can not get the stupid thing to work.

http://www.lhotka.net/Article.aspx?area=4&id=3bf8411e-8c4a-44b7-9fda-33c0e354aa57

 

Does anyone have an example of how to make this work?

Copyright (c) Marimer LLC