2014-09-22 38 views
-1

我有像下面的代码。它使用读取用户输入作为表名,然后获取输入的类属性信息库作为类类型。问题是typeof(tableName)不正确。任何人都可以帮助我,非常感谢。如何获取用户输入作为类的类型?

void Main() 
{ 
    var tableName = Console.ReadLine(); 

    var propertyInfo = this.GetTableProperties(tableName); 
} 

public PropertyInfo[] GetTableProperties(string tableName) 
{ 
    PropertyInfo[] props = typeof(tableName).GetProperties(); 
    return props; 
} 
+0

什么是'tableName',是一个自定义类的完全限定命名空间? – Sayse 2014-09-22 13:59:06

回答

0

Type.GetType可以提供一种基于字符串类型,但需要完全合格的名称:

Type t = Type.GetType("Fully.Qualified.Type.Name.Here"); 
+1

如果type在当前程序集或mscorlib之外,则需要'Assembly.Qualified.Type.Name.There' – 2014-09-22 14:00:13