コード例 #1
0
            public EnumWriter(RocketPackDefinition rocketPackDefinition)
            {
                _rocketPackDefinition = rocketPackDefinition;

                var accessLevelOption = _rocketPackDefinition.Options.FirstOrDefault(n => n.Name == "csharp_access_level");

                _accessLevel = accessLevelOption?.Value ?? "public";
            }
コード例 #2
0
ファイル: RocketCodeGenerator.cs プロジェクト: lulzzz/omnix
        public static string Generate(RocketPackDefinition definition, IEnumerable <RocketPackDefinition> externalDefinitions)
        {
            var w = new CodeWriter();

            // usingの宣言を行う。
            {
                var hashSet = new HashSet <string>();

                // ロードされた*.rpfファイルの名前空間をusingする
                hashSet.UnionWith(externalDefinitions.SelectMany(n => n.Options.Where(m => m.Name == "csharp_namespace").Select(m => m.Value.Trim())));

                var sortedList = hashSet.ToList();
                sortedList.Sort();

                foreach (var name in sortedList)
                {
                    w.WriteLine($"using {name};");
                }
            }

            w.WriteLine();

            w.WriteLine("#nullable enable");

            w.WriteLine();

            // namespaceの宣言を行う。
            {
                var option = definition.Options.First(n => n.Name == "csharp_namespace");

                w.WriteLine($"namespace {option.Value}");
            }

            w.WriteLine("{");
            w.PushIndent();

            var enumWriter   = new EnumWriter(definition);
            var classWriter  = new ClassWriter(definition, externalDefinitions);
            var structWriter = new StructWriter(definition, externalDefinitions);

            foreach (var enumInfo in definition.Enums)
            {
                // Enum
                enumWriter.Write(w, enumInfo);

                w.WriteLine();
            }

            foreach (var messageInfo in definition.Messages)
            {
                if (messageInfo.FormatType == MessageFormatType.Medium)
                {
                    // Class
                    classWriter.Write(w, messageInfo);
                }
                else if (messageInfo.FormatType == MessageFormatType.Small)
                {
                    // Struct
                    structWriter.Write(w, messageInfo);
                }

                w.WriteLine();
            }

            w.PopIndent();
            w.WriteLine("}");

            return(w.ToString());
        }