Skip to content

Instantly share code, notes, and snippets.

@xanathar
Created January 28, 2016 17:54
Show Gist options
  • Save xanathar/4b488427af23df1efea5 to your computer and use it in GitHub Desktop.
Save xanathar/4b488427af23df1efea5 to your computer and use it in GitHub Desktop.
Partial enumeration of reflection MethodInfo special names
// doesn't necessary compile, nor it is necessarily comprehensive but seems a good start ;)
public enum ReflectionSpecialNameType
{
IndexGetter,
IndexSetter,
ImplicitCast,
ExplicitCast,
BinaryOperator,
UnaryOperator,
OperatorTrue,
OperatorFalse,
PropertyGetter,
PropertySetter,
AddEvent,
RemoveEvent,
}
public struct ReflectionSpecialName
{
public ReflectionSpecialNameType Type { get; private set; }
public string Argument { get; private set; }
public ReflectionSpecialName(ReflectionSpecialNameType type, string argument = null)
{
Type = type;
Argument = argument;
}
public ReflectionSpecialName(string name)
{
if (name.Contains('.'))
{
string[] split = name.Split('.');
name = split[split.Length - 1];
}
switch (name)
{
case "op_Explicit":
Type = ReflectionSpecialNameType.ExplicitCast;
return;
case "op_Implicit":
Type = ReflectionSpecialNameType.ImplicitCast;
return;
case "set_Item":
Type = ReflectionSpecialNameType.IndexSetter;
return;
case "get_Item":
Type = ReflectionSpecialNameType.IndexGetter;
return;
case "op_Addition":
Type = ReflectionSpecialNameType.BinaryOperator;
Argument = "+";
return;
case "op_BitwiseAnd":
Type = ReflectionSpecialNameType.BinaryOperator;
Argument = "&";
return;
case "op_BitwiseOr":
Type = ReflectionSpecialNameType.BinaryOperator;
Argument = "|";
return;
case "op_Decrement":
Type = ReflectionSpecialNameType.UnaryOperator;
Argument = "--";
return;
case "op_Division":
Type = ReflectionSpecialNameType.BinaryOperator;
Argument = "/";
return;
case "op_Equality":
Type = ReflectionSpecialNameType.BinaryOperator;
Argument = "==";
return;
case "op_ExclusiveOr":
Type = ReflectionSpecialNameType.BinaryOperator;
Argument = "^";
return;
case "op_False":
Type = ReflectionSpecialNameType.OperatorFalse;
return;
case "op_GreaterThan":
Type = ReflectionSpecialNameType.BinaryOperator;
Argument = ">";
return;
case "op_GreaterThanOrEqual":
Type = ReflectionSpecialNameType.BinaryOperator;
Argument = ">=";
return;
case "op_Increment":
Type = ReflectionSpecialNameType.UnaryOperator;
Argument = "++";
return;
case "op_Inequality":
Type = ReflectionSpecialNameType.BinaryOperator;
Argument = "!=";
return;
case "op_LessThan":
Type = ReflectionSpecialNameType.BinaryOperator;
Argument = "<";
return;
case "op_LessThanOrEqual":
Type = ReflectionSpecialNameType.BinaryOperator;
Argument = "<=";
return;
case "op_LogicalNot":
Type = ReflectionSpecialNameType.UnaryOperator;
Argument = "!";
return;
case "op_Modulus":
Type = ReflectionSpecialNameType.BinaryOperator;
Argument = "%";
return;
case "op_Multiply":
Type = ReflectionSpecialNameType.BinaryOperator;
Argument = "*";
return;
case "op_OnesComplement":
Type = ReflectionSpecialNameType.UnaryOperator;
Argument = "~";
return;
case "op_Subtraction":
Type = ReflectionSpecialNameType.BinaryOperator;
Argument = "-";
return;
case "op_True":
Type = ReflectionSpecialNameType.OperatorTrue;
return;
case "op_UnaryNegation":
Type = ReflectionSpecialNameType.UnaryOperator;
Argument = "-";
return;
case "op_UnaryPlus":
Type = ReflectionSpecialNameType.UnaryOperator;
Argument = "+";
return;
}
if (name.StartsWith("get_"))
{
Type = ReflectionSpecialNameType.PropertyGetter;
Argument = name.Substring(4);
}
else if (name.StartsWith("set_"))
{
Type = ReflectionSpecialNameType.PropertySetter;
Argument = name.Substring(4);
}
else if (name.StartsWith("add_"))
{
Type = ReflectionSpecialNameType.AddEvent;
Argument = name.Substring(4);
}
else if (name.StartsWith("remove_"))
{
Type = ReflectionSpecialNameType.RemoveEvent;
Argument = name.Substring(7);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment