I have my own data types for use with a database that have various properties to manipulate values such as:
First: original value
IsNull: is the current state null (no value in Data)
IsFirstNull: was the initial state of the object null
Changed: has the value changed since the initial value was set.
SetNull(): set the object to null
SetFirstNull: set the initial value to null
Reset: set values all to original settings.
Each one of the objects has these. There is an object for each type of standard variables, such as:
int - IntType
string - StringType
bool - BoolType
I set up these types to handle the different states of each variable I read from a table as well as handle nulls. It was always hard to tell whether a value was null or not or whether it was null when the value was originally read so I would know how to write it back or whether the value was changed. Sometimes you need to know what the original value was when you read the data from the table.
So I only use these for data I have read from my tables, this is so I can keep track of values, including nulls, that I got originally and track changes as well as reset to original values.
I want to be able to access the data via properties, so I have it set up like:
To access the data, I could do something like
loginDto.UserName
But to access (set or get) the IsNull property, I can't really use a property for each variable.
I could set up a method:
SetNull()
but not sure how I would access the variable to change the IsNull property of each variable.
How would I pass a literal ( i.e. SetNull("loginID") or SetNull("userName")) such that the method would know which variable to set?
Or is there a better way to do this?
Thanks,
Tom
First: original value
IsNull: is the current state null (no value in Data)
IsFirstNull: was the initial state of the object null
Changed: has the value changed since the initial value was set.
SetNull(): set the object to null
SetFirstNull: set the initial value to null
Reset: set values all to original settings.
Each one of the objects has these. There is an object for each type of standard variables, such as:
int - IntType
string - StringType
bool - BoolType
I set up these types to handle the different states of each variable I read from a table as well as handle nulls. It was always hard to tell whether a value was null or not or whether it was null when the value was originally read so I would know how to write it back or whether the value was changed. Sometimes you need to know what the original value was when you read the data from the table.
So I only use these for data I have read from my tables, this is so I can keep track of values, including nulls, that I got originally and track changes as well as reset to original values.
I want to be able to access the data via properties, so I have it set up like:
Code:
public class LoginDTO
{
public IntType loginID = new IntType();
public StringType userName = new StringType();
#region Properties
public object LoginID
{
get
{
object value = null;
return NullHandler.SetDbObjectValueFromValue(loginID, ref value);
}
set
{
NullHandler.GetValueFromDbObject(value, ref loginID);
}
}
public object UserName
{
get
{
object value = null;
return NullHandler.SetDbObjectValueFromValue(userName, ref value);
}
set
{
NullHandler.GetValueFromDbObject(value, ref userName);
}
}
To access the data, I could do something like
loginDto.UserName
But to access (set or get) the IsNull property, I can't really use a property for each variable.
I could set up a method:
SetNull()
but not sure how I would access the variable to change the IsNull property of each variable.
How would I pass a literal ( i.e. SetNull("loginID") or SetNull("userName")) such that the method would know which variable to set?
Or is there a better way to do this?
Thanks,
Tom