简体   繁体   English

Web API对象共享

[英]Web API object sharing

I have a problem with my objects. 我的物体有问题。

I used to have two objects that were mostly the same but one had some extra fields, so I merged them into one. 我曾经有两个几乎相同的对象,但是一个对象有一些额外的字段,因此我将它们合并为一个。

Now the problem I am having is that when I do my web api documentation using swagger it is displaying the entire object, but for some calls I only want to use part of the object. 现在,我遇到的问题是,当我使用swagger处理Web api文档时,它会显示整个对象,但是对于某些调用,我只想使用对象的一部分。

My question is, if I have one object with the base values, is it possible to make another object use the base object as a starting point/reference from which I can add the extra values I require ? 我的问题是,如果我有一个带有基值的对象,是否可以使另一个对象将基对象用作起点/参考,从中可以添加所需的额外值?

The answer for your question is in OOP, inheritance 您问题的答案是在OOP,继承中

public class FirstClass
{
    public string Property1 { get; set; }
}

public class SecondClass : FirstClass
{
    public string Property2 { get; set; }
}

SecondClass will have both Property1 and Property2 SecondClass将同时具有Property1和Property2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM