c# - Create implicit cast for enum value -
i've created own messagebox own enum messageboxbutton :
public enum mymessageboxbutton { ok = messageboxbutton.ok, okcancel = messageboxbutton.okcancel, yesnocancel = messageboxbutton.yesnocancel, yesno = messageboxbutton.yesno, nowlatercancel = 5, }
as can see, it's system.windows.messageboxbutton 1 value more.
for class mymessagebox, have function :
public static messageboxresult show(string caption, string message, mymessageboxbutton button, messageboximage icon) { ... }
is there way call show
messageboxbutton
, implicitly cast value mymessageboxbutton
?
you can create converter method converts messageboxbuttons
mymessageboxbutton
, create overload of show
method takes messageboxbuttons
, , in method conversion , call existing show
method.
since don't have matching enum values items (like abortretryignore
), have decide button combination show if selects 1 of those:
public static mymessageboxbutton converttomymessageboxbutton(messageboxbuttons input) { mymessageboxbutton result; switch (input) { case messageboxbuttons.ok: result = mymessageboxbutton.ok; break; case messageboxbuttons.okcancel: result = mymessageboxbutton.okcancel; break; case messageboxbuttons.retrycancel: result = mymessageboxbutton.nowlatercancel; break; case messageboxbuttons.yesno: result = mymessageboxbutton.yesno; break; case messageboxbuttons.yesnocancel: result = mymessageboxbutton.yesnocancel; break; default: // abortretryignore fall through result = mymessageboxbutton.okcancel; break; } return result; }
then use convert
method in overload of show
method, conversion , call original show
:
public static messageboxresult show(string caption, string message, messageboxbuttons button, messageboximage icon) { return show(caption, message, converttomymessageboxbutton(button), icon); }
Comments
Post a Comment