T
tshad
I am trying to add values to a property in my class dynamically.
In my problem, I would have something like:
string value = "somevalue"
string name = "ColumnName"
or
string name = "ColumnType"
I have a class that has ColumnName and ColumnType as properties (there are
many more but this is just an illustration).
I don't want to create a big switch statement or a bunch of "if" statements
that in essence say:
if (name == "ColumnName")
tableColumnName.ColumnName = value
if (name == 'ColumnType")
tableColumnName.ColumnType = value
Is there a way using the column names in the name field to dynamically move
the data into the correct property? Something like:
tableColumnName.??? = value
where ??? would somehow use the "name" field
My class is:
**********************************************
using System;
using System.Collections.Generic;
using System.Text;
namespace RepositoryServiceApp.BusinessLayer
{
public class TableColumnName
{
private string mstrTableName;
private string mstrColumnName;
private string mstrColumnType;
public string ColumnType
{
get { return mstrColumnType; }
set { mstrColumnType = value; }
}
public string ColumnName
{
get { return mstrColumnName; }
set { mstrColumnName = value; }
}
public string TableName
{
get { return mstrTableName; }
set { mstrTableName = value; }
}
public new string ToString()
{
return TableName + " / " + ColumnName + " / " + ColumnType;
}
}
public class TableColumnNameCollection : List<TableColumnName> { }
}
*******************************************************
Thanks,
Tom
In my problem, I would have something like:
string value = "somevalue"
string name = "ColumnName"
or
string name = "ColumnType"
I have a class that has ColumnName and ColumnType as properties (there are
many more but this is just an illustration).
I don't want to create a big switch statement or a bunch of "if" statements
that in essence say:
if (name == "ColumnName")
tableColumnName.ColumnName = value
if (name == 'ColumnType")
tableColumnName.ColumnType = value
Is there a way using the column names in the name field to dynamically move
the data into the correct property? Something like:
tableColumnName.??? = value
where ??? would somehow use the "name" field
My class is:
**********************************************
using System;
using System.Collections.Generic;
using System.Text;
namespace RepositoryServiceApp.BusinessLayer
{
public class TableColumnName
{
private string mstrTableName;
private string mstrColumnName;
private string mstrColumnType;
public string ColumnType
{
get { return mstrColumnType; }
set { mstrColumnType = value; }
}
public string ColumnName
{
get { return mstrColumnName; }
set { mstrColumnName = value; }
}
public string TableName
{
get { return mstrTableName; }
set { mstrTableName = value; }
}
public new string ToString()
{
return TableName + " / " + ColumnName + " / " + ColumnType;
}
}
public class TableColumnNameCollection : List<TableColumnName> { }
}
*******************************************************
Thanks,
Tom