|
■No82135 (yapii さん) に返信 > Option Strict On で Dynamic型をあつかえる日が来るのでしょうか・・・
操作用の拡張メソッドを用意しておいては如何でしょう。 MsgBox( dynObj.Test ) の代わりに MsgBox( dynObj.GetProp("Test") ) と書く感じで。
Option Strict On Imports System.Dynamic Imports System.Runtime.CompilerServices Friend Module DynamicExtensions <Extension> Friend Sub SetProp(Of T)(this As DynamicObject, memberName As String, newValue As T) CallByName(this, memberName, CallType.Set, newValue) End Sub
<Extension> Friend Function GetProp(this As DynamicObject, memberName As String) As Object Return CallByName(this, memberName, CallType.Get) End Function
<Extension> Friend Function GetPropT(Of T)(this As DynamicObject, memberName As String) As T Return DirectCast(CallByName(this, memberName, CallType.Get), T) End Function End Module
|