Esempio n. 1
0
        public static void BuildSopClassUids()
        {
            var sopFields = DicomDefinitionLoader.LoadCurrentSopClasses()
                            .Select(sopClass => G.FieldDeclaration(
                                        sopClass.Keyword,
                                        G.IdentifierName(nameof(String)),
                                        Accessibility.Public,
                                        DeclarationModifiers.Const,
                                        G.LiteralExpression(sopClass.Id)));

            CodeGenHelper.PublicPartialClassFull(typeof(SOPClassUID), sopFields)
            .WriteOut("SOPClassUID.cs");
        }
Esempio n. 2
0
        public static void GenerateStuff()
        {
            var tags         = new List <SyntaxNode>();
            var selectors    = new List <SyntaxNode>();
            var seqSelectors = new List <SyntaxNode>();
            var forgeNodes   = new List <SyntaxNode>();

            foreach (var entry in DicomDefinitionLoader.LoadCurrentDictionary().Where(d => !string.IsNullOrEmpty(d.Keyword)))
            {
                tags.Add(entry.GenerateTag());

                var(className, node) = entry.Parse();

                if (className == null)
                {
                    continue;
                }

                // selector
                var(propGetStatements, propSetStatements) = entry.GeneratePropertyStatements(className);

                var selector = G.PropertyDeclaration(entry.Keyword,
                                                     G.IdentifierName(className),
                                                     Accessibility.Public,
                                                     DeclarationModifiers.None,
                                                     propGetStatements,
                                                     propSetStatements);

                selectors.Add(selector);

                var propGetManyStatements = G.ReturnStatement(G.InvocationExpression(
                                                                  G.IdentifierName($"_dicom.FindAll(\"{entry.Id}\").Select(d => d as {className}).ToList")));

                var manySelector = G.PropertyDeclaration(entry.Keyword + "_", G.IdentifierName($"List<{className}>"),
                                                         Accessibility.Public, DeclarationModifiers.ReadOnly, new[] { propGetManyStatements });

                selectors.Add(manySelector);

                var seqPropGetStatements = entry.GenerateSequencePropertyStatements(className);

                var seqSelector = G.PropertyDeclaration(entry.Keyword,
                                                        G.IdentifierName(className),
                                                        Accessibility.Public,
                                                        DeclarationModifiers.ReadOnly,
                                                        seqPropGetStatements);

                seqSelectors.Add(seqSelector);

                var propGetManySeqStatements = G.ReturnStatement(G.InvocationExpression(
                                                                     G.IdentifierName($"Items.FindAll<{className}>(\"{entry.Id}\").ToList")));

                var manySeqSelector = G.PropertyDeclaration(entry.Keyword + "_", G.IdentifierName($"List<{className}>"),
                                                            Accessibility.Public, DeclarationModifiers.ReadOnly, new[] { propGetManySeqStatements });

                seqSelectors.Add(manySeqSelector);

                // forge
                var forgeStatements = new[]
                {
                    G.AssignmentStatement(G.IdentifierName("var element"), G.ObjectCreationExpression(G.IdentifierName(className))),
                    G.AssignmentStatement(G.IdentifierName("element.Tag"), G.ObjectCreationExpression(G.IdentifierName("Tag"), G.Argument(RefKind.None, G.LiteralExpression(entry.Id)))),
                    G.AssignmentStatement(G.IdentifierName("element.Data_"), G.IdentifierName("data?.ToList()")),
                    G.ReturnStatement(G.IdentifierName("element"))
                };

                var forgeMethod = G.MethodDeclaration(entry.Keyword, new[] { node },
                                                      null,
                                                      G.IdentifierName(className),
                                                      Accessibility.Public,
                                                      DeclarationModifiers.Static,
                                                      forgeStatements);

                forgeNodes.Add(forgeMethod);
            }

            CodeGenHelper.PublicStaticClassFull(typeof(DICOMForge), forgeNodes)
            .WriteOut("DICOMForge.cs");

            CodeGenHelper.PublicStaticClassFull(typeof(TagHelper), tags)
            .WriteOut("TagHelper.cs");

            CodeGenHelper.PublicPartialClassFull(typeof(DICOMSelector), selectors)
            .WriteOut("DICOMSelectorProperties.cs");

            G.ClassDeclaration(typeof(SequenceSelector).Name,
                               null,
                               Accessibility.Public,
                               DeclarationModifiers.Partial,
                               G.IdentifierName("AbstractElement<DICOMSelector>"),
                               null,
                               seqSelectors)
            .AddNamespace(typeof(SequenceSelector).Namespace)
            .AddImports()
            .WriteOut("SequenceSelectorProperties.cs");
        }