如何为自定义集合列表进行字符串比较? [英] How to do string compare for custom collection list?

查看:77
本文介绍了如何为自定义集合列表进行字符串比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个课程:

I have a class:

public class ADClient
       {
           public int InstanceID = 1;
           public string ClientName = "";
           public string HostIP = "";
           public string UserName = "";
           public string Password = "";
           public bool IsPasswordEncrypted = true;
           public string HostFilePath = "";
           public string LocationTrim = "";
           public string ImageVideoPath = "";
           public string DestinationPath = "";
           public string FileType = "";
           public string RenameAfterCopy = "";
           public string BinaryAscii = "";
           public string LogFile = "";
           public int NumberOfDaysToKeepLog = 0;
           public int ADTransactionDays = 0;
           public int Hours = 0;
           public bool ADCleanUp = true;
       }





所有这些都是一些设置。

现在我有另一个功能填充这些设置的值。该函数是:

protected void PopulateDataFromDatabase(RegistrationInfoSettingsDB _regInfoSettingDb)

{

ADClient ad_Client = new ADClient();

string categoryName =Advance Diagnostics;

string settingValue = null;



string settingName = null;



SqlDataReader reader = _regInfoSettingDb.GetRegistrationInfoSetting(categoryName,ad_Client.InstanceID);

while(reader.Read())

{

settingValue = reader.GetValue(1).ToString()。Trim();



settingName = reader.GetValue(2).ToString ().Trim();

}



}



我必须在设置名称和赋值的基础上进行比较。但我不知道如何为自定义集合进行字符串比较。



All these are some settings.
Now I have another function that should populate values for these settings. The function is:
protected void PopulateDataFromDatabase(RegistrationInfoSettingsDB _regInfoSettingDb)
{
ADClient ad_Client = new ADClient();
string categoryName = "Advance Diagnostics";
string settingValue = null;

string settingName = null;

SqlDataReader reader = _regInfoSettingDb.GetRegistrationInfoSetting(categoryName, ad_Client.InstanceID);
while (reader.Read())
{
settingValue = reader.GetValue(1).ToString().Trim();

settingName = reader.GetValue(2).ToString().Trim();
}

}

I have to compare on the basis of setting name and assign value. But i don't know how to do a string comparison for custom collection.

推荐答案

不要。

你可以做到 - 反射将得到属性名称和数据类型 - 但它会缓慢而笨拙,并不是特别明显。

相反,使用编译时名称直接填充属性:

Don't.
You can do it - Reflection will get the the property names and datatypes - but it'll be slow and awkward, and not particularly obvious.
Instead, fill the properties directly using compile time names:
DestinationPath = (string) reader["DestinationPath"];

它会更清楚,它意味着如果有人在以后添加列或计算属性,您的代码不会失败,并且它允许DB列独立于类属性移动。

It'll be clearer, it'll mean your code doesn't fail if someone adds a column or a "calculated property" later, and it allows the DB columns to move around independently of the class properties.


这篇关于如何为自定义集合列表进行字符串比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆