我在“FileData.cs”文件中声明了属性。我想为另一个类“PdfMergerViewModel.cs”中的每个属性分配值。
文件数据.cs
public class FileData
{
private BatchData _batch;
public FileData(BatchData batch)
{
this._batch = batch;
}
public string FileName { get; set; }
public string VersionNormalizedFileName { get; set; }
public string OrderNumber { get; set; }
public DateTime OrderDate { get; set; }
public string Metadata { get; private set; }
public bool IsDeleted { get; set; }
public string FilePath { get; set; }
public string Centerpoint { get; set; }
public string BatchID { get; set; }
public string RegionalPrefix { get; set; }
public string City { get; set; }
public string FunctionLocation { get; set; }
public string KeyMap { get; set; }
public string State { get; set; }
public string StreetNumber { get; set; }
public string StreetName { get; set; }
public string UnitNumber { get; set; }
public string SendToGIS { get; set; }
public string PipeBeforeFilename { get; set; }
public IList<FileData> VersionFiles
{
get
{
return _batch.Files.Where(x => x.VersionNormalizedFileName == FileName && !x.IsDeleted).ToList();
}
private set { }
}
PdfMergerViewModel.cs
FileData fd = new FileData(new BatchData());
void createOutputBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
using (StreamReader sr = File.OpenText("D:/data.txt"))
{
String input;
while ((input = sr.ReadLine()) != null)
{
string[] stringArray = input.Split(',');
for (int i = 0; i < stringArray.Count() - 1; i++)
{
}
}
}
}
我需要将“fd”对象放在 for 循环中,并为“FileData.cs”中的每个属性分配值。我不知道如何分配价值。给我一个解决方案。谢谢。
“Data.Txt”文件中存在多行。“Data.txt”文件中的一行如下所示:
"Centerpoint - Arkansas (Fixed)","Centerpoint SO - Arkansas","{$DOCUMENT ID}","61||","{$BATCH ID}","32601","{$REGIONAL PREFIX}","E","CITY","CUSHING","DATE","05/25/1945","FUNCTION LOCATION","X-SVCS","KEY MAP","","ORDER NUMBER","","STATE","AR","STREET NUMBER","819","STREET NAME","E BROADWAY","UNIT NUMBER","","SEND TO GIS","X","{$PIPE BEFORE FILENAME}","||","\\HOUKOFAX01\Client\Centerpoint Arkansas\7_9_2012\32601\819 E BROADWAY.pdf"
以前使用“字典”。现在我们正在转向面向对象的方法。当存在字典项时使用以下代码。现在,我需要使用面向对象的方法来分配“FileData.cs”类中的值,而不是字典。使用字典项的代码:
Dictionary<string, string> item = new Dictionary<string, string>();
for (int i = 0; i < stringArray.Count() - 1; i++)
{
item.Add(RemoveQuote(stringArray[i]), RemoveQuote(stringArray[i + 1]));
i++;
}
我需要分配值而不是字典“fd”对象。我不知道如何分配价值。给我一个解决方案。谢谢。