I'm not sure if that's what you were asking for, but if you need a type's name, use
//short class name
typeof(T).Name
//full name with namespace
typeof(T).FullName
//namespace only
typeof(T).Namespace
typeof(T)
is resolved at compilation, but if you want to get it dynamically at runtime, use object.GetType()
for that.
EDIT
Ok, I see some mistakes in your code:
public void SetColumnName(string columnName)
{
this._columnName = _columnName;
}
should be
public void SetColumnName(string columnName)
{
this._columnName = columnName;
}
same with
this._dataTypes = _dataTypes;
which should be
this._dataTypes = dataTypes;
basically you were reassigning the same values in those methods, ignoring objects sent as parameter. And this will definately won't work:
public void SetDataType(string type)
{
try
{
SetDataType(type != null ? typeof (Type) : typeof (string));
}
I'm not sure what are you trying to achieve here, but typeof(Type)
is Type
, which I doubt you intended to use. Also, typeof(string)
will return the type of string class, not the object send in parameter. typeof(type)
(an object sent in parameter) will also return you a string type, because that's the parameter type. Try to avoid confusing names, that are similar to keywords, especially when moving from Java to C#, because standard naming convention can trick you out.