我想给一个默认值的注册属性方法。这需要一个函数,但作为一个对象传递(委托?)。这里的代码:如何将函数作为对象而不是函数传递?
protected static propertydata registerproperty(string name, Type type, Func<object> createDefaultValue)
{
return RegisterProperty(name, type, createDefaultValue, false, null);
}
我想调用registerproperty方法,但我不知道我怎么能在VB.net中做到这一点。我只需要沿着一个新的Person对象传递,我认为这是要走的路:
Public Shared ReadOnly ItemsProperty As PropertyData = RegisterProperty("Items", GetType(IEnumerable(Of Person)), Function() new Person())
这是作为一个函数传递的功能,但我需要它来传递作为对象。
对这个有什么想法?
使用'AddressOf'操作。 [VB委托文档](http://msdn.microsoft.com/en-us/library/ms172879.aspx)包含许多示例。 – 2011-12-20 15:38:02
代码大致正确,lambda是'Func
[离题]很酷,在SO看到Raymond。 – HardCode 2011-12-20 16:44:38