.NET 4.0 framework dynamic features in VB with Option Strict On?

前端 未结 3 1164
慢半拍i
慢半拍i 2020-12-11 15:06

Is there any way to use the new dynamic features in the 4.0 framework like ExpandoObject in VB.NET without setting Option Strict Off? With C#, you

3条回答
  •  离开以前
    2020-12-11 15:37

    It appears you can't without having to turn Option Strict off. I'll research some more though.


    Edit


    After going through some documentation on the ExpandoObject, it appears it is used in C# for COM and Office Interop. Traditionally, in VB.NET, the Object was used for such purposes and that would require you turn off Option Strict.

    To answer your question this means that you can use dynamic types in VB.NET by using the Object type instead of the ExpandoObject [if such a type exists in VB.NET], set Option Infer On and Option Strict On or Off.
    You could also consider using partial classes to localise your non Option Strict code to particular files.



    Suggested Reading

    • Dynamic Type in C#, Equivalent in VB
    • Using Type Dynamic (C# Programming Guide)

提交回复
热议问题