c# - 构造函数重载隐藏 PowerShell 中的属性
问题描述
我有一个有两个不同构造函数的类,它有 4 个属性。出于我们的目的,它看起来类似于以下内容:
class Book
{
public string Title { get; set; }
public string Author { get; set; }
public string Publisher { get; set; }
public int PubDate { get; set; }
public Book(string title, string author)
{
Title = title;
Author = author;
}
public Book(string title, string author, string publisher, int pubDate)
{
Title = title;
Author = author;
Publisher = publisher;
PubDate = pubDate;
}
}
当用户只传入两个参数时,第一个构造函数在技术上应该创建对象。
我遇到的问题是,我想在 PowerShell 中使用用于实例化它的任何参数来显示该对象,例如,仅使用 Title 和 Author 实例化的 Book,应仅在终端中显示 Book 的 Title 和 Author。
我正在研究使用format.ps1xml来格式化它。
解决方案
推荐阅读
- python - 相互引用的两个模型字段 - django rest
- ruby-on-rails - Rails 6 - 将 URL 中 root_path 的参数更改为 SEO 友好的 URL
- go - 我运行我的代码,文件被标记为脏。我该如何解决?
- reactjs - 数据更新时如何呈现项目反应本机
- c++ - 如何使分组框的大小和布局的内容统一
- python - 数组中的相同值排序为多个数组,排序复制到第二个数组
- ip-camera - 谷歌助手说“抱歉,相机似乎不支持流式传输到远程屏幕”
- java - 如何更改 void 方法中的响应状态(不返回 ResponseEntity)?
- python - 如何按小时分组一周中的每一天?
- php - 新用户注册和购买会员时自动创建日历