Click here to Skip to main content
15,940,921 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi i want to move enum from java to c# but i dont know what todo so im going here to ask you.
here is java code:
Java
@XmlEnum
public enum ItemAttackType {
	PHYSICAL(false, SkillElement.NONE),
	MAGICAL_EARTH(true, SkillElement.EARTH),
	MAGICAL_WATER(true, SkillElement.WATER),
	MAGICAL_WIND(true, SkillElement.WIND),
	MAGICAL_FIRE(true, SkillElement.FIRE);

	private boolean magic;
	private SkillElement elem;

	private ItemAttackType(boolean magic, SkillElement elem) {
		this.magic = magic;
		this.elem = elem;
	}

	public boolean isMagical() {
		return magic;
	}
	
	public SkillElement getMagicalElement() {
		return elem;
	}
}


Java
public enum SkillElement {
	NONE(0),
	FIRE(1),
	WATER(2),
	WIND(3),
	EARTH(4),
	LIGHT(5),
	DARK(6);

	private int element;

	private SkillElement(int id) {
		this.element = id;
	}

	public int getElementId() {
		return element;
	}

}


What I have tried:

i tried code like this but im not sure its work.

C#
public enum ItemAttackType
    {
        PHYSICAL,
        MAGICAL_EARTH,
        MAGICAL_WATER,
        MAGICAL_WIND,
        MAGICAL_FIRE
    }

    public enum SkillElement
    {
        NONE=0,
        FIRE=1,
        WATER=2,
        WIND=3,
        EARTH=4,
        LIGHT=5,
        DARK=6
    }


C#
public class ItemAttackTypeUtil
    {
        private static readonly IDictionary<itemattacktype, itemattacktypeutil=""> PLANETS = new Dictionary<itemattacktype, itemattacktypeutil="">();
        SkillElement guardRace;
        bool isMagic;

        static ItemAttackTypeUtil()
        {
            PLANETS.Add(ItemAttackType.PHYSICAL, new ItemAttackTypeUtil(SkillElement.NONE, false));
            PLANETS.Add(ItemAttackType.MAGICAL_EARTH, new ItemAttackTypeUtil(SkillElement.EARTH, true));
            PLANETS.Add(ItemAttackType.MAGICAL_WATER, new ItemAttackTypeUtil(SkillElement.WATER, true));
            PLANETS.Add(ItemAttackType.MAGICAL_WIND, new ItemAttackTypeUtil(SkillElement.WIND, true));
            PLANETS.Add(ItemAttackType.MAGICAL_FIRE, new ItemAttackTypeUtil(SkillElement.FIRE, true));
        }

        public ItemAttackTypeUtil(SkillElement guardRace, bool isMagic)
        {
            this.guardRace = guardRace;
            this.isMagic = isMagic;
        }

        public static ItemAttackTypeUtil GetUtil(ItemAttackType tribe)
        {
            return PLANETS[tribe];
        }
    }


is its correct? or have another solutions?
Posted
Updated 18-Nov-16 4:04am

1 solution

Is what correct? If something does not work then please explain in proper detail.

In the meantime you could take a look at Enumeration Types (C# Programming Guide)[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900