Exemple #1
0
        public static IAttribute ReadAttribute(this ClassReader reader, ConstantPool pool)
        {
            var nameIndex = reader.ReadU2();
            var length    = reader.ReadU4();
            var name      = pool.GetUtf8String(nameIndex);

            if (!Enum.TryParse <AttributeType>(name, true, out var type))
            {
                type = AttributeType.Unparsed;
            }
            switch (type)
            {
            case AttributeType.Deprecated:
                return(new DeprecatedAttribute());

            case AttributeType.Synthetic:
                return(new SyntheticAttribute());

            case AttributeType.SourceFile:
                var fileNameIndex = reader.ReadU2();
                return(new SourceFileAttribute(pool.GetUtf8String(fileNameIndex)));

            case AttributeType.ConstantValue:
                var constantIndex = reader.ReadU2();
                return(new ConstantValueAttribute(pool.GetConstant(constantIndex)));

            case AttributeType.Code:
                ushort stack = reader.ReadU2(), locals = reader.ReadU2();
                var    codelength = reader.ReadU4();
                var    code       = reader.ReadBytes((int)codelength);
                return(new CodeAttribute(stack, locals, code, ReadExceptionTables(reader), ReadAttributes(reader, pool)));

            case AttributeType.Exceptions:
                return(new ExceptionsAttribute(reader.ReadU2S()));

            case AttributeType.LineNumberTable:
                return(new LineNumberTableAttribute(ReadLineNumberTableEntrys(reader)));

            case AttributeType.LocalVariableTable:
                return(new LocalVariableTableAttribute(ReadLocalVariableTableEntrys(reader)));
            }
            return(new UnparsedAttribute(reader.ReadBytes((int)length)));
        }