在C#中创建TS Index Signatures对象的模型。

huangapple go评论48阅读模式
英文:

Create model in C# for TS Index Signatures object

问题

我正在尝试为这样的请求在C#中创建模型。我不确定如何在C#中构建filter属性?在C#中,如何实现TS的索引签名?

来自typescriptlang
索引签名
有时,您不提前知道类型的属性名称,但您知道值的形状。
在这种情况下,您可以使用索引签名来描述可能值的类型。

英文:

My angular fronend sending to .net core contoler object with index signature object.
Something like

export interface LazyLoadEvent {
    first?: number;
    rows?: number;
    filters?: {
        [s: string]: FilterMetadata;
    };
    
}
export interface FilterMetadata {
    value?: any;
    matchMode?: string;
    operator?: string;
}

I am trying create models in C# for request like this.
I am confused how I construct property filter in C# ?
What would be the equivalent of TS Index Signatures implantation in C# ?

From typescriptlang
Index Signatures
Sometimes you don’t know all the names of a type’s properties ahead of time, but you do know the shape of the values.
In those cases you can use an index signature to describe the types of possible values

答案1

得分: 1

你可以使用一个字典

Dictionary<string, FilterMetadata> Filters { get; set; }

你可以使用索引器来访问它

var value = Filters["SomeKey"];

或者使用 TryGetValue 方法。

英文:

You could use a Dictionary

Dictionary&lt;string, FilterMetadata&gt; Filters { get; set; }

Which you can access using the indexer access

var value = Filters[&quot;SomeKey&quot;];

or by using the TryGetValue method.

huangapple
  • 本文由 发表于 2023年2月16日 17:58:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75470576.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定