CommonBusinessRule -> MinValue<T> Rule (CSLA 4.0)

CommonBusinessRule -> MinValue<T> Rule (CSLA 4.0)

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


rxelizondo posted on Sunday, June 06, 2010

 

Hello.

I was just looking at the MinValue<T> rule implementation and I wanted to bring up some minor issues I have with the rule implementation.

--------------------------------------------------

1)  The documentation for the “IComparable” interface *return* value states the following: A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance is less than obj. Zero This instance is equal to obj. Greater than zero This instance is greater than obj.

I underlined the text that I wanted to bring up to your attention. On the rule implementation we compare for “result <= -1” when I think we should really be comparing for “result < 0” right?

*** EDIT: I am such a big IDIOT, IComparable->CompareTo() returns an Integer so there will never be the case where the CopareTo will return something like a 0.5 so the current implementation i s100% fine..... I tell you, sometimes I wonder if the thing above my shoulder is my head or my @ss Embarrassed

--------------------------------------------------

2)  The other thing that I wanted to bring up is that we totally ignore the possibility of the value contained for the “PrimaryProperty” being “null”. Personally, I think that if the “PrimaryProperty” value is null, then the rule should pass and not throw an NullReferenceException when we execute the “value.CompareTo(Min)” code.

If we don’t want to deal with nulls, then perhaps we should add another constraint to the rule class of “struct” to formalize our intentions of not being able to deal with null such as:

public class MinValue<T> : CommonBusinessRule where T : struct, IComparable

--------------------------------------------------

3)  The constructor for the rule class calls for a parameter of type “Csla.Core.IPropertyInfo”, is there any particular reason why the parameter can’t be generic such as “Csla.Core.IPropertyInfo<T>”?

Would there be a problem with creating a “Csla.Core.IPropertyInfo<T>” that inherits from “Csla.Core.IPropertyInfo” and have the generic “IPropertyInfo<T>” as the base class for all “PropertyInfo” implementations? Using the generic parameter will completely eliminate possible runtime cast exceptions when we do the following cast on the "Execute" method:

T value = (T)context.InputPropertyValues[PrimaryProperty];

The constructor can look like the example below, note that PropertyInfo has a value of type T as does the min paramter.

public MinValue(Csla.Core.IPropertyInfo<T> primaryProperty, T min)

--------------------------------------------------

4)  I know it's silly but I felt that in the old CSLA the "RuleName" concatenated the "EventArgs" parameters using proper casing. So in the case of the "MinValue" rule, I would have expected for the AddQueryParameterto() to use "Min" instead of "min" as:

this.RuleUri.AddQueryParameter("Min", min.ToString());

I know I can use whatever I want, but is there any relevant reason why not using the actual name of the property which in the case of this rule is "Min" and not "min"?

--------------------------------------------------

5)  The xml documentation for the "min" paramter states:

<param name="min">Min length value.</param>

I think it should be:

<param name="min">Min value.</param>

--------------------------------------------------

Assuming that anything that I have said makes any sense, then other rules should also be updated but no point on mentioning them if my points don’t have any real value.

--------------------------------------------------

Thank you.

 

rxelizondo replied on Sunday, June 06, 2010

Moved to: http://forums.lhotka.net/forums/t/9046.aspx

 

rxelizondo replied on Tuesday, June 08, 2010

I have decided to delete this post because it may contain questions that have obvious answers if I just take some time to research rather than just jump into asking.

Unfortunately, I can’t seem to find the “Delete/Remove” button anywhere. As usual, I am sure that deleting a post is straight forward but for some reason I am not able to find a way to do it.

Adim, can you please delete this post as well as the http://forums.lhotka.net/forums/t/9046.aspx  one?

Thank you.

Copyright (c) Marimer LLC