Example #1
0
        public void GenerateTypeProvider()
        {
            // Make sure the output dir exists
            Directory.CreateDirectory(_options.OutputDir);

            var classCodeGenerators       = GetClassCodeGenerators();
            var typeProviderCodeGenerator = new TypeProviderCodeGenerator(_options.Namespace);

            foreach (var codeGenerator in classCodeGenerators)
            {
                typeProviderCodeGenerator.AddContentType(codeGenerator.ClassDefinition.Codename, codeGenerator.ClassDefinition.ClassName);
            }

            var typeProviderCode = typeProviderCodeGenerator.GenerateCode();

            if (!string.IsNullOrEmpty(typeProviderCode))
            {
                SaveToFile(typeProviderCode, TypeProviderCodeGenerator.CLASS_NAME);
                Console.WriteLine($"{TypeProviderCodeGenerator.CLASS_NAME} class was successfully created.");
            }
            else
            {
                Console.WriteLine($"{TypeProviderCodeGenerator.CLASS_NAME} class was not created.");
            }
        }
Example #2
0
        public void GenerateTypeProvider()
        {
            // Make sure the output dir exists
            Directory.CreateDirectory(_options.OutputDir);

            var classCodeGenerators = GetClassCodeGenerators();

            if (classCodeGenerators.Count() > 0)
            {
                var typeProviderCodeGenerator = new TypeProviderCodeGenerator(_options.Namespace);

                foreach (var codeGenerator in classCodeGenerators)
                {
                    typeProviderCodeGenerator.AddContentType(codeGenerator.ClassDefinition.Codename, codeGenerator.ClassDefinition.ClassName);
                }

                var typeProviderCode = typeProviderCodeGenerator.GenerateCode();
                if (!string.IsNullOrEmpty(typeProviderCode))
                {
                    SaveToFile(typeProviderCode, TypeProviderCodeGenerator.CLASS_NAME);
                    Console.WriteLine($"{TypeProviderCodeGenerator.CLASS_NAME} class was successfully created.");
                }
            }
            else
            {
                Console.WriteLine($@"No content type available for the project ({_options.DeliveryOptions.ProjectId}). Please make sure you have the Delivery API enabled at https://app.kenticocloud.com/.");
            }
        }