c# - How can I add a .Equals() extension to an enumeration? -
i have following code:
public enum fieldtype { int, year, string, datetime } public enum datatype { int, string, datetime }
i have extension method each can this:
fieldtype ftype = fieldtype.year; datatype dtype = datatype.int; ftype.equals(dtype); //if ftype int/year, , dtype int should return true dtype.equals(ftype); //if dtype int, , ftype int/year should true
is there way create .equals extension, work out?
as jon said, reusing framework's method name not idea.
but :
public static class extensions { public static bool isequivalentto(this fieldtype field, datatype data) { return data.tostring() == field.tostring(); } public static bool isequivalentto(this datatype data, fieldtype field) { return data.tostring() == field.tostring(); } }
or better :
public static class extensions { public static bool isequivalentto(this enum e1, enum e2) { return e1.tostring() == e2.tostring(); } }
Comments
Post a Comment