コード例 #1
0
        internal ClassCodeGenerator GetClassCodeGenerator(ContentTypeModel contentType, IEnumerable <ContentTypeSnippetModel> managementSnippets)
        {
            var classDefinition = new ClassDefinition(contentType.Codename);

            foreach (var element in contentType.Elements)
            {
                try
                {
                    if (element.Type != ElementMetadataType.ContentTypeSnippet)
                    {
                        AddProperty(Property.FromContentTypeElement(element), ref classDefinition);
                    }
                    else
                    {
                        var snippetElements = ManagementElementHelper.GetManagementContentTypeSnippetElements(element, managementSnippets);
                        foreach (var snippetElement in snippetElements)
                        {
                            AddProperty(Property.FromContentTypeElement(snippetElement), ref classDefinition);
                        }
                    }
                }
                catch (Exception e)
                {
                    WriteConsoleErrorMessage(e, element.Codename, element.Type.ToString(), classDefinition.ClassName);
                }
            }

            var classFilename = GetFileClassName(classDefinition.ClassName);

            return(ClassCodeGeneratorFactory.CreateClassCodeGenerator(Options, classDefinition, classFilename));
        }
コード例 #2
0
        protected ClassCodeGenerator GetCustomClassCodeGenerator(string contentTypeCodename)
        {
            var classDefinition = new ClassDefinition(contentTypeCodename);
            var classFilename   = $"{classDefinition.ClassName}";

            return(ClassCodeGeneratorFactory.CreateClassCodeGenerator(Options, classDefinition, classFilename, true));
        }
コード例 #3
0
        public void CreateClassCodeGenerator_PartialClassCodeGenerator_Returns(bool managementApi)
        {
            var classDefinitionCodename = "codename";
            var classFileName           = "classFileName";
            var codeGeneratorOptions    = new CodeGeneratorOptions
            {
                ManagementApi = managementApi
            };

            var result = ClassCodeGeneratorFactory.CreateClassCodeGenerator(codeGeneratorOptions, new ClassDefinition(classDefinitionCodename), classFileName, true);

            AssertClassCodeGenerator <PartialClassCodeGenerator>(result, classDefinitionCodename, classFileName, ClassCodeGenerator.DefaultNamespace);
        }
コード例 #4
0
        public void CreateClassCodeGenerator_DeliveryClassCodeGenerator_NoCustomPartialProperty_Returns()
        {
            var classDefinitionCodename = "codename";
            var classFileName           = "classFileName";
            var codeGeneratorOptions    = new CodeGeneratorOptions
            {
                ManagementApi = false
            };

            var result = ClassCodeGeneratorFactory.CreateClassCodeGenerator(codeGeneratorOptions, new ClassDefinition(classDefinitionCodename), classFileName);

            AssertClassCodeGenerator <DeliveryClassCodeGenerator>(result, classDefinitionCodename, classFileName, ClassCodeGenerator.DefaultNamespace);
        }
コード例 #5
0
        public void CreateClassCodeGenerator_DeliveryClassCodeGenerator_CustomNamespace_Returns()
        {
            var classDefinitionCodename = "codename";
            var classFileName           = "classFileName";
            var customNamespace         = "CustomNameSpace";
            var codeGeneratorOptions    = new CodeGeneratorOptions
            {
                ManagementApi = false,
                Namespace     = customNamespace
            };

            var result = ClassCodeGeneratorFactory.CreateClassCodeGenerator(codeGeneratorOptions, new ClassDefinition(classDefinitionCodename), classFileName);

            AssertClassCodeGenerator <DeliveryClassCodeGenerator>(result, classDefinitionCodename, classFileName, customNamespace);
        }
コード例 #6
0
        internal ClassCodeGenerator GetClassCodeGenerator(IContentType contentType)
        {
            var classDefinition = new ClassDefinition(contentType.System.Codename);

            foreach (var element in contentType.Elements.Values)
            {
                try
                {
                    var elementType = DeliveryElementHelper.GetElementType(Options, element.Type);
                    var property    = Property.FromContentTypeElement(element.Codename, elementType);
                    AddProperty(property, ref classDefinition);
                }
                catch (Exception e)
                {
                    WriteConsoleErrorMessage(e, element.Codename, element.Type, classDefinition.ClassName);
                }
            }

            TryAddSystemProperty(classDefinition);

            var classFilename = GetFileClassName(classDefinition.ClassName);

            return(ClassCodeGeneratorFactory.CreateClassCodeGenerator(Options, classDefinition, classFilename));
        }
コード例 #7
0
 public void CreateClassCodeGenerator_ClassFilenameIsNull_ThrowsException()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           ClassCodeGeneratorFactory.CreateClassCodeGenerator(new CodeGeneratorOptions(), new ClassDefinition("codename"), null));
 }