私はレジスタプロパティメソッドにデフォルト値を与えようとしています。これには関数が必要でしたが、オブジェクトとして渡されました(デリゲート?)。ここでは、コードです:関数ではなく関数として関数を渡す方法はありますか?
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())
これは関数として渡された関数ですが、私はそれをオブジェクトとして渡す必要があります。
これについてのご意見はありますか? VB 2008以上と
Public Shared Function whatever() As propertyData
registerproperty("item", GetType(IEnumerable(Of Person)), AddressOf GetObject)
End Function
Public Shared Function GetObject() As Person
return New Person
End Function
あなたが持っているものを使用することができます:
registerproperty("Item", GetType(IEnumerable(Of Person)), Function() New Person)
'AddressOf'演算子を使用します。 [VB代理人のドキュメント](http://msdn.microsoft.com/en-us/library/ms172879.aspx)には多くの例があります。 –
コードは大体正しいですが、ラムダは 'Func
[トピックを外して] Raymondさんを見てみましょう。 – HardCode