「FileData.cs」ファイルでプロパティを宣言しました。別のクラス「PdfMergerViewModel.cs」の各プロパティに値を割り当てたい。
FileData.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」ファイルの1行は次のようになります。
"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」オブジェクトの代わりに、値を割り当てる必要があります。値の割り当て方がわかりません。解決策を教えてください。ありがとう。