How to call a method written in VB.NET with C # with optional arguments

I have a method written in VB.NET. It looks like this:

Shared Sub SomeMethod(ByVal Id As Guid, 
                      Optional ByVal str1 As String = "foo", 
                      Optional ByVal str2 As String = "")

I want to call this method from C # 3.0, and I want it to use its default arguments. I tried to skip System.Reflection.Missing.Value, but I cannot use it as a String.

Is there any way to do this?

Thanks in advance for your help.

+3
source share
3 answers

No, in C # 3 you just need to pass all the parameters. C # 4 will have optional and named parameters.

Of course, you can create some overloaded variations, but this is only an approximation.

+9
source

# 4.0 ( ) ; FxCop, , #.

+2

if you want to get additional parameter values ​​that you can use for reflection, this information is stored in a user attribute with the corresponding parameter

0
source

Source: https://habr.com/ru/post/1735234/


All Articles