【发布时间】:2015-12-04 03:25:28
【问题描述】:
我一直在构建一个大型应用程序,需要使用 args 重载 NEW 方法(我猜很常见)。
我在某些类中有很多属性,而且大多数(如果不是全部)在新方法中都被重载了。我想知道是否有办法从方法中捕获参数并通过查看属性/参数将值分配给自定义对象。我在类中的所有属性名称都与方法中作为参数传递的名称匹配,因此应该可以匹配“名称”属性???
或者为每个参数手动输入me.property = arg 的一种不那么费力的方式...
例如:
public class myClass
property arg1 as string
property arg2 as string
property arg3 as string
public sub new(arg1 as string, arg2 as string, arg3 as string)
For each arg in methodbase.getcurrentmethod.getParameters
custObj(<property name>).value = arg.value where custObj.name = arg.name
end for
end sub
end class
这不是有效的 VB.net 语法只是我试图实现的一个示例。
【问题讨论】:
标签: vb.net methods reflection