FieldManager Errors

FieldManager Errors

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


AndrewBurns posted on Thursday, March 19, 2009

I have a rather strange issue that I am not sure how it is occurring.

I am running 3.6.1 and all of the sudden the FieldManager is returning incorrect FieldData instances.

Has anyone else experienced anything like this? If I am able to isolate it then I will write a test and patch it.

Andrew

AndrewBurns replied on Thursday, March 19, 2009

OK long story short, PEBKAC.

Turns out I was registering the property on the wrong type and I am using a custom property loader that requires the class type to be correct otherwise I probably wouldn't have noticed.

To help prevent this in the future and to clean up property registrations I wrote some methods on my BusinessBase class that could easily be put on Csla.BusinessBase:


protected static PropertyInfo

RegisterProperty

(PropertyInfo

info)
{
Type objectType = typeof(T);
return RegisterProperty

(objectType, info);
}


protected static PropertyInfo

RegisterProperty

(string name)
{
PropertyInfo

info = new PropertyInfo

(name);
return RegisterProperty(info);
}


protected static PropertyInfo

RegisterProperty

(string name, string friendlyName)
{
PropertyInfo

info = new PropertyInfo

(name, friendlyName);
return RegisterProperty(info);
}


protected static PropertyInfo

RegisterProperty

(string name, P defaultValue)
{
PropertyInfo

info = new PropertyInfo

(name, "", defaultValue);
return RegisterProperty(info);
}


protected static PropertyInfo

RegisterProperty

(string name, string friendlyName, P defaultValue)
{
PropertyInfo

info = new PropertyInfo

(name, friendlyName, defaultValue);
return RegisterProperty(info);
}

RockfordLhotka replied on Thursday, March 19, 2009

3.6.2 throws an exception if you attempt to register a property for a type that's already been used.

That's about as far as I can go, because it is totally legal to register properties for one class from within another class (there's a thread about this that's active right now actually).

In all cases (except CriteriaBase and CslaIdentity subclasses) I recommend people use the proper overload of RegisterProperty() - that doesn't accept the object type:

RegisterProperty<string>(c => c.Name);

or

RegisterProperty<string>(new PropertyInfo<string>("Name"));

Skip the typeof() parameter and let the compiler do the work for you to make sure the right type is being used.

Copyright (c) Marimer LLC