3
I am creating a project in which I search the database information, in this case it is a DBF file, and the field is of the Logical type. However, I want to create a property that can receive a variable (either int, string or bool) and save to the bool private variable.
I already have methods that receive int (0/1) and transform into (True/False) and that receive string (T/F | V/F | S/N) and transform into (True/False). But I would like to do the treatment when "setando" the value of the field.
I tried to create 3 properties with each type of data, but when I use it says that there is more than one property with the same name. (Which would be in that 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’s 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, string and Bool. Is there any way to do this?
Edit: The result would be this way?
Class DBPort
{
private bool vip;
public LogicalValue Vip
{
get { return vip; }
set { vip = value.Value; }
}
public DBPort()
{
Vip = false;
}
}
That way it doesn’t work?
– Marco Souza