Attaching extra information to PropertyInfo objectsAttaching extra information to PropertyInfo objects
Old forum URL: forums.lhotka.net/forums/t/8003.aspx
Pawz.777 posted on Tuesday, November 17, 2009
Hi,
I'm wondering what the best way of attaching additional information to PropertyInfo<T> objects is. I've got a situation where I'd like to eliminate a lot of plumbing code by attaching database information to the field declaration.
Eg. Replace this:
DM.AddParameter("@AssemblyTeamID", _assemblyTeamID);
DM.AddParameter("@AssignedProgrammer", _assignedProgrammer);
.... x 30
with
foreach (var field in FieldManager.GetRegisteredProperties())
{
if (FieldManager.IsFieldDirty(field))
{
DM.AddParameter("@" + field.Name, GetProperty(field));
}
}
This actually works really well, but I'd like to cover cases where the field isn't a database field, is readonly, and so on - I was thinking it would be ideal to declare the properties like:
private static readonly PropertyInfo<Guid> FieldNameProperty =
RegisterProperty(new CustomPropertyInfo<Guid>("FieldName", "Friendly Name", "DatabaseFieldName"));
How would I go about doing this? It's sort of similar to the custom FieldData concept, and I suppose I could go in and tweak the PropertyInfo class directly, but surely there's a better way?
Thanks for any help :)
sergeyb replied on Tuesday, November 17, 2009
You
can just inherit from PropertyInfo class.
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: Pawz.777
[mailto:cslanet@lhotka.net]
Sent: Tuesday, November 17, 2009 8:06 AM
To: Sergey Barskiy
Subject: [CSLA .NET] Attaching extra information to PropertyInfo objects
Hi,
I'm wondering what the best way of attaching additional information to
PropertyInfo<T> objects is. I've got a situation where I'd like to eliminate
a lot of plumbing code by attaching database information to the field
declaration.
Eg. Replace this:
DM.AddParameter("@AssemblyTeamID", _assemblyTeamID);
DM.AddParameter("@AssignedProgrammer",
_assignedProgrammer);
.... x 30
with
foreach (var field in
FieldManager.GetRegisteredProperties())
{
if (FieldManager.IsFieldDirty(field))
{
DM.AddParameter("@" + field.Name, GetProperty(field));
}
}
This actually works really well, but I'd like to cover cases where the field
isn't a database field, is readonly, and so on - I was thinking it would be
ideal to declare the properties like:
private static readonly PropertyInfo<Guid> FieldNameProperty =
RegisterProperty(new CustomPropertyInfo<Guid>("FieldName",
"Friendly Name", "DatabaseFieldName"));
How would I go about doing this? It's sort of similar to the custom FieldData
concept, and I suppose I could go in and tweak the PropertyInfo class directly,
but surely there's a better way?
Thanks for any help :)
jjhartma replied on Tuesday, November 17, 2009
http://forums.lhotka.net/forums/thread/36467.aspx
That thread links a blog post talking about replacing the PropertyInfoFactory and therefore allowing you to use your own PropertyInfo based class.
Pawz.777 replied on Tuesday, November 17, 2009
jjhartma - I took a closer look at the sample from Jasonbock.net, but it doesn't quite handle the scenario I'm talking about here. It changes the internal FieldData structure without changing the signature of the PropertyInfo, whereas I'm looking for a way to insert data into the PropertyInfo in its declaration.
sergeyb - After fiddling for a while trying to convert from object to PropertyInfo<T> I finally figured out I needed to create a new interface to convert the PropertyInfo<T> object (from FieldManager.GetRegisteredProperties()) to my new interface type. I also had to modify the RegisterProperty function slightly:
private static readonly PropertyInfo<string> AssignedProgrammerProperty =
RegisterProperty(new CsPropertyInfo<string>("AssignedProgrammer", "AssignedProgrammer"));
And now I've got it working!
Thanks for pointing me down the right track :)
Copyright (c) Marimer LLC