Optional parameters in managed C++/CLI methods

后端 未结 3 1311
感情败类
感情败类 2020-12-10 23:58

How can I declare a managed method in C++/CLI that has an optional parameter when used from C#?

I\'ve decorated the parameter with both an Optional and a DefaultPara

3条回答
  •  醉话见心
    2020-12-11 00:36

    The C# compiler doesn't use the [DefaultParameterValue] attribute to set the default value, it uses the .param directive to get the value embedded in the metadata. Barely documented in the CLI spec btw, only Partition II, chapter 15.4.1 mentions that it can have a FieldInit value, 15.4.1.4 is silent about it.

    That's where the buck stops, the C++/CLI compiler doesn't know how to generate the directive. You cannot make this work.

提交回复
热议问题