RegisterProperty overloads?RegisterProperty overloads?
Old forum URL: forums.lhotka.net/forums/t/8165.aspx
Cine posted on Tuesday, December 15, 2009
Is there any particular reason why I am required to specify the type of the parameter to RegisterProperty?
private static readonly PropertyInfo<int> IdProperty = RegisterProperty<int>(c => c.Id);
It is due to the implementation in BusinessBase is
protected static PropertyInfo<P> RegisterProperty<P>(Expression<Func<T, object>> propertyLambdaExpression)
IE, the func return value is object.
However, with just a simple overload to this function, we can avoid having to specify this type one more time.
protected static PropertyInfo<P> RegisterProperty<P>(Expression<Func<T, P>> propertyLambdaExpression)
{
PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
return RegisterProperty(new PropertyInfo<P>(reflectedPropertyInfo.Name));
}
Now I just have to write
private static readonly PropertyInfo<int> IdProperty = RegisterProperty(c => c.Id);
RockfordLhotka replied on Tuesday, December 15, 2009
I think we tried that, but the overload is ambiguous in some other uses of RegisterProperty().
Maybe I'm not remembering correctly - have you tried running the unit tests with your overload in place?
rxelizondo replied on Tuesday, December 15, 2009
Cine: Is there any particular reason why I am required to specify the type of the parameter to RegisterProperty?
private static readonly PropertyInfo IdProperty = RegisterProperty(c => c.Id);
I think you pretty much nailed right in the butt. There is no way for the compiler to resolve the Type for {P} when it is never given any clue on what {P} may be. Its pretty much as declaring a method like:
void DoIt{Z}()
{
}
If you try to call DoIt() from anywhere in the code, the compiler wont have a clue what {Z} is because you never gave it anything to work from. You will be forced to have the call include the type such as:
void DoIt{int}()
Copyright (c) Marimer LLC