kontent-ai / model-generator-net

Kontent.ai .NET model generator.
https://www.nuget.org/packages/Kontent.Ai.ModelGenerator
MIT License
17 stars 19 forks source link

(v10.0.0 compat) ICodeFirstTypeProvider does not exist in KenticoCloud.Delivery #87

Closed Gerfaut closed 5 years ago

Gerfaut commented 5 years ago

Brief bug description

After generating models, the CustomTypeProvider is still implementing the removed interface ICodeFirstTypeProvider.

Repro steps

Using following command CloudModelGenerator.exe --projectid "MYAPPID" --namespace "Kentico.Cloud.Starter.Infra.KCloud.Models" --outputdir "Kentico.Cloud.Starter.Infra\KCloud\Models" --baseclass "BaseModel"

The following class is not compiling anymore:

using System;
using System.Collections.Generic;
using System.Linq;
using KenticoCloud.Delivery;

namespace Kentico.Cloud.Starter.Infra.KCloud.Models
{
    public class CustomTypeProvider : ICodeFirstTypeProvider
    {
        private static readonly Dictionary<Type, string> _codenames = new Dictionary<Type, string>
        {
            {typeof(AboutUs), "about_us"},
            {typeof(Accessory), "accessory"},
            {typeof(Article), "article"},
            {typeof(Brewer), "brewer"},
            {typeof(Cafe), "cafe"},
            {typeof(Coffee), "coffee"},
            {typeof(FactAboutUs), "fact_about_us"},
            {typeof(Grinder), "grinder"},
            {typeof(HeroUnit), "hero_unit"},
            {typeof(Home), "home"},
            {typeof(HostedVideo), "hosted_video"},
            {typeof(Office), "office"},
            {typeof(Tweet), "tweet"}
        };

        public Type GetType(string contentType)
        {
            return _codenames.Keys.FirstOrDefault(type => GetCodename(type).Equals(contentType));
        }

        public string GetCodename(Type contentType)
        {
            return _codenames.TryGetValue(contentType, out var codename) ? codename : null;
        }
    }
}

Expected behavior

The class should be generated using ITypeProvider instead of ICodeFirstTypeProvider

Test environment

Thanks a lot !

Gerfaut

Gerfaut commented 5 years ago

Great, thanks a lot! And thanks for the merge 👍