reinforced-typings

configuring reinforced-typings to extend a class unrelated to server inheritence pattern


I have a simple DTO like so

public class MyDTO {
   public string Name {get; set;}
}

I wish all my typescript interfaces used by the client to have the properties of MyDTO on the server, and also extend BreezeJS entity type. that is, the output for the typescript file should become

export interface IMyDTO extends breeze.Entity {
    name: string
}

But the server/ .NET type is a simple POCO (i.e. does not derive from any classes), because the members of the BreezeJS.Entity type purely relate to managing the entities on the client/in an ECMAScript environment.

How do I achieve this with Reinforced.Typings fluent API?


Solution

  • Consider using following code generator:

    public class BreezeCodeGenerator : InterfaceCodeGenerator
    {
    
        private static readonly RtSimpleTypeName BreezeBase = new RtSimpleTypeName("breeze.Entity");
    
        public override RtInterface GenerateNode(Type element, RtInterface result, TypeResolver resolver)
        {
            var b = base.GenerateNode(element, result, resolver);
            if (b == null) return null;
            b.Implementees.Add(BreezeBase);
            return b;
        }
    }
    

    And apply it to your POCOs as follows:

    public static void Configure(ConfigurationBuilder builder)
    {
        builder.ExportAsInterfaces(
            //or generate IEnumerable of desired POCO types somehow else
            new[] { typeof(BreezeEntity1), typeof(BreezeEntity2) }
            ,
            d => d.WithPublicProperties().WithCodeGenerator<BreezeCodeGenerator>());
    
    }