Overiding PropertyInfo<T>

Overiding PropertyInfo<T>

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


shrage posted on Wednesday, December 02, 2009

I would like to stor more information about a property so i inherited from PropertyInfo and added additional fields, here is how i tried to register a property using my own sub class

private static StringPropertyInfo FirstNameProperty = RegisterProperty(c => c.FirstName) as StringPropertyInfo;

But for some reason after this line of code runs, FirstNameProperty will be null, looks like it cannot convert from simple PropertyInfo to my sub class, how would i go about it?

RockfordLhotka replied on Thursday, December 03, 2009

Jason has a blog post about changing the way IsDirty works - which involves creating a custom PropretyInfo<T> type among other things, so this may help:

http://www.jasonbock.net/JB/Default.aspx?blog=entry.9cc70d85bef34e2b9a683ba82615f8a3

rxelizondo replied on Sunday, December 06, 2009

Wowzers ! That sure looks like a lot of work!

Just toying around with this I came up with something that may save you some time if you want to cut some corners. It looks to me though that you almost got something working in your example.

Here is the code, you will need to replace the “{“ with the lower than symbol and the “}” with greater than symbol for the code to compile:

class StringPropertyInfo{P} : PropertyInfo{P}
{
public StringPropertyInfo(string name) : base(name, "")
{
}

public int MyProperty
{
get;
set;
}
}

class SomeClass : BusinessBase{SomeClass}
{
private static StringPropertyInfo{string} IDProperty = (StringPropertyInfo{string})RegisterProperty{string}(new StringPropertyInfo{string}("ID"));
public string ID
{
get { return GetProperty(IDProperty); }
set { SetProperty(IDProperty, value); }
}
}

Copyright (c) Marimer LLC