简体   繁体   English

是否可以引用未在.nswag文件中定义的C#类?

[英]Is it possible to reference a C# class that's not defined in a .nswag file?

I have a .Net Core project with multiple APIs that are generated by using Swagger (Nswag). 我有一个.Net Core项目,具有使用Swagger(Nswag)生成的多个API。 I also have a few projects that contain shared classes that are used in multiple of the APIs and are not generated. 我也有一些项目,这些项目包含在多个API中使用但未生成的共享类。

Now I want one generated controller method to return an object of a type that's specified in one of these model projects and written by myself (not generated by Swagger) 现在,我希望一个生成的控制器方法返回一个在这些模型项目之一中指定并由我自己编写的类型的对象(不是由Swagger生成)

Is this even possible and, if yes, how can I achieve it? 这是否有可能,如果可以,我将如何实现?

您可以从生成中排除一些dto(我认为是它的ExcludedTypes设置),然后在您的命名空间中添加using(AdditionalNamespaceUsages)

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

相关问题 C# OpenApi Nswag 客户端生成复合体 Class 为空 - C# OpenApi Nswag Client Generation Complex Class is empty C# 带有 NSwag 的多态模型 - C# Polymorphic models with NSwag 是否可以在 C# 中使用 C++/CLI 类中定义的实例? - Is it possible to use the instance defined in C++/CLI class in C#? 派生类是否有可能持有对C#中现有基类的引用? - Is it possible for a derived class to hold a reference to an existing base class in C#? 是否可以使用C#中的索引引用类成员变量? - Is it possible to reference class member variables using an index in C#? 可以将变量的引用保存在 c# 中的另一个变量中吗? - It is possible to save a variable's reference inside another variable in c#? 在 NSwag 中是否可以只生成 C# 客户端接口并使用一些自定义属性注释它们的方法? - Is it possible in NSwag to generate just C# client interfaces and annotate their methods with some custom attributes? 使用NSwag和C#对控制器名称或标签进行排序 - Sort on controller name or tag with NSwag and C# C# NSwag 和带有枚举的 swagger-codegen - C# NSwag and swagger-codegen with Enums CodeGo.net>如何获取对A类内的对象A的引用? - c# - How to get reference to object A inside A's class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM