Reflection and Operator Overloads in C#

Posted by TenshiNoK on Stack Overflow See other posts from Stack Overflow or by TenshiNoK
Published on 2010-06-10T16:38:00Z Indexed on 2010/06/10 17:12 UTC
Read the original article Hit count: 221

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about reflection