dotnet / dotnet/dotnet-api-docs
May we call Activator.CreateInstance with the BindingFlags.OptionalParamBinding flag?
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
This documentation page, under the OptionalParamBinding field description, stats that:
"This flag should only be used with InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[])."
This remark seems to suggest that it is invalid to use this flag with Activator.CreateInstance.
However, apparently, StackOverflow disagrees:
https://stackoverflow.com/questions/11002523/activator-createinstance-with-optional-parameters
The above question links to another question to explain why they think it is valid to use OptionalParamBinding with Activator.CreateInstance:
https://stackoverflow.com/questions/1295344/difference-between-activator-createinstance-and-typeoft-invokemember-with
My question is, is such a use valid?
If it is, then maybe this remark on this page should be updated, to explicitely allow InvokeMember AND CreateInstance?
If it's not, then maybe it would make sense to explicitely say on StackOveflow that such a use is invalid (regardless of what other comments / answers say) to clear the confusion?
---
#### Document Details
⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*
* ID: 7a92a1aa-804c-89c8-582d-7e1d034f8ec6
* Version Independent ID: dab87a82-eb83-77ce-8acc-67a77e2a9860
* Content: [BindingFlags Enum (System.Reflection)](https://docs.microsoft.com/en-us/dotnet/api/system.reflection.bindingflags?view=netcore-2.1)
* Content Source: [xml/System.Reflection/BindingFlags.xml](https://github.com/dotnet/dotnet-api-docs/blob/master/xml/System.Reflection/BindingFlags.xml)
* Product: **.net**
* GitHub Login: @rpetrusha
* Microsoft Alias: **ronpet**
Contributor guide
Assessment
This issue has not been assessed yet.