Typelite: Why is Dictionary mapped to KeyValuePair and not to any or [index:string]:any

前端 未结 3 1224
遥遥无期
遥遥无期 2021-02-14 21:16

I have a class,

public class Instance : IResource
{
   public Dictionary Value { get; set; }

and it is mapped to

<
3条回答
  •  独厮守ぢ
    2021-02-14 21:49

    A quick and dirty workaround is to use a regex to alter output:

    Using

    <#= Regex.Replace( ts.Generate(TsGeneratorOutput.Properties)
            , @":\s*System\.Collections\.Generic\.KeyValuePair\<(?[^\,]+),(?[^\,]+)\>\[\];"
            , m=>": {[key: "+m.Groups["k"].Value+"]: "+m.Groups["v"].Value+"};"
            , RegexOptions.Multiline)
    #>
    

    Transforms a field

        myField: System.Collections.Generic.KeyValuePair[];
    

    to

        myField: {[key: string]: OtherClass};
    

提交回复
热议问题