For Example: Fields, other than strings, will generally have data come into a class as a string or the fields native datatype:
private string _StockNumber = null;
private decimal _Quantity = 0.00M;
// StockNumber
// string data is safe as a Property( assuming it doesn't enter your system as a number. )
public string StockNumber
{
get { return _StockNumber; }
set { _StockNumber = value; }
}
// Quantity
public decimal GetQuantity()
{
return( _Quantity );
}
// Here's our standard method for sending decimal data to a decimal field
public void SetQuantity( decimal Quantity )
{
_Quantity = Quantity;
} // Here's our overloaded method to PARSE string data.
public void SetQuantity( string Quantity )
{
try
{
decimal tempQuant = decimal.Parse( Quantity );
_Quantity = tempQuant;
}
catch( ArgumentNullException ane )
{ // caught Null value
// build a decimal value of zero? and accept? Up to You.
string sMsg = ane.Message;
throw new xQuantityException( sMsg );
}
catch( FormatException fe )
{ // caught Non-Numeric data
string sMsg = fe.Message;
throw new xQuantityException( sMsg );
}
catch( OverflowException oe )
{ // number too large or too small
string sMsg = oe.Message;
throw new xQuantityException( sMsg );
}
} - Intellisense will show overloaded methods: decimal SetQuantity( decimal )
decimal SetQuantity( string )
- Hybrid Coding Quantity as a property and a SetQuantity() method would lead to programmers MISSING the SetQuantity() method when viewing Intellisense.
|