public short AddConstantUtf8(string s) { byte[] value = new JavaTextEncoding().GetBytes(s); CompileConstantUtf8 utf8Const = ConstantPool.OfType<CompileConstantUtf8>().FirstOrDefault(x => x.Value.SequenceEqual(value)); if (utf8Const == null) { utf8Const = new CompileConstantUtf8 { PoolIndex = nextConstantIndex++, Value = value }; ConstantPool.Add(utf8Const); } return utf8Const.PoolIndex; }
private static CompileConstant[] ReadConstants(EndianBinaryReader reader) { short constantCount = reader.ReadInt16(); var constants = new CompileConstant[constantCount]; for (int i = 1; i < constantCount; i++) { var tag = (CompileConstants)reader.ReadByte(); switch (tag) { case CompileConstants.Class: constants[i] = new CompileConstantClass().Read(reader); break; case CompileConstants.Fieldref: constants[i] = new CompileConstantFieldref().Read(reader); break; case CompileConstants.Methodref: constants[i] = new CompileConstantMethodref().Read(reader); break; case CompileConstants.InterfaceMethodref: constants[i] = new CompileConstantInterfaceMethodref().Read(reader); break; case CompileConstants.String: constants[i] = new CompileConstantString().Read(reader); break; case CompileConstants.Integer: constants[i] = new CompileConstantInteger().Read(reader); break; case CompileConstants.Float: constants[i] = new CompileConstantFloat().Read(reader); break; case CompileConstants.Long: constants[i] = new CompileConstantLong().Read(reader); i++; // The next slot is invalid break; case CompileConstants.Double: constants[i] = new CompileConstantDouble().Read(reader); i++; // The next slot is invalid break; case CompileConstants.NameAndType: constants[i] = new CompileConstantNameAndType().Read(reader); break; case CompileConstants.Utf8: constants[i] = new CompileConstantUtf8().Read(reader); break; case CompileConstants.MethodHandle: constants[i] = new CompileConstantMethodHandle().Read(reader); break; case CompileConstants.MethodType: constants[i] = new CompileConstantMethodType().Read(reader); break; case CompileConstants.InvokeDynamic: constants[i] = new CompileConstantInvokeDynamic().Read(reader); break; default: throw new NotImplementedException(); } } return constants; }