-
Notifications
You must be signed in to change notification settings - Fork 60
Closed
Description
Hi,
We have a serializer that converts some C# dictionaries to Maps, and some lists to Sets.
CustomTypeMappings doesn't seem to handle dictionaries (or any other generic type).
Steps to reproduce
Compile the following and run dotnet-typegen:
public class MyClass1
{
public Dictionary<string, MyClass2> MyDictionary { get; set; }
}
public class MyClass2
{
public string MyNullableProperty { get; set; }
}
public class ModelAssemblyGenerationSpec : GenerationSpec
{
public override void OnBeforeGeneration(OnBeforeGenerationArgs args)
{
// "System.Collections.Generic.Dictionary`2"
args.GeneratorOptions.CustomTypeMappings.Add(typeof(Dictionary<,>).FullName, "Map<>");
AddClass<MyClass1>();
AddClass<MyClass2>();
}
}Expected
import { MyClass2 } from "./my-class2";
export class MyClass1 {
myDictionary: Map<string,MyClass2>;
}Actual
import { MyClass2 } from "./my-class2";
export class MyClass1 {
myDictionary: { [key: string]: MyClass2; };
}Notes
Sure enough, CustomTypeMappings is only used for simple types at this point (TypeGen.Core/Generator/Services/TypeService.cs#L44).
Would you be interested in one or more pull requests to add dictionaries, collections, and improve generic types support ?
Cheers !
Metadata
Metadata
Assignees
Labels
No labels