I would like to build a custom Int struct that inheriets from Int, so that I can pass everything through but override the toString method.
What I have done in the pass...
I use customer business objects to store several ints and datetimes,
When loading these objects if the database returns null I would set the int = int.MinValue
On the GUI side when assigning the int to a textbox I would write a line like
textbox1.Text = (myObj.CustomerCount == int.MinValue) ? "" : myObj.CustomerCount.ToString();
It is the line above that I would like to but in a customer Int Struct so the users can just type
textbox1.Text = myObj.CustomerCount.ToString();
and it will do the type check in the overrided method.
I know you can not inherit from Int (or Int32) so this is where I am stuck. I would appreciate any help or steering in a better direction
I have done this in the past for a "unboundless" array where I inherit from ICollection
and then have
and
Thanks in advance.
What I have done in the pass...
I use customer business objects to store several ints and datetimes,
When loading these objects if the database returns null I would set the int = int.MinValue
On the GUI side when assigning the int to a textbox I would write a line like
textbox1.Text = (myObj.CustomerCount == int.MinValue) ? "" : myObj.CustomerCount.ToString();
It is the line above that I would like to but in a customer Int Struct so the users can just type
textbox1.Text = myObj.CustomerCount.ToString();
and it will do the type check in the overrided method.
I know you can not inherit from Int (or Int32) so this is where I am stuck. I would appreciate any help or steering in a better direction
I have done this in the past for a "unboundless" array where I inherit from ICollection
and then have
Code:
public string this[int index]
{
get
{
if(index > _arrayList.Count-1)
{
return null;
}
else
{
return _arrayList[index].ToString() == "" ? null : _arrayList[index].ToString();
}
}
}
Code:
public static DateTime ConvertToDate(string field)
{
if (field != null && field.Length == 8)
return DateTime.Parse(field.Substring(0, 4) + "/" + field.ToString().Substring(4, 2) + "/" + field.Substring(6, 2));
else
{
return new DateTime();
}
}
Thanks in advance.