C# naming related enum, private member and public accessor.

Might sound petty of me, but I struggle with C# naming convention.
It is fine when I only have a private member and a public accessor as follow:

private int size;
public int Size { get { return size;} }

but it gets confusing when you use an enum. Clearly, I can’t name my accessor the same as my enum :

public enum Size { Tiny = 0, Small = 1, Medium = 2, Large = 4}
private Size size;
public Size Size { get { return size;} }

By convention I shouldn’t use plural enum names unless they are bitwise which it isn’t. The following could solve it, but I doubt that’s coding friendly when it is only a simple getter.

public Size GetSize(){ return size; }

Is there other alternatives?

After a bit more research, I managed to find a bit of counter-intuitive information. The suggested structure is to pull the enum out of my class :

public class Item {
    Size size;
    public Size Size { get { return size; } }
}

public enum Size {
    tiny = 0,
    small = 1,
    medium = 2,
    large = 4
}

This way you are not conflicting with naming convention. Problem I see with this is you must not have more than one Size enum in the namespace.

public class Weapon : Item {
    Type type;
    public Type Type { get { return type; } }
}

public class Armor : Item {
    Type type;
    public Type Type { get { return type; } }
}

We’ll agree armor and weapon can’t have the same type. Can’t nest enum due to original issue to not conflict with naming convention. So only solution left would be to rename Type into ArmorType and WeaponType, and if we are renaming them it won’t conflict with accessor name right? :

public class Weapon : Item {
    public enum WeaponType {
        ranged,
        melee
    }

    WeaponType type;
    public WeaponType Type { get { return type; } }
}

But how fun will it be to type :

Weapon.WeaponType type = Weapon.WeaponType.ranged;

So no nesting :

public class Weapon : Item {
    
    WeaponType type;
    public WeaponType Type { get { return type; } }
}

public enum WeaponType {
    ranged,
    melee
}

put a underscore _ before your private filed. it’s very common in C#.
like this:


 public enum Size { Tiny = 0, Small = 1, Medium = 2, Large = 4}
 private Size _size;
 public Size Size { get { return _size;} }