Antlr4.StringTemplate.TemplateGroup.CreateGroupObject C# (CSharp) Method

CreateGroupObject() private method

private CreateGroupObject ( System.IO.BinaryReader reader, int key, object>.Dictionary objects ) : object
reader System.IO.BinaryReader
key int
objects object>.Dictionary
return object
        private object CreateGroupObject(BinaryReader reader, int key, Dictionary<int, object> objects)
        {
            var comparer = ObjectReferenceEqualityComparer<object>.Default;

            int typeKey = reader.ReadInt32();
            if (typeKey == 0)
            {
                // this is a string
                return reader.ReadString();
            }

            string typeName = (string)objects[typeKey];
            if (typeName == typeof(bool).FullName)
            {
                return reader.ReadBoolean();
            }
            else if (typeName == typeof(TemplateToken).FullName || typeName == typeof(CommonToken).FullName)
            {
                int channel = reader.ReadInt32();
                int charPositionInLine = reader.ReadInt32();
                int line = reader.ReadInt32();
                int startIndex = reader.ReadInt32();
                int stopIndex = reader.ReadInt32();
                string text = reader.ReadString();
                int tokenIndex = reader.ReadInt32();
                int type = reader.ReadInt32();
                CommonToken token = new CommonToken(type, text)
                {
                    Channel = channel,
                    CharPositionInLine = charPositionInLine,
                    Line = line,
                    StartIndex = startIndex,
                    StopIndex = stopIndex,
                    TokenIndex = tokenIndex,
                };

                return token;
            }
            else if (typeName == typeof(CompiledTemplate).FullName)
            {
                CompiledTemplate compiledTemplate = new CompiledTemplate();
                compiledTemplate.Name = reader.ReadString();
                compiledTemplate.Prefix = reader.ReadString();
                compiledTemplate.Template = reader.ReadString();
                int templateDefStartTokenObject = reader.ReadInt32();
                compiledTemplate.HasFormalArgs = reader.ReadBoolean();
                int nativeGroupObject = reader.ReadInt32();
                compiledTemplate.IsRegion = reader.ReadBoolean();
                compiledTemplate.RegionDefType = (Template.RegionType)reader.ReadInt32();
                compiledTemplate.IsAnonSubtemplate = reader.ReadBoolean();

                int formalArgsLength = reader.ReadInt32();
                if (formalArgsLength > 0)
                {
                    for (int i = 0; i < formalArgsLength; i++)
                    {
                        int formalArgObject = reader.ReadInt32();
                    }
                }

                int stringsLength = reader.ReadInt32();
                if (stringsLength >= 0)
                {
                    compiledTemplate.strings = new string[stringsLength];
                    for (int i = 0; i < stringsLength; i++)
                        compiledTemplate.strings[i] = reader.ReadString();
                }

                int instrsLength = reader.ReadInt32();
                if (instrsLength >= 0)
                    compiledTemplate.instrs = reader.ReadBytes(instrsLength);

                compiledTemplate.codeSize = reader.ReadInt32();

                int sourceMapLength = reader.ReadInt32();
                if (sourceMapLength >= 0)
                {
                    compiledTemplate.sourceMap = new Interval[sourceMapLength];
                    for (int i = 0; i < sourceMapLength; i++)
                    {
                        int start = reader.ReadInt32();
                        int length = reader.ReadInt32();
                        if (length >= 0)
                            compiledTemplate.sourceMap[i] = new Interval(start, length);
                    }
                }

                return compiledTemplate;
            }
            else if (typeName == typeof(FormalArgument).FullName)
            {
                string name = reader.ReadString();
                int index = reader.ReadInt32();
                IToken defaultValueToken = (IToken)objects[reader.ReadInt32()];
                int defaultValueObject = reader.ReadInt32();
                int compiledDefaultValue = reader.ReadInt32();

                FormalArgument formalArgument = new FormalArgument(name, defaultValueToken);
                formalArgument.Index = index;

                return formalArgument;
            }
            else if (typeName == typeof(Template).FullName)
            {
                int implObject = reader.ReadInt32();

                int localsCount = reader.ReadInt32();
                for (int i = 0; i < localsCount; i++)
                {
                    int localObject = reader.ReadInt32();
                }

                int groupObject = reader.ReadInt32();

                TemplateGroup group = this;
                Template template = new Template(group);
                return template;
            }
            else if (typeName == typeof(TemplateGroupFile).FullName)
            {
                bool isDefaultGroup = reader.ReadBoolean();
                if (!isDefaultGroup)
                    return this;
                else
                    throw new NotSupportedException();
            }
            else if (typeName == typeof(TemplateGroup).FullName)
            {
                bool isDefaultGroup = reader.ReadBoolean();
                if (isDefaultGroup)
                    return TemplateGroup.DefaultGroup;
                else
                    throw new NotSupportedException();
            }
            else
            {
                throw new NotImplementedException();
            }
        }