I'm new in C# and I need some hints to solve this problem: I start to develop an application in C# an Windows Form Application (until this summer, I work 20 years in Visual Fox) The UI is generic (has an grid and controls for show details for current record), and is build dynamic from definitions I stored in an Xml File.
I want to create a class for each table I use for create methods for getting default values, validate fields, and record, etc). I use for this classes a namespace: BmiSqlTables.
Now I need in UI on adding record to get default values, validate fields, etc. The problem i have is to replace switch case statements which can became a very large one (for 50 tables) with something using substitution like in Foxpro
private void GetDefaultValue ( string TableName, string fieldName)
{
switch (tableName)
{
case "person":
BmiSqlTables.Person.GetDefaulValue( fieldName, valueType);
break;
case "client":
BmiSqlTables.Client.GetDefaulValue( fieldName, valueType);
break;
default:
break
}
}
namespace BmiSqlTables
{
public static class Person
{
public static dynamic GetDefaultValue( string fieldName, string valueType)
{
dynamic defaultValue = null;
switch (fieldName.toLower())
{
case "field1":
case "field2":
default:
switch (valueType.ToLower())
{
case "string":
case "varchar":
case "char:"
return "";
case "int":
return 0;
default:
return null;
}
.......
}
}
}
}
In Foxpro the GetDefaultValue can be something like this:
Function GetDefaultValue( tableName, fieldName, valueType)
return BmiSqlTable.&tableName..GetDefaultValue( fieldName, valueType)
Any advice to this problem (and project) will be apreciate. Hope you understand my english, and what I need to do. Thanks in advance.