I have searched and found many example but still I need expert help. Below in the code in java:
public class myClass { public static enum myEnum { P("aco", 1000, 4, 8), L("acs", 2100, 1, 9), S("acn", 3500, 1, 6), H("ach", 5400, 1, 6); final public String cc; final int bt; final int Qp; final int lp; private myEnum(String cc, int bt, int Qp, int lp) { this.cc = cc; this.bt = bt; this.Qp = Qp; this.lp = lp; } };} I have tried to convert it like below by seeing examples:
using System.Reflection; using System; [System.AttributeUsage(System.AttributeTargets.Field, AllowMultiple = false, Inherited = true)] public class EnumAttr : System.Attribute { public EnumAttr() { } } public static class EnumExtension { public static EnumAttr GetAttr(this Enum value) { Type type = value.GetType(); FieldInfo fieldInfo = type.GetField(value.ToString()); var atts = (EnumAttr[])fieldInfo.GetCustomAttributes(typeof(EnumAttr), false); return atts.Length > 0 ? atts[0] : null; } } public class myEnumAttr : EnumAttr { public string Desc { get; set; } } public class myClass { public enum myEnum { [myEnumAttr("aco", 1000, 4, 8)]P, [myEnumAttr("acs", 2100, 1, 9)]L, [myEnumAttr("acn", 3500, 1, 6)]S, [myEnumAttr("ach", 5400, 1, 6)]H, public String cc; int bt; int Qp; int lp; private void myEnum(String cc, int bt, int Qp, int lp) { this.cc = cc; this.bt = bt; this.Qp = Qp; this.lp = lp; } };} The above code is not correct as per compiler which I know but how to make it working. Please help. Thanks.