c# - Add operator to third-party type? -


i have third-party library (mogre), in struct (vector3). add overload '+' operator (no override needed) type not sure how.

i cannot use extension methods operator want extend; class not sealed not partial either, if try , define again new operator overload conflicts.

is possible extend type this? best way it?

you cannot add operator overload third-party type -- class don't have ability edit. operator overloads must defined inside type operate on (at least 1 of args). since it's not type, can't edit it, , structs cannot extended.

but, if non-sealed class, you'd have sub-class, ruin point because you'd have use subclass , not superclass operator, since can't define operator overload between base types...

public class {     public int x { get; set; } }  public class b : {     public static operator + (a first, second)     {         // won't compile because either first or second must type b...     } } 

you overload between instances of subclass, you'd have use new subclass wherever wanted overload instead of original superclass, clunky , not want:

public class {     public int x { get; set; } }  public class b : {     public static b operator + (b first, b second)     {         // this, you'd have use subclass b everywhere wanted         // instead of original class a, may undesirable...     } } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -