I found this great resource that explains how to make the determination between standard, output, or reference parameters using .NET reflection.
Now, I want to do the same thing using EnvDTE. There doesn't seem to be any obvious way in the documentation. So how does one accomplish that?
I don't want to resort to string parsing if I don't have to, but if there is no other way, I will accept it as the answer (provided you show an example).
On a related note - how do you determine default values for optional parameters using DTE?
Some Context
I am creating an extension for the Visual Studio IDE (single file generator). It reads the project code files and looks for interfaces that are decorated with some custom attributes, then it retrieves the information about all of the members and inherited members of the interfaces. The end goal is to generate fully implemented methods and properties based on those interfaces. I have it working for the standard parameters, but working out how to make it identify ref, out, and optional parameters is proving difficult.
You can cast your CodeParameter
to CodeParameter2
interface.
Note: you'll have to add reference to the EnvDTE80.dll
assembly.
After that, you can analyze its ParameterKind
property e.g.:
CodeFunction function = ...;
foreach (CodeParameter2 param in function.Parameters)
{
if (param.ParameterKind == vsCMParameterKind.vsCMParameterKindNone)
{
// standard parameter
}
else if (param.ParameterKind == vsCMParameterKind.vsCMParameterKindOptional)
{
// optional parameter
}
else if (param.ParameterKind == vsCMParameterKind.vsCMParameterKindOut)
{
// out parameter
}
else if (param.ParameterKind == vsCMParameterKind.vsCMParameterKindRef)
{
// reference parameter
}
}
And regarding:
On a related note - how do you determine default values for optional parameters using DTE?
If parameter is optional you can use the DefaultValue
property to get or set its default value.
As a side note, when EnvDTE type doesn't provide needed functionality the first thing I'd suggest - is to look for type's counterpart with a higher version number:
CodeParameter
=>CodeParameter2
Debugger
=>Debugger2
=> ... =>Debugger5