public static bool SomeCommonRule<T>(...) where T : SmartDate won't work

public static bool SomeCommonRule<T>(...) where T : SmartDate won't work

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


david.wendelken posted on Monday, April 30, 2007

 

I tried to set up a new common rule where the <T> had to be a SmartDate.

The compiler refused.  Basically, it wouldn't take a struct.  It suggested an Interface.

But, the methods that I wanted were either the constructors or the static parse routines, neither of which are allowed in Interfaces.  :(

Any clues?

 

xal replied on Monday, April 30, 2007

What's the point of <T> if you require that it's a smartdate??
Assuming your method is something like:

public static bool SomeCommonRule(SmartDate d)

Now, if it's a business rule for csla, you need to explain what exactly you want to validate.

Perhaps you want to validate a bo that has a smart date??
In that case, is it rule that applies to only one bo? or a "generic" rule (not in the "<T>" compiler meaning, but in the traditional sense) that could validate different BO types?


Andrés

david.wendelken replied on Tuesday, May 01, 2007

xal:
What's the point of <T> if you require that it's a smartdate??
Assuming your method is something like:

public static bool SomeCommonRule(SmartDate d)

Now, if it's a business rule for csla, you need to explain what exactly you want to validate.

Perhaps you want to validate a bo that has a smart date??
In that case, is it rule that applies to only one bo? or a "generic" rule (not in the "<T>" compiler meaning, but in the traditional sense) that could validate different BO types?


Andrés

I've greatly simplified my example just to find a way past the compiler rules...

The actual rule we are coding is a common rule to handle Min-Max situations, such as StartDate must not be after EndDate. 

The public properties that have values will be strings, but the corresponding private variables will be SmartDates, SmartInt16s, SmartFloats, Int32, Decimal, DateTime, etc.   That means the input property values must be converted to the appropriate data type.  I was trying to write several different, relatively simple versions of the MinMax rule, each one keyed to a specific datatype, hoping that the compiler would be able to figure out which one to call.

I think I'll just have to add a parameter to the rule, which willl be called ComparisonDatatype, and write the appropriate if statements. :(

William replied on Tuesday, May 01, 2007

The "where" clause implements to constraint "is a" relationship (i.e. inheritance). Structure in C# does not support inheritance. Thus, it is an invalid candidate for "where" clause.

Regards,
William

Copyright (c) Marimer LLC