コード例 #1
0
        private static void CollectEnumTypes(
            IDocumentAnalyzerContext context)
        {
            var analyzer = new EnumTypeUsageAnalyzer(context.Schema);

            analyzer.Analyze(context.Document);

            foreach (EnumType enumType in analyzer.EnumTypes)
            {
                RenameDirective?rename;
                var             values = new List <EnumValueModel>();

                foreach (IEnumValue enumValue in enumType.Values)
                {
                    rename = enumValue.Directives.SingleOrDefault <RenameDirective>();

                    EnumValueDirective?value =
                        enumValue.Directives.SingleOrDefault <EnumValueDirective>();

                    values.Add(new EnumValueModel(
                                   rename?.Name ?? GetEnumValue(enumValue.Name),
                                   enumValue.Description,
                                   enumValue,
                                   value?.Value));
                }

                rename = enumType.Directives.SingleOrDefault <RenameDirective>();

                SerializationTypeDirective?serializationType =
                    enumType.Directives.SingleOrDefault <SerializationTypeDirective>();

                NameString typeName = context.ResolveTypeName(
                    rename?.Name ?? GetClassName(enumType.Name));

                context.RegisterModel(
                    typeName,
                    new EnumTypeModel(
                        typeName,
                        enumType.Description,
                        enumType,
                        serializationType?.Name,
                        values));
            }
        }
コード例 #2
0
        private static void CollectEnumTypes(
            IDocumentAnalyzerContext context,
            IEnumerable <DocumentNode> documents)
        {
            var analyzer = new EnumTypeUsageAnalyzer(context.Schema);

            foreach (DocumentNode document in documents)
            {
                analyzer.Analyze(document);
            }

            foreach (EnumType enumType in analyzer.EnumTypes)
            {
                RenameDirective?rename;
                var             values = new List <EnumValueModel>();

                foreach (EnumValue enumValue in enumType.Values)
                {
                    rename = enumValue.Directives.SingleOrDefault <RenameDirective>();

                    EnumValueDirective?value =
                        enumValue.Directives.SingleOrDefault <EnumValueDirective>();

                    values.Add(new EnumValueModel(
                                   GetClassName(rename?.Name ?? enumValue.Name),
                                   enumValue,
                                   enumValue.Description,
                                   value?.Value));
                }

                rename = enumType.Directives.SingleOrDefault <RenameDirective>();

                SerializationTypeDirective?serializationType =
                    enumType.Directives.SingleOrDefault <SerializationTypeDirective>();

                context.Register(new EnumTypeModel(
                                     GetClassName(rename?.Name ?? enumType.Name),
                                     enumType.Description,
                                     enumType,
                                     serializationType?.Name,
                                     values));
            }
        }