How can I check whether a certain type implements a certain operator?
struct CustomOperatorsClass
{
public int Value { get; private set; }
public CustomOperatorsClass( int value )
: this()
{
Value = value;
}
static public CustomOperatorsClass operator +(
CustomOperatorsClass a, CustomOperatorsClass b )
{
return new CustomOperatorsClass( a.Value + b.Value );
}
}
Following two checks should return true
:
typeof( CustomOperatorsClass ).HasOperator( Operator.Addition )
typeof( int ).HasOperator( Operator.Addition )
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…