mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-16 09:12:22 +00:00
Add enum name lookup method to Java/C# enums
Tested: on Linux for Java and C# Bug: 15781151 Change-Id: I7cb97bcc01d986cac2b24aaf7cb29521ddaa2f6b
This commit is contained in:
@@ -5,8 +5,12 @@ namespace MyGame.Example
|
||||
|
||||
public class Any
|
||||
{
|
||||
public static byte NONE = 0;
|
||||
public static byte Monster = 1;
|
||||
public static readonly byte NONE = 0;
|
||||
public static readonly byte Monster = 1;
|
||||
|
||||
private static readonly string[] names = { "NONE", "Monster", };
|
||||
|
||||
public static string Name(int e) { return names[e]; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
4
tests/MyGame/Example/Any.java
Executable file → Normal file
4
tests/MyGame/Example/Any.java
Executable file → Normal file
@@ -5,5 +5,9 @@ package MyGame.Example;
|
||||
public class Any {
|
||||
public static final byte NONE = 0;
|
||||
public static final byte Monster = 1;
|
||||
|
||||
private static final String[] names = { "NONE", "Monster", };
|
||||
|
||||
public static String name(int e) { return names[e]; }
|
||||
};
|
||||
|
||||
|
||||
@@ -5,9 +5,13 @@ namespace MyGame.Example
|
||||
|
||||
public class Color
|
||||
{
|
||||
public static sbyte Red = 1;
|
||||
public static sbyte Green = 2;
|
||||
public static sbyte Blue = 8;
|
||||
public static readonly sbyte Red = 1;
|
||||
public static readonly sbyte Green = 2;
|
||||
public static readonly sbyte Blue = 8;
|
||||
|
||||
private static readonly string[] names = { "Red", "Green", "", "", "", "", "", "Blue", };
|
||||
|
||||
public static string Name(int e) { return names[e - Red]; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
4
tests/MyGame/Example/Color.java
Executable file → Normal file
4
tests/MyGame/Example/Color.java
Executable file → Normal file
@@ -6,5 +6,9 @@ public class Color {
|
||||
public static final byte Red = 1;
|
||||
public static final byte Green = 2;
|
||||
public static final byte Blue = 8;
|
||||
|
||||
private static final String[] names = { "Red", "Green", "", "", "", "", "", "Blue", };
|
||||
|
||||
public static String name(int e) { return names[e - Red]; }
|
||||
};
|
||||
|
||||
|
||||
0
tests/MyGame/Example/Monster.java
Executable file → Normal file
0
tests/MyGame/Example/Monster.java
Executable file → Normal file
0
tests/MyGame/Example/Test.java
Executable file → Normal file
0
tests/MyGame/Example/Test.java
Executable file → Normal file
0
tests/MyGame/Example/Vec3.java
Executable file → Normal file
0
tests/MyGame/Example/Vec3.java
Executable file → Normal file
Reference in New Issue
Block a user