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)); }
protected ClassCodeGenerator GetCustomClassCodeGenerator(string contentTypeCodename) { var classDefinition = new ClassDefinition(contentTypeCodename); var classFilename = $"{classDefinition.ClassName}"; return(ClassCodeGeneratorFactory.CreateClassCodeGenerator(Options, classDefinition, classFilename, true)); }
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); }
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); }
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); }
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)); }
public void CreateClassCodeGenerator_ClassFilenameIsNull_ThrowsException() { Assert.Throws <ArgumentNullException>(() => ClassCodeGeneratorFactory.CreateClassCodeGenerator(new CodeGeneratorOptions(), new ClassDefinition("codename"), null)); }