KISS: StringName 到类
我有两个类 xCustomer
和 xProduct
Case Tables.xCustomer
Dim Count As Integer = (From t In New XPQuery(Of xCustomer)(DefaultSession) Select t.CustomerID).Count
Return Count + 1
Case Tables.xProduct
Dim Count As Integer = (From t In New XPQuery(Of xProduct)(DefaultSession) Select t.ProductID).Count
Return Count + 1
我如何简化上述语句,比如说使用字符串到类的转换?
例如,我想使用像
Dim Test 这样的对象
Test = ReturnClassOfString("xCustomer")
I have two classes xCustomer
and xProduct
Case Tables.xCustomer
Dim Count As Integer = (From t In New XPQuery(Of xCustomer)(DefaultSession) Select t.CustomerID).Count
Return Count + 1
Case Tables.xProduct
Dim Count As Integer = (From t In New XPQuery(Of xProduct)(DefaultSession) Select t.ProductID).Count
Return Count + 1
How can i simplify the above statements, lets say by using a string to class conversion?
For example i would like to use something like
Dim Test as object
Test = ReturnClassOfString("xCustomer")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许使用反射?这应该可以帮助您开始一般性的反思:
http://msdn.microsoft.com/en-us/magazine/cc163750.aspx
这应该可以帮助您解决实际问题:http://wiki.lessthandot.com/index.php/VB.Net:_Create_an_instance_of_class_from_a_string_using_reflection
Perhaps using reflection? This should help you get started with reflection in general:
http://msdn.microsoft.com/en-us/magazine/cc163750.aspx
This should help you with your actual question: http://wiki.lessthandot.com/index.php/VB.Net:_Create_an_instance_of_class_from_a_string_using_reflection