SmartInt16, SmartInt32, SmartInt64, SmartBool and SrdSafeDataReader Available

SmartInt16, SmartInt32, SmartInt64, SmartBool and SrdSafeDataReader Available

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


david.wendelken posted on Saturday, November 04, 2006

I added the above c# classes to the CSLA Contrib project.

They are designed to be in a separate DLL but could be easily modified to fit inside the CSLA project by a global search and replace on the NameSpace names.

The "Smart" classes mimic SmartDate for their respective data types.

The SrdSafeDataReader extends SafeDataReader and recognizes the additional "Smart" classes.

Please pass on any suggestions for improvements, I'm still learning the nuances of C#.

Enjoy!

david.wendelken replied on Sunday, November 12, 2006

Renamed SrdSafeDataReader to SmartSafeDataReader and loaded it up to CSLA Contrib, along with other features dealing with validation rules.

mtavares replied on Wednesday, November 15, 2006

Hi David,

Just took a look at the code for the SmartBool, and seems like the code can only make the assumption that it is empty when it is set to either true (EmptyIsMax) or false (EmptyIsMin).  Shouldn't there be some way to represent it in a tri-state mechanism, sort of like a nullable(of boolean).  There will be times when I want to distinguish between something that is true or false and something that is empty, and it seems like right now that class cannot distinguish that. Because if I have EmptyIsMin set and then actually set my value of the property to false, then the DBValue equivalent is going to return DBNull, and not false. (Unless of course i'm not reading the code properly).  Just an observation, so let me know if i'm off base in my logic.

david.wendelken replied on Wednesday, November 15, 2006

mtavares:

Hi David,

Just took a look at the code for the SmartBool, and seems like the code can only make the assumption that it is empty when it is set to either true (EmptyIsMax) or false (EmptyIsMin).  Shouldn't there be some way to represent it in a tri-state mechanism, sort of like a nullable(of boolean).  There will be times when I want to distinguish between something that is true or false and something that is empty, and it seems like right now that class cannot distinguish that. Because if I have EmptyIsMin set and then actually set my value of the property to false, then the DBValue equivalent is going to return DBNull, and not false. (Unless of course i'm not reading the code properly).  Just an observation, so let me know if i'm off base in my logic.

The SmartBool class was cloned from the SmartDate class and should (mistakes on my part excluded) handle this type of situation exactly like SmartDate would.

I'll take a look and see if I broke something and didn't catch it.

david.wendelken replied on Wednesday, November 15, 2006

Yep, I broke something in SmartBool.

Will get the fix up within the next few days.

david.wendelken replied on Thursday, November 16, 2006

I made a copy of SmartDate and turned it into SmartBool with a rather mindless clone and edit process, much as I did the SmartInt series.

But the fact that the datatype for the Smart class contents and the datatype for the min/max indicator are the same datatype actually requires a somewhat different concept than SmartDate and SmartInt.

SmartDate has many constructors, some accept no values, some accept just a date value, some accept just the min/max indicator, and some accept both types.

SmartBool cannot do that, as the compiler cannot tell the difference between:

  1. public SmartBool (bool value)
  2. public SmartBool(bool emptyIsMin)

If I pick option two above, then option 1 below becomes conceptually different from the other Smart class behaviors.

  1. public SmartBool(string value)
  2. public SmartBool(string value, bool emptyIsMin)

So, upon further reflection, I'm actually unsure what to do.

Suggestions?

david.wendelken replied on Monday, November 27, 2006

mtavares:

Hi David,

Just took a look at the code for the SmartBool, and seems like the code can only make the assumption that it is empty when it is set to either true (EmptyIsMax) or false (EmptyIsMin).  Shouldn't there be some way to represent it in a tri-state mechanism, sort of like a nullable(of boolean).  There will be times when I want to distinguish between something that is true or false and something that is empty, and it seems like right now that class cannot distinguish that. Because if I have EmptyIsMin set and then actually set my value of the property to false, then the DBValue equivalent is going to return DBNull, and not false. (Unless of course i'm not reading the code properly).  Just an observation, so let me know if i'm off base in my logic.

Take a look at SmartBool again, I believe it is better structured now.

owensig replied on Monday, November 27, 2006

In my opinion these classes should really be called CslaXXX class names.  Rocky's SmartDate should also be renamed to CslaDate.  SmartDate should be depricated. 

david.wendelken replied on Tuesday, November 28, 2006

I named them to match SmartDate to reduce confusion.  Any Csla programmer should automatically know what they do just by their name.  Until Rocky changes SmartDate to CslaDate, I don't see any gain in doing so.

PS - quite a few programmers seem unable to remember "csla".

mtavares replied on Tuesday, November 28, 2006

I took a look at it again, and made a few changes. I'm not a C# guy, and haven't tried a recompile so there may be some syntax issues, i'm not sure.  I think the text property should be used to determine whether the value is null or not, so what I did was reset the _initialized field in the StringToBool and BoolToString methods.  Also, I don't think that the getter for the Bool property should reset the _initialized field, just the setter.  This way it can still return false (or true is emptyIsMax), but the actual internal value can still keep track of the difference between false-empty and false-false.  And since I'll be using the text property to setup my BO's property, making the text an empty string should force the internal handling to set itself to empty.  Finally, as a note, I noticed that the SmartBool isn't being handled by your SmartSafeDataReader class.  Hope this helps.  Here's the code:

using System;

using CslaSrd;

using CslaSrd.Properties;

namespace CslaSrd

{

/// <summary>

/// Provides an boolean data type that understands the concept

/// of an empty value.

/// </summary>

/// <remarks>

/// See Chapter 5 for a full discussion of the need for a similar

/// data type and the design choices behind it. Basically, we are

/// using the same approach to handle booleans instead of dates.

///

/// However, there are a few differences in behavior and interface from SmartDate, SmartInt16, etc.

///

/// Major Difference One: More Limited Set of Constructors

///

/// SmartDate (etc.) has a constructor that accepts a primitive of the appropriate underlying datatype, and a separate constructor

/// that is a boolean that sets whether an empty object is considered to have a maximum or minimum value. Since the underlying

/// primitive is also a boolean, both of these constructors cannot exist. So, we had to choose. I chose to keep the ability to

/// define how an empty SmartBool is to be compared.

///

/// Major Difference Two: IsEmpty does not return based upon Minimum or Maximum value.

///

/// SmartDate (etc.) compare the internal value with the minimum or maximum possible value to determine whether to return an empty value.

/// Given that a Date or Int have many, many possible values to choose from, this is an acceptable practice. Given that a bool has

/// only two values, it does not work. An internal indicator, _isInitialized, is used to determine the answer instead.

///

/// Possible Major Difference Three: FormatString may be useless.

///

/// It may be just my ignorance of the format capability for booleans built into the .Net framework, but this functionality

/// doesn't appear to be properly supported (in that I did not find any settings that made a difference to the output).

/// I left the capability in place in case others know how to use it, in the hope that they will update this code or send me a message

/// to let me know. :)

/// </remarks>

[Serializable()]

public struct SmartBool : IComparable

{

private const bool _minValue = false;

private const bool _maxValue = true;

private bool _bool;

private bool _initialized;

private bool _emptyIsMax;

private string _format;

#region Constructors

/// <summary>

/// Creates a new, empty SmartBool object.

/// </summary>

/// <remarks>

/// The SmartBool created will have an empty value.

/// It will compare as the minimum or maximum possible value as specified.

/// </remarks>

/// <param name="emptyIsMin">Whether to compare an empty value as the minimum or maximum value.</param>

public SmartBool(bool emptyIsMin)

{

_emptyIsMax = !emptyIsMin;

_format = null;

_initialized = false;

if (_emptyIsMax)

{

_bool = _maxValue;

}

else

{

_bool = _minValue;

}

}

/// <summary>

/// The SmartBool created will use the value supplied. If the object is later set to

/// an empty value, it will compare as the minimum or maximum possible value as specified.

/// </summary>

/// <param name="Value">The initial value of the object.</param>

/// <param name="EmptyIsMin">Indicates whether an empty bool is the min or max bool value.</param>

public SmartBool(bool value, bool emptyIsMin)

{

_emptyIsMax = !emptyIsMin;

_format = null;

_initialized = true;

_bool = value;

}

/// <summary>

/// Creates a new SmartBool object.

/// </summary>

/// <remarks>

/// The SmartBool created will use the min possible

/// bool to represent an empty bool.

/// </remarks>

/// <param name="Value">The initial value of the object (as text).</param>

public SmartBool(string value)

{

_emptyIsMax = false;

_format = null;

_bool = _minValue;

if (value != null)

{

_initialized = true;

this.Text = value;

}

else

{

_initialized = false;

}

}

/// <summary>

/// Creates a new SmartBool object.

/// </summary>

/// <param name="Value">The initial value of the object (as text).</param>

/// <param name="EmptyIsMin">Indicates whether an empty bool is the min or max bool value.</param>

public SmartBool(string value, bool emptyIsMin)

{

_emptyIsMax = !emptyIsMin;

_format = null;

if (_emptyIsMax)

{

_bool = _maxValue;

}

else

{

_bool = _minValue;

}

if (value != null)

{

_initialized = true;

this.Text = value;

}

else

{

_initialized = false;

}

}

#endregion

 

#region Text Support

/// <summary>

/// Gets or sets the format string used to format a bool

/// value when it is returned as text.

/// </summary>

/// <remarks>

/// The format string should follow the requirements for the

/// .NET <see cref="System.String.Format"/> statement.

/// </remarks>

/// <value>A format string.</value>

public string FormatString

{

get

{

if (_format == null)

_format = "d";

return _format;

}

set

{

_format = value;

}

}

/// <summary>

/// Gets or sets the bool value.

/// </summary>

/// <remarks>

/// <para>

/// This property can be used to set the bool value by passing a

/// text representation of the bool. Any text bool representation

/// that can be parsed by the .NET runtime is valid.

/// </para><para>

/// When the bool value is retrieved via this property, the text

/// is formatted by using the format specified by the

/// <see cref="FormatString" /> property. The default is the

/// short bool format (d).

/// </para>

/// </remarks>

public string Text

{

get { return BoolToString(this.Bool, FormatString, !_emptyIsMax); }

set { this.Bool = StringToBool(value, !_emptyIsMax); }

}

#endregion

#region Bool Support

/// <summary>

/// Gets or sets the bool value.

/// </summary>

public bool Bool

{

get

{

if (!_initialized)

{

if (_emptyIsMax)

{

_bool = _maxValue;

}

else

{

_bool = _minValue;

}

}

return _bool;

}

set

{

_bool = value;

_initialized = true;

}

}

#endregion

#region System.Object overrides

/// <summary>

/// Returns a text representation of the bool value.

/// </summary>

public override string ToString()

{

return this.Text;

}

/// <summary>

/// Compares this object to another <see cref="SmartBool"/>

/// for equality.

/// </summary>

public override bool Equals(object obj)

{

if (obj is SmartBool)

{

SmartBool tmp = (SmartBool)obj;

if (this.IsEmpty && tmp.IsEmpty)

return true;

else

return this.Bool.Equals(tmp.Bool);

}

else if (obj is bool)

return this.Bool.Equals((bool)obj);

else if (obj is string)

return (this.CompareTo(obj.ToString()) == 0);

else

return false;

}

/// <summary>

/// Returns a hash code for this object.

/// </summary>

public override int GetHashCode()

{

return this.Bool.GetHashCode();

}

#endregion

#region DBValue

/// <summary>

/// Gets a database-friendly version of the bool value.

/// </summary>

/// <remarks>

/// <para>

/// If the SmartBool contains an empty bool, this returns <see cref="DBNull"/>.

/// Otherwise the actual bool value is returned as type Bool.

/// </para><para>

/// This property is very useful when setting parameter values for

/// a Command object, since it automatically stores null values into

/// the database for empty bool values.

/// </para><para>

/// When you also use the SafeDataReader and its GetSmartBool method,

/// you can easily read a null value from the database back into a

/// SmartBool object so it remains considered as an empty bool value.

/// </para>

/// </remarks>

public object DBValue

{

get

{

if (this.IsEmpty)

return DBNull.Value;

else

return this.Bool;

}

}

#endregion

#region Empty Bools

/// <summary>

/// Gets a value indicating whether this object contains an empty bool.

/// </summary>

public bool IsEmpty

{

get

{

return !_initialized;

}

}

/// <summary>

/// Gets a value indicating whether an empty bool is the

/// min or max possible bool value.

/// </summary>

/// <remarks>

/// Whether an empty bool is considered to be the smallest or largest possible

/// bool is only important for comparison operations. This allows you to

/// compare an empty bool with a real bool and get a meaningful result.

/// </remarks>

public bool EmptyIsMin

{

get { return !_emptyIsMax; }

}

#endregion

#region Conversion Functions

/// <summary>

/// Converts a string value into a SmartBool.

/// </summary>

/// <param name="value">String containing the bool value.</param>

/// <returns>A new SmartBool containing the bool value.</returns>

/// <remarks>

/// EmptyIsMin will default to <see langword="true"/>.

/// </remarks>

public static SmartBool Parse(string value)

{

return new SmartBool(value);

}

/// <summary>

/// Converts a string value into a SmartBool.

/// </summary>

/// <param name="value">String containing the bool value.</param>

/// <param name="emptyIsMin">Indicates whether an empty bool is the min or max bool value.</param>

/// <returns>A new SmartBool containing the bool value.</returns>

public static SmartBool Parse(string value, bool emptyIsMin)

{

return new SmartBool(value, emptyIsMin);

}

/// <summary>

/// Converts a text bool representation into a Bool value.

/// </summary>

/// <remarks>

/// An empty string is assumed to represent an empty bool. An empty bool

/// is returned as the MinValue of the Bool datatype.

/// </remarks>

/// <param name="Value">The text representation of the bool.</param>

/// <returns>A Bool value.</returns>

public static bool StringToBool(string value)

{

return StringToBool(value, true);

}

/// <summary>

/// Converts a text bool representation into a Bool value.

/// </summary>

/// <remarks>

/// An empty string is assumed to represent an empty bool. An empty bool

/// is returned as the MinValue or MaxValue of the Bool datatype depending

/// on the EmptyIsMin parameter.

/// </remarks>

/// <param name="Value">The text representation of the bool.</param>

/// <param name="EmptyIsMin">Indicates whether an empty bool is the min or max bool value.</param>

/// <returns>A Bool value.</returns>

public static bool StringToBool(string value, bool emptyIsMin)

{

bool tmp;

if (String.IsNullOrEmpty(value))

{

_initialized = false;

if (emptyIsMin)

return _minValue;

else

return _maxValue;

}

else if (bool.TryParse(value, out tmp))

{

_initialized = true;

return tmp;

}

else

{

string lint = value.Trim().ToLower();

throw new ArgumentException(Resources.StringToBoolException);

}

}

/// <summary>

/// Converts a bool value into a text representation.

/// </summary>

/// <remarks>

/// The bool is considered empty if it matches the min value for

/// the Bool datatype. If the bool is empty, this

/// method returns an empty string. Otherwise it returns the bool

/// value formatted based on the FormatString parameter.

/// </remarks>

/// <param name="Value">The bool value to convert.</param>

/// <param name="FormatString">The format string used to format the bool into text.</param>

/// <returns>Text representation of the bool value.</returns>

public static string BoolToString(bool value, string formatString)

{

return BoolToString(value, formatString, true);

}

/// <summary>

/// Converts a bool value into a text representation.

/// </summary>

/// <remarks>

/// Whether the bool value is considered empty is determined by

/// the EmptyIsMin parameter value. If the bool is empty, this

/// method returns an empty string. Otherwise it returns the bool

/// value formatted based on the FormatString parameter.

/// </remarks>

/// <param name="Value">The bool value to convert.</param>

/// <param name="FormatString">The format string used to format the bool into text.</param>

/// <param name="EmptyIsMin">Indicates whether an empty bool is the min or max bool value.</param>

/// <returns>Text representation of the bool value.</returns>

public static string BoolToString(

bool value, string formatString, bool emptyIsMin)

{

if (!_initialized)

return string.Empty;

else

return string.Format("{0:" + formatString + "}", value);

}

#endregion

#region Manipulation Functions

/// <summary>

/// Compares one SmartBool to another.

/// </summary>

/// <remarks>

/// This method works the same as the <see cref="bool.CompareTo"/> method

/// on the Bool type, with the exception that it

/// understands the concept of empty bool values.

/// </remarks>

/// <param name="Value">The bool to which we are being compared.</param>

/// <returns>A value indicating if the comparison bool is less than, equal to or greater than this bool.</returns>

public int CompareTo(SmartBool value)

{

if (this.IsEmpty && value.IsEmpty)

return 0;

else

return _bool.CompareTo(value.Bool);

}

/// <summary>

/// Compares one SmartBool to another.

/// </summary>

/// <remarks>

/// This method works the same as the <see cref="bool.CompareTo"/> method

/// on the Bool type, with the exception that it

/// understands the concept of empty bool values.

/// </remarks>

/// <param name="obj">The bool to which we are being compared.</param>

/// <returns>A value indicating if the comparison bool is less than, equal to or greater than this bool.</returns>

int IComparable.CompareTo(object value)

{

if (value is SmartBool)

return CompareTo((SmartBool)value);

else

throw new ArgumentException(Resources.ValueNotSmartBoolException);

}

/// <summary>

/// Compares a SmartBool to a text bool value.

/// </summary>

/// <param name="value">The bool to which we are being compared.</param>

/// <returns>A value indicating if the comparison bool is less than, equal to or greater than this bool.</returns>

public int CompareTo(string value)

{

return this.Bool.CompareTo(StringToBool(value, !_emptyIsMax));

}

/// <summary>

/// Compares a SmartBool to a bool value.

/// </summary>

/// <param name="value">The bool to which we are being compared.</param>

/// <returns>A value indicating if the comparison bool is less than, equal to or greater than this bool.</returns>

public int CompareTo(bool value)

{

return this.Bool.CompareTo(value);

}

#endregion

#region Operators

public static bool operator ==(SmartBool obj1, SmartBool obj2)

{

return obj1.Equals(obj2);

}

public static bool operator !=(SmartBool obj1, SmartBool obj2)

{

return !obj1.Equals(obj2);

}

public static bool operator ==(SmartBool obj1, bool obj2)

{

return obj1.Equals(obj2);

}

public static bool operator !=(SmartBool obj1, bool obj2)

{

return !obj1.Equals(obj2);

}

public static bool operator ==(SmartBool obj1, string obj2)

{

return obj1.Equals(obj2);

}

public static bool operator !=(SmartBool obj1, string obj2)

{

return !obj1.Equals(obj2);

}

public static bool operator >(SmartBool obj1, SmartBool obj2)

{

return obj1.CompareTo(obj2) > 0;

}

public static bool operator <(SmartBool obj1, SmartBool obj2)

{

return obj1.CompareTo(obj2) < 0;

}

public static bool operator >(SmartBool obj1, bool obj2)

{

return obj1.CompareTo(obj2) > 0;

}

public static bool operator <(SmartBool obj1, bool obj2)

{

return obj1.CompareTo(obj2) < 0;

}

public static bool operator >(SmartBool obj1, string obj2)

{

return obj1.CompareTo(obj2) > 0;

}

public static bool operator <(SmartBool obj1, string obj2)

{

return obj1.CompareTo(obj2) < 0;

}

public static bool operator >=(SmartBool obj1, SmartBool obj2)

{

return obj1.CompareTo(obj2) >= 0;

}

public static bool operator <=(SmartBool obj1, SmartBool obj2)

{

return obj1.CompareTo(obj2) <= 0;

}

public static bool operator >=(SmartBool obj1, bool obj2)

{

return obj1.CompareTo(obj2) >= 0;

}

public static bool operator <=(SmartBool obj1, bool obj2)

{

return obj1.CompareTo(obj2) <= 0;

}

public static bool operator >=(SmartBool obj1, string obj2)

{

return obj1.CompareTo(obj2) >= 0;

}

public static bool operator <=(SmartBool obj1, string obj2)

{

return obj1.CompareTo(obj2) <= 0;

}

#endregion

}

}

david.wendelken replied on Tuesday, November 28, 2006

mtavares:

I think the text property should be used to determine whether the value is null or not, so what I did was reset the _initialized field in the StringToBool and BoolToString methods. 

Remember, I'm trying to have the entire set of Smart... classes act just like SmartDate whenever possible.  That way, the programmers don't have to "learn" them if they've already learned SmartDate's quirks.

Your suggestion is problematic.  Both those routines are static ones in the Smart... series.  (Is that "shared" in VB?)  Basically, you can't access the object's internal variables from the static routine.

That said, I think you are right in not being happy with those routines.  :(

Basically, SmartDate used a "cheat" in some ways.  It assumed that no one would **really** want to use the highest or lowest possible date value as a "real" date, so some of the routines return the min or max values when the object is not initialized.  These static routines use the same trick, but they have to rely upon a match to the min or max values, since the _initialized variable isn't available in the static routines.  The problem is that the min and max values, for a smart boolean, are two of the three possible values!   Given that, there really is no use for these static routines.

I will probably ditch them unless a better idea shows up.

mtavares:

Also, I don't think that the getter for the Bool property should reset the _initialized field, just the setter.  This way it can still return false (or true is emptyIsMax), but the actual internal value can still keep track of the difference between false-empty and false-false. 

I agree, but that would make SmartBool inconsistent with SmartDate in its behavior!  That's why I left it as is.  (I also think that SmartDate should also be returning the max value depending upon the emptyIsMax setting.)  So, in order for it to be consistent with SmartDate, I'm inclined to leave it as it stands.

mtavares:

And since I'll be using the text property to setup my BO's property, making the text an empty string should force the internal handling to set itself to empty. 

The Text property has to be re-written to NOT use BoolToString for the reasons cited above.  I'll make sure this feature works in that manner.

mtavares:

Finally, as a note, I noticed that the SmartBool isn't being handled by your SmartSafeDataReader class. 

Yeah, disabled that when I realized SmartBool was broken.  Thought it best to wait until SmartBool was really ready before activating SmartSafeDataReader support again.

mtavares:

Hope this helps. 

Very Much!!!  Thanks!  This has been a nasty one to do.

The SmartInt classes were easy to do.  (I've been using SmartInt32 for several months and haven't noticed any problems yet.  Of course, I haven't used every single feature in it either.)  I should have a SmartFloat up and running fairly soon.   That should be an easy one!

david.wendelken replied on Tuesday, November 28, 2006

Forgot to add something about SmartDate (and thus the rest of the Smart... series):

If you want to know if a SmartDate is empty, the only true way to know for sure is to check it's IsEmpty property.

So, to check a SmartDate for empty values and take different action based upon that, the right way would be :

if (theSmartDateObject.IsEmpty)
{
   doSomethingIfEmpty();
}
else
{
   doSomethingElseIfNotEmpty();
}

So, the SmartDate Text property does not ever return an empty string even if the date hasn't been initialized yet. It will return the min or max date instead, depending upon the setting of the EmptyIsMin property.  Given that, I'm going to keep the StringToBool and BoolToString functionality as it is, as it matches SmartDate. 

 

mtavares replied on Wednesday, November 29, 2006

david.wendelken:

So, the SmartDate Text property does not ever return an empty string even if the date hasn't been initialized yet. It will return the min or max date instead, depending upon the setting of the EmptyIsMin property.  Given that, I'm going to keep the StringToBool and BoolToString functionality as it is, as it matches SmartDate. 

I don't think that's the case about SmartDate.  I took a look at the DateToString function and it shows the following:

Public Shared Function DateToString( _

ByVal value As Date, ByVal formatString As String, _

ByVal emptyValue As EmptyValue) As String

If emptyValue = SmartDate.EmptyValue.MinDate Then

If value = Date.MinValue Then

Return ""

End If

Else ' maxdate is empty

If value = Date.MaxValue Then

Return ""

End If

End If

Return String.Format("{0:" + formatString + "}", value)

End Function

You can see that it is passing back the empty string when the date is max or min depending upon whether empty is min or empty is max.  And vice versa in the StringToDate function it is taking an empty string and translating it into Min or Max date based on what emptyIsMin is.  So using the Text property would actually allow the user to set an empty date. 

That being said, I understand that you want SmartBool to work like SmartDate, but when you are only dealing with Max and Min being the only 2 values for a boolean, you need make it function a little different.  You need that 3rd internal variable (which you are using) to keep track of when it is empty, not just passing min or max back. The StringToBool and BoolToString functions that I modified would give you that ability to set empty booleans, as well as display empty booleans, whereas, I don't think your versions of those functions would do that.  (At least I don't think so by looking at it.  Honestly, I haven't fully tested it).  I follow what you are saying about them being static methods in the SmartDate class, but I'm just not sure you will be able to make SmartBool just like the other classes. It's tough to replicate the 'Smart' functionality when you are trying to store something with 3 possible values, in a storage type that can only hold 2 possible values.

As far the question regarding the VB versions mentioned earlier, I have converted your classes from C# to VB using Instant VB and they work quite well.  I don't mind sharing them, just let me know.

david.wendelken replied on Sunday, December 03, 2006

mtavares:
david.wendelken:

So, the SmartDate Text property does not ever return an empty string even if the date hasn't been initialized yet. It will return the min or max date instead, depending upon the setting of the EmptyIsMin property.  Given that, I'm going to keep the StringToBool and BoolToString functionality as it is, as it matches SmartDate. 

I don't think that's the case about SmartDate.  I took a look at the DateToString function and it shows the following:

Public Shared Function DateToString( _

...

Agreed.  It returns an empty string when the value is the min or max value.

mtavares:

You can see that it is passing back the empty string when the date is max or min depending upon whether empty is min or empty is max.  And vice versa in the StringToDate function it is taking an empty string and translating it into Min or Max date based on what emptyIsMin is.  So using the Text property would actually allow the user to set an empty date. 

That being said, I understand that you want SmartBool to work like SmartDate, but when you are only dealing with Max and Min being the only 2 values for a boolean, you need make it function a little different.  You need that 3rd internal variable (which you are using) to keep track of when it is empty, not just passing min or max back.

In a C# static function (and I suspect in a VB shared function) there is no 3rd internal variable.  The 3rd internal variable, _initialized, only exists for an instantiated object.  The static function does not reference the instantiated object.  Only the parameters being passed in are useable, not the internal object variables.  I suspect that's true for VB as well. 

Basically, the BoolToString function is worthless as written because you can only ever get two values back.

This is a nasty design problem.  Basically, I think I will just need to strip out some of the standard "Smart..." functionality to start with, then see what I can add back in that would be useful.  I think I'll finish up SmartFloat first.

I would love to put your VB versions of the classes up on CSLA Contrib.  Send me a private email via the forum and I'll send you my email address.

david.wendelken replied on Monday, December 04, 2006

Made the corrections to SmartBool previously discussed.  Plus, added SmartFloat.

Enjoy, and comments/corrections welcome!

mtavares is volunteering to port these classes to VB from C#.

glenntoy replied on Tuesday, November 28, 2006

Just a thought is there a VB.NET version for this one?

Thanks,
Glenn

Copyright (c) Marimer LLC