英文:
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<string, FilterMetadata> Filters { get; set; }
Which you can access using the indexer access
var value = Filters["SomeKey"];
or by using the TryGetValue method.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论