Here's the deal. I've got a program that will load a given assembly, parse through all Types and their Members and compile a TreeView (very similar to old MSDN site) and then build HTML pages for each node in the TreeView. It basically takes a given assembly and allows the user to create their own MSDN-like library for it for documentation purposes.
Here's the problem I've run into: whenever an operator overload is encounted in a defined class, reflection returns that as a "MethodInfo" with the name set to something like "op_Assign" or "op_Equality". I want to be able to capture these and list them properly, but I can't find anything in the MethodInfo object that is returned to accurately identify that I'm looking at an operator.
I definitely don't want to just capture everything that starts with "op_", since that will most certainly (at some point) will pick up a method it's not supposed to. I know that other methods and properties that are "special cases" like this one have the "IsSpecialName" property set, but appearantly that's not the case with operators.
I've been scouring the 'net and wracking my brain to two days trying to figure this one out, so any help will be greatly appreciated.
The op_ naming convention is a standard or defacto standard for .net. When reflecting, I would do something like this:
public void GenerateDocForMethod(MethodInfo method)
{
if(method.Name.StartsWith("op_"))
GenerateDocForOperator(method);
else
GenerateDocForStandardMethod(method);
}
public void GenerateDocForOperator(MethodInfo method)
{
switch(method.Name)
{
case "op_Addition":
//generate and handle other cases...
//handle methods that just happen to start with op_
default:
GenerateDocForStandardMethod(method);
}
}
public void GenerateDocForStandardMethod(MethodInfo method)
{
//generate doc
}
GenerateDocForOperator will switch on all of the overloadable operators (don't forget implicit and explicit conversions). If the method name is not one of the standard operator names, it calls the GenerateDocForStandardMethod. I couldn't find an exhaustive list of operator method names but I could probably provide a complete list if you really need it.
EDIT: Here's a list of the method names of overloadable operators (taken from http://forums.devx.com/showthread.php?55322-Operator-Overloading.....C-can-do-it....&p=208952#post208952):
op_Implicit
op_Explicit
op_Addition
op_Subtraction
op_Multiply
op_Division
op_Modulus
op_ExclusiveOr
op_BitwiseAnd
op_BitwiseOr
op_LogicalAnd
op_LogicalOr
op_Assign
op_LeftShift
op_RightShift
op_SignedRightShift
op_UnsignedRightShift
op_Equality
op_GreaterThan
op_LessThan
op_Inequality
op_GreaterThanOrEqual
op_LessThanOrEqual
op_MultiplicationAssignment
op_SubtractionAssignment
op_ExclusiveOrAssignment
op_LeftShiftAssignment
op_ModulusAssignment
op_AdditionAssignment
op_BitwiseAndAssignment
op_BitwiseOrAssignment
op_Comma
op_DivisionAssignment
op_Decrement
op_Increment
op_UnaryNegation
op_UnaryPlus
op_OnesComplement
Operator overloads do get the IsSpecialName flag set to true. And if you implement the methods by explicitly giving them a name like op_* that flag is set to false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With