示例#1
0
        internal AssociationBuilder(ModelBuildingOptions options, CimTypeDeclaration declaration, IDictionary <string, CimTypeDeclaration> typeRepository)
        {
            _options        = options;
            _declaration    = declaration;
            _typeRepository = typeRepository;

            var keyProperties = declaration.Properties.Where(p => p.IsKey()).ToList();

            if (keyProperties.Count == 0)
            {
                keyProperties = declaration.Properties.Where(p => p.IsReference()).ToList();
            }
            if (keyProperties.Count != 2)
            {
                throw new NotSupportedException($"{_declaration.Name} association type should have 2 key properties. Got {keyProperties.Count}");
            }
            _sourceProperty = keyProperties[0];
            _targetProperty = keyProperties[1];
        }
示例#2
0
        internal void Build()
        {
            var typeDeclMap = new Dictionary <string, CimTypeDeclaration>();

            foreach (var c in _cimSession.EnumerateClasses(_cimNamespace))
            {
                var typeDecl = new CimTypeDeclaration(c);
                typeDeclMap.Add(typeDecl.Name, typeDecl);
            }

            var toRemove = new List <string>();

            foreach (var kvp in typeDeclMap)
            {
                if (kvp.Value.IsAssociation)
                {
                    if (!kvp.Value.IsAbstract)
                    {
                        try
                        {
                            var associationBuilder = new AssociationBuilder(_options, kvp.Value, typeDeclMap);
                            associationBuilder.Build();
                        }
                        catch (Exception ex)
                        {
                            _options.Error.WriteLine(ex.Message);
                        }
                    }
                }

                var classBuilder = new ClassBuilder(_options, kvp.Value, typeDeclMap);
                classBuilder.Build();
            }
            foreach (var r in toRemove)
            {
                typeDeclMap.Remove(r);
            }
            BuildFactoryClass(typeDeclMap);
            BuildSimCimScopeExtensions(typeDeclMap);
        }
示例#3
0
 private ExpressionSyntax GenerateTypeMapInitializerExpression(CimTypeDeclaration value)
 {
     return(SyntaxFactory.ParseExpression($"{{ typeof({value.CSharpName}), \"{value.Name}\"}}"));
 }
示例#4
0
 private SwitchSectionSyntax GenerateSwitchCase(CimTypeDeclaration value)
 {
     return(SyntaxFactory.SwitchSection()
            .AddLabels(SyntaxFactory.CaseSwitchLabel(SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal(value.Name))))
            .AddStatements(SyntaxFactory.ParseStatement($"return new {value.CSharpName}(scope, cimInstance);")));
 }
示例#5
0
 public ClassBuilder(ModelBuildingOptions options, CimTypeDeclaration declaration, IDictionary <string, CimTypeDeclaration> typeRepository)
 {
     _options        = options;
     _declaration    = declaration;
     _typeRepository = typeRepository;
 }