예제 #1
0
        private void Initialized(SourceReader reader, List <string> declarations, CodeType type)
        {
            var typeName = reader.ReadTypeName();

            switch (type)
            {
            case CodeType.Class:
            {
                var element = new ClassElement(typeName, declarations, this);
                element.Init(reader);
                AddElement(element);
            }
            break;

            case CodeType.Interface:
            {
                var element = new InterfaceElement(typeName, declarations, this);
                element.Init(reader);
                AddElement(element);
            }
            break;

            case CodeType.Struct:
            {
                var element = new StructElement(typeName, declarations, this);
                element.Init(reader);
                AddElement(element);
            }
            break;

            case CodeType.Enum:
            {
                var element = new EnumElement(typeName, declarations, this);
                element.Init(reader);
                AddElement(element);
            }
            break;
            }
        }
예제 #2
0
        /// <summary>
        /// 读取当前代码块。
        /// </summary>
        /// <param name="reader">字符串读取实例。</param>
        public override void Init(SourceReader reader)
        {
            reader.Offset();           //跳过{
            reader.EscapeWhiteSpace(); //过滤空格
            while (reader.CanRead)
            {
                switch (reader.Current)
                {
                case '[':
                    ReadAttribute(reader);
                    break;

                case '/':
                    ReadComment(reader);
                    break;

                case '}':    //结束
                    reader.Offset();
                    return;

                default:
                {
                    var declarations = ReadDeclarations(reader, out var type);
                    var typeName     = reader.ReadTypeName();
                    switch (type)
                    {
                    case CodeType.Class:
                    {
                        var element = new ClassElement(typeName, declarations, this);
                        element.Init(reader);
                        AddElement(element);
                    }
                    break;

                    case CodeType.Interface:
                    {
                        var element = new InterfaceElement(typeName, declarations, this);
                        element.Init(reader);
                        AddElement(element);
                    }
                    break;

                    case CodeType.Struct:
                    {
                        var element = new StructElement(typeName, declarations, this);
                        element.Init(reader);
                        AddElement(element);
                    }
                    break;

                    case CodeType.Enum:
                    {
                        var element = new EnumElement(typeName, declarations, this);
                        element.Init(reader);
                        AddElement(element);
                    }
                    break;
                    }
                }
                break;
                }

                reader.EscapeWhiteSpace();
            }
        }