c# - 如何检查类中的对象是否不为空
问题描述
我有一个配置文件,其中包含有关不同数据库的详细信息,我正在阅读该文件,并且我为文件中的每个对象定义了模型(见下文)
我的配置文件:
{
"DatabaseSettings": {
"Database": "db_Test",
"Collection": "apptests",
"Instance": "https://cosmos-tables.documents.azure.com:443/",
"Key": "4c6ykE3Sutest=="
},
"TableSettings": {
"AzureTable": {
"Account": "testables",
"Table": "atest",
"Key": "test===="
}
}
我的代码模型:
public class CosmosDbSettings
{
public string Database { get; set; }
public string Collection { get; set; }
public string Instance { get; set; }
public string Key { get; set; }
}
public class AzureTableSettings
{
public string Account { get; set; }
public string Key { get; set; }
public string Table { get; set; }
}
public class MyClass
{
public AzureTableSettings TableSettings { get; set; }
public CosmosDbSettings DatabaseSettings { get; set; }
}
现在我想检查我的 C# 方法,如果我在 CosmosDbSettings 类中的对象不为空,即我正在检查我的配置文件是否有 DatabseSettings 条目并且它们不为空或为空。我怎样才能检查这个?一种方法是检查每个对象是否 NullorEmpty() 但我相信有更好的方法可以做到这一点,我正在寻找一些帮助。
谢谢
解决方案
推荐阅读
- identityserver4 - 在 IdentityServer4 中支持核心身份角色
- excel - 如何使用 excel odbc 驱动程序获取仅数字值?
- javascript - 地图功能中箭头功能中的“咖啡”来自哪里?
- architecture - 高可用但一致的 id 生成器
- azure - Kudu git部署无法部署.net core 3.1
- java - 如何在 Spring Data mongoTemplate 中嵌套 sql select?
- c# - 如何使用 C# ITextSharp 区分链接和脚注?
- python - 在数据框中保存随机森林预测
- javascript - 如何在动态创建的 HTML 中使用拖放功能?(SortableJS)
- python - sqlite3.ProgrammingError:提供的绑定数量不正确。当前语句使用 1,并且提供了 0