I'm creating a project where I look for the database information, in this case it's a DBF file, and the field is a Logical type. However I want to create a property that can receive a variable (either int, string or bool) and write to the private variable bool.
I already have methods that get int (0/1) and transform into (True / False) and receive string (T / F | V / F | S / N) and transforms into (True / False). But I'd like to do the treatment when setting the value of the field.
I tried to create 3 properties with each data type, but when I use it it says there is more than one property with the same name. (Which would be in this case).
public override int Vip
{
get { return clsGeneric.convertFromBool(vip); }
set { vip = clsGeneric.convertToBool(value); }
}
public override string Vip
{
get { return clsGeneric.convertFromBool(vip,clsGeneric.TypeRetBool.TF); }
set { vip = clsGeneric.convertToBool(value); }
}
public override bool Vip
{
get { return vip; }
set { vip = value; }
}
And now it looks like this:
public override TipoGenérico Vip
{
get { return vip; }
set
{
if (value.GetType() == typeof(string))
{
vip = clsGeneric.convertToBool((string)value);
}
else if (value.GetType() == typeof(int))
{
vip = clsGeneric.convertToBool(value);
} else {
vip = value;
}
}
}
I wanted to make the property accept both Int, and string and Bool. Is there any way to do this?
Edit: Would the result look like this?
Class DBPort
{
private bool vip;
public LogicalValue Vip
{
get { return vip; }
set { vip = value.Value; }
}
public DBPort()
{
Vip = false;
}
}