这个问题是这个问题的副产品(Can this method be refactored to use a lamba?).在对这一问题的评论中,有人提出:
重构需要在不同的地方完成。糟糕的不是你的功能,而是
CLMExplorerHistory的定义。
内部数据结构不需要以1:1的方式表示CSV文件的结构。只要确保你能以一种兼容的方式读写。
我认为,您正在尝试直接使用csv数据结构,而不是考虑可能的复制区域,这些区域将指明实现类类型的明显位置,以便允许代码重用。你能为你的CSV文件张贴一个示例数据片段来指出你的起点吗?
在这些注释的后端,下面是示例CSV数据的片段:
Date,Status,Weekly Bible Reading,Song1 #,Song1 Title,Song1 Scripture,Song2 #,Song2 Title,Song2 Scripture,Song3 #,Song3 Title,Song3 Scripture,Meeting?,CO Visit,Cancel Reason,# Classes,Chairman,PrayerOpen,PrayerClose,TreasuresTalk,TreasuresTalk_Theme,TreasuresDigging,BibleReading_A,BibleReading_Study_A,BibleReading_B,BibleReading_Study_B,BibleReading_C,BibleReading_Study_C,BibleReading_Source,Apply1_Description,Apply2_Description,Apply3_Description,Apply4_Description,Apply1_A,Apply1_Asst_A,Apply1_Study_A,Apply2_A,Apply2_Asst_A,Apply2_Study_A,Apply3_A,Apply3_Asst_A,Apply3_Study_A,Apply4_A,Apply4_Asst_A,Apply4_Study_A,Apply1_B,Apply1_Asst_B,Apply1_Study_B,Apply2_B,Apply2_Asst_B,Apply2_Study_B,Apply3_B,Apply3_Asst_B,Apply3_Study_B,Apply4_B,Apply4_Asst_B,Apply4_Study_B,Apply1_C,Apply1_Asst_C,Apply1_Study_C,Apply2_C,Apply2_Asst_C,Apply2_Study_C,Apply3_C,Apply3_Asst_C,Apply3_Study_C,Apply4_C,Apply4_Asst_C,Apply4_Study_C,LivingPart1,LivingPart1_Theme,LivingPart1_Length,LivingPart2,LivingPart2_Theme,LivingPart2_Length,CBS,CBS_Source,CBS_Read,Audience B,Audience C,AuxCounselor B,AuxCounselor C
01/03/2021,Registrato e completo,NUMERI 7-8,4,“Geova è il mio Pastore”,Salmo 23,54,“Questa è la via”,"Isaia 30:20, 21",127,Che tipo di persona sono?,2 Pietro 3:11,Y,N,,1,Italo De Gaeta,xxx,xxx,xxx,“L’accampamento d’Israele: lezioni utili”,xxx,xxx,5,,,,,Nu 7:1-17,Commemorazione,Visita ulteriore,Visita ulteriore,Visita ulteriore,xxx,xxx,11,xxx,xxx,6,xxx,xxx,12,xxx,xxx,17,,,,,,,,,,,,,,,,,,,,,,,,,xxx,Risultati raggiunti dall’organizzazione,(5 min),xxx,Bisogni locali,(10 min),xxx,"rr cap. 5 parr. 17-22, riquadro 5A",xxx,,,,我使用CsvReader类将其读入CLMExplorerHistory对象。类的定义如下:
public class CLMExplorerHistory
{
[Format("dd/MM/yyyy")]
[Name("Date")]
public DateTime Date { get; set; }
[BooleanFalseValues(new string[] { "N", "n" })]
[BooleanTrueValues(new string[] { "Y", "y" })]
[Name("Meeting?")]
public bool Meeting { get; set; }
[Name("# Classes")]
public int Classes { get; set; }
[Name("Chairman")]
public string Chairman { get; set; }
[Name("AuxCounselor B")]
public string AuxCounsellor1 { get; set; }
[Name("AuxCounselor C")]
public string AuxCounsellor2 { get; set; }
[Name("PrayerOpen")]
public string PrayerOpen { get; set; }
[Name("PrayerClose")]
public string PrayerClose { get; set; }
[Name("CBS")]
public string CBSConductor { get; set; }
[Name("CBS_Read")]
public string CBSReader { get; set; }
[Name("TreasuresTalk")]
public string TreasuresTalkName { get; set; }
[Name("TreasuresTalk_Theme")]
public string TreasuresTalkTheme { get; set; }
[Name("TreasuresDigging")]
public string SpiritualGemsName { get; set; }
[Name("LivingPart1")]
public string LivingPart1Name { get; set; }
[Name("LivingPart1_Theme")]
public string LivingPart1Theme { get; set; }
[Name("LivingPart2")]
public string LivingPart2Name { get; set; }
[Name("LivingPart2_Theme")]
public string LivingPart2Theme { get; set; }
[Name("BibleReading_A")]
public string BibleReadingClass1Name { get; set; }
[Name("BibleReading_B")]
public string BibleReadingClass2Name { get; set; }
[Name("BibleReading_C")]
public string BibleReadingClass3Name { get; set; }
[Name("BibleReading_Study_A")]
public string BibleReadingStudy { get; set; }
[Name("Apply1_Description")]
public string StudentItem1Description { get; set; }
[Name("Apply2_Description")]
public string StudentItem2Description { get; set; }
[Name("Apply3_Description")]
public string StudentItem3Description { get; set; }
[Name("Apply4_Description")]
public string StudentItem4Description { get; set; }
[Name("Apply1_A")]
public string StudentItem1Class1StudentName { get; set; }
[Name("Apply1_B")]
public string StudentItem1Class2StudentName { get; set; }
[Name("Apply1_C")]
public string StudentItem1Class3StudentName { get; set; }
[Name("Apply1_Asst_A")]
public string StudentItem1Class1AssistantName { get; set; }
[Name("Apply1_Asst_B")]
public string StudentItem1Class2AssistantName { get; set; }
[Name("Apply1_Asst_C")]
public string StudentItem1Class3AssistantName { get; set; }
[Name("Apply2_A")]
public string StudentItem2Class1StudentName { get; set; }
[Name("Apply2_B")]
public string StudentItem2Class2StudentName { get; set; }
[Name("Apply2_C")]
public string StudentItem2Class3StudentName { get; set; }
[Name("Apply2_Asst_A")]
public string StudentItem2Class1AssistantName { get; set; }
[Name("Apply2_Asst_B")]
public string StudentItem2Class2AssistantName { get; set; }
[Name("Apply2_Asst_C")]
public string StudentItem2Class3AssistantName { get; set; }
[Name("Apply3_A")]
public string StudentItem3Class1StudentName { get; set; }
[Name("Apply3_B")]
public string StudentItem3Class2StudentName { get; set; }
[Name("Apply3_C")]
public string StudentItem3Class3StudentName { get; set; }
[Name("Apply3_Asst_A")]
public string StudentItem3Class1AssistantName { get; set; }
[Name("Apply3_Asst_B")]
public string StudentItem3Class2AssistantName { get; set; }
[Name("Apply3_Asst_C")]
public string StudentItem3Class3AssistantName { get; set; }
[Name("Apply4_A")]
public string StudentItem4Class1StudentName { get; set; }
[Name("Apply4_B")]
public string StudentItem4Class2StudentName { get; set; }
[Name("Apply4_C")]
public string StudentItem4Class3StudentName { get; set; }
[Name("Apply4_Asst_A")]
public string StudentItem4Class1AssistantName { get; set; }
[Name("Apply4_Asst_B")]
public string StudentItem4Class2AssistantName { get; set; }
[Name("Apply4_Asst_C")]
public string StudentItem4Class3AssistantName { get; set; }
[Name("Apply1_Study_A")]
public string StudentItem1Study { get; set; }
[Name("Apply2_Study_A")]
public string StudentItem2Study { get; set; }
[Name("Apply3_Study_A")]
public string StudentItem3Study { get; set; }
[Name("Apply4_Study_A")]
public string StudentItem4Study { get; set; }
}我在CSV文件中读到这样的内容:
using (var reader = new StreamReader(_calendarDBPath))
using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
{
var records = csv.GetRecords<CLMExplorerHistory>();
foreach (var record in records)
{
...目前,CSV记录被读取到这个公共属性列表中。我想知道它是否能直接将字段读入一个更复杂的对象中?
具体来说,# Classes字段的值为1、2或3,对于每个类(不是C#类--想想学校)都有类似的数据。
每堂课有4个项目,每节课的描述/学习是相同的。因此,这些CSV字段是常见的:
[Name("Apply1_Description")]
[Name("Apply2_Description")]
[Name("Apply3_Description")]
[Name("Apply4_Description")]
[Name("BibleReading_Study_A")]
[Name("Apply1_Study_A")]
[Name("Apply2_Study_A")]
[Name("Apply3_Study_A")]
[Name("Apply4_Study_A")]但其余的是针对以下三个班级(学校):
[Name("BibleReading_A")]
[Name("Apply1_A")]
[Name("Apply1_Asst_A")]
[Name("Apply2_A")]
[Name("Apply2_Asst_A")]
[Name("Apply3_A")]
[Name("Apply3_Asst_A")]
[Name("Apply4_A")]
[Name("Apply4_Asst_A")][Name("BibleReading_B")]
[Name("Apply1_B")]
[Name("Apply1_Asst_B")]
[Name("Apply2_B")]
[Name("Apply2_Asst_B")]
[Name("Apply3_B")]
[Name("Apply3_Asst_B")]
[Name("Apply4_B")]
[Name("Apply4_Asst_B")][Name("BibleReading_C")]
[Name("Apply1_C")]
[Name("Apply1_Asst_C")]
[Name("Apply2_C")]
[Name("Apply2_Asst_C")]
[Name("Apply3_C")]
[Name("Apply3_Asst_C")]
[Name("Apply4_C")]
[Name("Apply4_Asst_C")]这3个类可以用一个StudentClass中的3个“Lists”对象来表示。有点像
StudentClasses
NumClasses
Item1Desc
Item2Desc
Item3Desc
Item4Desc
BibleReadingStudy
Item1Study
Item2Study
Item3Study
Item4Study
List<StudentClass>
BibleReading
Item1Student
Item1Assistant
Item2Student
Item2Assistant
Item3Student
Item3Assistant
Item4Student
Item4Assistant以上所述是以下列方式建造的:
StudentClasses
NumClasses: # Classes
Item1Desc: Apply1_Description
Item2Desc: Apply2_Description
Item3Desc: Apply3_Description
Item4Desc: Apply4_Description
BibleReadingStudy: BibleReading_Study_A
Item1Study: Apply1_Study_A
Item2Study: Apply2_Study_A
Item3Study: Apply3_Study_A
Item4Study: Apply4_Study_A
List<StudentClass>
BibleReading BibleReading_A|B|C
Item1Student Apply1_A|B|C
Item1Assistant Apply1_Asst_A|B|C
Item2Student Apply2_A|B|C
Item2Assistant Apply2_Asst_A|B|C
Item3Student Apply3_A|B|C
Item3Assistant Apply3_Asst_A|B|C
Item4Student Apply4_A|B|C
Item5Assistant Apply4_Asst_A|B|C现在,您知道了字段到建议对象之间的映射。显然,我可以自己创建这个C#类,并且可以手动地将字段转换到这样的结构中。但是CvsReader有能力像这样直接读入类吗?而不是一大串财产?
发布于 2022-01-13 10:00:04
,但CvsReader有能力直接读入这样的类吗?而不是一大串财产?
我会说“是的”,虽然我不能百分之百地确定你最终希望创造什么,但是你可以通过这些属性来变得可爱。我举一个简单的例子。
假设我们有一个CSV,它列出商店和每个商店需要购买的3种产品。
Shop,Product1,P1Price,Product2,P2Price,Product3,P3Price
Walmart,Eggs,1,Milk,2,Bread,3
BestBuy,PC,4,iPad,5,iPhone,6你可以让你的班级拿着道具:
class ShopLine
{
string Shop {get;set;}
string Product1 {get;set;}
string Product2 {get;set;}
string Product3 {get;set;}
int P1Price {get;set;}
int P2Price {get;set;}
int P3Price {get;set;}
}但是没有人用枪指着你的头说数据存储必须是这样的。你可以:
class Product
{
string Name {get;set;}
int Price {get;set;}
}
class ShopLineTrick
{
string Shop {get;set;}
string Product1 {get => products[0].Name; set => products[0].Name= value;}
string Product2 {get => products[1].Name; set => products[1].Name= value;}
string Product3 {get => products[2].Name; set => products[2].Name= value;}
int P1Price {get => products[0].Price; set => products[0].Price = value;}
int P2Price {get => products[1].Price; set => products[1].Price = value;}
int P3Price {get => products[2].Price; set => products[2].Price = value;}
List<Product> products;
ShopLineTrick(){
//precreate 3 products
products = Enumerable.Range(1,3).Select(x => new Product()).ToList();
}
}在操作结束时,您有一些ShopLineTrick集合,每个集合都包含一些已构建的产品层次结构;Product是一个“来自其他地方的可重用类”,因此这个操作就像一个解析和映射。以前用于接收文件中数据的POCO已经成为能够从其他地方构建较小、可重用类的层次结构的工具。例如,您可以使用LINQ查询以获得它们。
shopLines.SelectMany(sl => sl.Products). // a straight list of every product我已经用另一个例子解释过了,因为我还不太明白您希望用您拥有的数据实现什么:我正在描述一个替代的数据存储,以便您可以将它应用于进一步实现您的目标。例如,对于最近的一个项目,我必须在某个时间点存储属性的每个版本,然后让我没有控制的进程更改对象的一些属性,然后检查更改了什么。这在一个循环中很容易做到,10个属性中的每一个都使用一个object10作为存储。在某个时候,我会克隆数组,让进程改变内容,然后在当前寻找与克隆副本不同的数组条目。使用数组备份属性,通过循环数组使检查(甚至重置/接受更改)变得非常简单。
唯一需要注意的是,某些类型的读取CsvH会重用您传递的对象,因此,如果您正在执行异步读取,请注意,它可以读取文件的所有行,最后只能读取最后一行的数据(提取产品列表,并更新每个循环传递以防止覆盖)。
发布于 2022-01-13 20:48:15
这个答案是基于被接受的答案中的原则。我觉得我应该把它作为对我的具体情况的扩展解释。可能会对别人有帮助。
第一步
我设计了一组课程来代表每周的会议:
public class MSAHistoryItemTalk
{
public string Name { get; set; }
public string Theme { get; set; }
public string Method { get; set; }
}
public class MSAHistoryItemStudent
{
public string Name { get; set; }
public string Assistant { get; set; }
public string Type { get; set; }
public string Study { get; set; }
}
public class MSAHistoryWeek
{
public DateTime Week { get; set; }
public bool Meeting { get; set; }
public int NumClasses { get; set; }
public string Host { get; set; }
public string Cohost { get; set; }
public string Chairman { get; set; }
public string AuxCounsellor1 { get; set; }
public string AuxCounsellor2 { get; set; }
public string PrayerOpen { get; set; }
public string PrayerClose { get; set; }
public string CBSConductor { get; set; }
public string CBSReader { get; set; }
public List<MSAHistoryItemTalk> TalkItems { get; set; }
public List<string> Teaching { get; set; }
public List<string> StudentItemStudyNumbers { get; set; }
public List<string> StudentItemDescriptions { get; set; }
public int NumStudentItems { get; set; }
public List<MSAHistoryItemStudent>[] StudentItems { get; set; }
public MSAHistoryWeek()
{
TalkItems = Enumerable.Range(1, 6).Select(x => new MSAHistoryItemTalk()).ToList();
Teaching = Enumerable.Range(1, 3).Select(x => string.Empty).ToList();
StudentItemStudyNumbers = Enumerable.Range(1, 5).Select(x => string.Empty).ToList();
StudentItemDescriptions = Enumerable.Range(1, 5).Select(x => string.Empty).ToList();
StudentItems = new List<MSAHistoryItemStudent>[]
{
Enumerable.Range(1, 5).Select(x => new MSAHistoryItemStudent()).ToList(),
Enumerable.Range(1, 5).Select(x => new MSAHistoryItemStudent()).ToList(),
Enumerable.Range(1, 5).Select(x => new MSAHistoryItemStudent()).ToList(),
};
}
public override string ToString()
{
return Week.ToShortDateString();
}
}第二步
我将MSAHistoryWeek对象的实例添加到与CsvReader一起使用的类的修改版本中。
public class CLMExplorerHistory
{
[Format("dd/MM/yyyy")]
[Name("Date")]
public DateTime Date { get => HistoryWeek.Week; set => HistoryWeek.Week = value; }
[BooleanFalseValues(new string[] { "N", "n" })]
[BooleanTrueValues(new string[] { "Y", "y" })]
[Name("Meeting?")]
public bool Meeting { get => HistoryWeek.Meeting; set => HistoryWeek.Meeting = value; }
[Name("# Classes")]
public int Classes { get => HistoryWeek.NumClasses; set => HistoryWeek.NumClasses = value; }
[Name("Chairman")]
public string Chairman { get => HistoryWeek.Chairman; set => HistoryWeek.Chairman = value; }
[Name("AuxCounselor B")]
public string AuxCounsellor1 { get => HistoryWeek.AuxCounsellor1; set => HistoryWeek.AuxCounsellor1 = value; }
[Name("AuxCounselor C")]
public string AuxCounsellor2 { get => HistoryWeek.AuxCounsellor2; set => HistoryWeek.AuxCounsellor2 = value; }
[Name("PrayerOpen")]
public string PrayerOpen { get => HistoryWeek.PrayerOpen; set => HistoryWeek.PrayerOpen = value; }
[Name("PrayerClose")]
public string PrayerClose { get => HistoryWeek.PrayerClose; set => HistoryWeek.PrayerClose = value; }
[Name("CBS")]
public string CBSConductor { get => HistoryWeek.CBSConductor; set => HistoryWeek.CBSConductor = value; }
[Name("CBS_Read")]
public string CBSReader { get => HistoryWeek.CBSReader; set => HistoryWeek.CBSReader = value; }
[Name("TreasuresTalk")]
public string TreasuresTalkName { get => HistoryWeek.TalkItems[0].Name; set => HistoryWeek.TalkItems[0].Name = value; }
[Name("TreasuresTalk_Theme")]
public string TreasuresTalkTheme { get => HistoryWeek.TalkItems[0].Theme; set => HistoryWeek.TalkItems[0].Theme = value; }
[Name("TreasuresDigging")]
public string SpiritualGemsName { get => HistoryWeek.TalkItems[1].Name; set => HistoryWeek.TalkItems[1].Name = value; }
[Name("LivingPart1")]
public string LivingPart1Name { get => HistoryWeek.TalkItems[3].Name; set => HistoryWeek.TalkItems[3].Name = value; }
[Name("LivingPart1_Theme")]
public string LivingPart1Theme { get => HistoryWeek.TalkItems[3].Theme; set => HistoryWeek.TalkItems[3].Theme = value; }
[Name("LivingPart2")]
public string LivingPart2Name { get => HistoryWeek.TalkItems[4].Name; set => HistoryWeek.TalkItems[4].Name = value; }
[Name("LivingPart2_Theme")]
public string LivingPart2Theme { get => HistoryWeek.TalkItems[4].Theme; set => HistoryWeek.TalkItems[4].Theme = value; }
[Name("BibleReading_A")]
public string BibleReadingClass1Name { get => HistoryWeek.StudentItems[0][0].Name; set => HistoryWeek.StudentItems[0][0].Name = value; }
[Name("BibleReading_B")]
public string BibleReadingClass2Name { get => HistoryWeek.StudentItems[1][0].Name; set => HistoryWeek.StudentItems[1][0].Name = value; }
[Name("BibleReading_C")]
public string BibleReadingClass3Name { get => HistoryWeek.StudentItems[2][0].Name; set => HistoryWeek.StudentItems[2][0].Name = value; }
[Name("BibleReading_Study_A")]
public string BibleReadingStudy { get => HistoryWeek.StudentItemStudyNumbers[0]; set => HistoryWeek.StudentItemStudyNumbers[0] = value; }
[Name("Apply1_Description")]
public string StudentItem1Description { get => HistoryWeek.StudentItemDescriptions[1]; set => HistoryWeek.StudentItemDescriptions[1] = value; }
[Name("Apply2_Description")]
public string StudentItem2Description { get => HistoryWeek.StudentItemDescriptions[2]; set => HistoryWeek.StudentItemDescriptions[2] = value; }
[Name("Apply3_Description")]
public string StudentItem3Description { get => HistoryWeek.StudentItemDescriptions[3]; set => HistoryWeek.StudentItemDescriptions[3] = value; }
[Name("Apply4_Description")]
public string StudentItem4Description { get => HistoryWeek.StudentItemDescriptions[4]; set => HistoryWeek.StudentItemDescriptions[4] = value; }
[Name("Apply1_A")]
public string StudentItem1Class1StudentName { get => HistoryWeek.StudentItems[0][1].Name; set => HistoryWeek.StudentItems[0][1].Name = value; }
[Name("Apply1_B")]
public string StudentItem1Class2StudentName { get => HistoryWeek.StudentItems[1][1].Name; set => HistoryWeek.StudentItems[1][1].Name = value; }
[Name("Apply1_C")]
public string StudentItem1Class3StudentName { get => HistoryWeek.StudentItems[2][1].Name; set => HistoryWeek.StudentItems[2][1].Name = value; }
[Name("Apply1_Asst_A")]
public string StudentItem1Class1AssistantName { get => HistoryWeek.StudentItems[0][1].Assistant; set => HistoryWeek.StudentItems[0][1].Assistant = value; }
[Name("Apply1_Asst_B")]
public string StudentItem1Class2AssistantName { get => HistoryWeek.StudentItems[1][1].Assistant; set => HistoryWeek.StudentItems[1][1].Assistant = value; }
[Name("Apply1_Asst_C")]
public string StudentItem1Class3AssistantName { get => HistoryWeek.StudentItems[2][1].Assistant; set => HistoryWeek.StudentItems[2][1].Assistant = value; }
[Name("Apply2_A")]
public string StudentItem2Class1StudentName { get => HistoryWeek.StudentItems[0][2].Name; set => HistoryWeek.StudentItems[0][2].Name = value; }
[Name("Apply2_B")]
public string StudentItem2Class2StudentName { get => HistoryWeek.StudentItems[1][2].Name; set => HistoryWeek.StudentItems[1][2].Name = value; }
[Name("Apply2_C")]
public string StudentItem2Class3StudentName { get => HistoryWeek.StudentItems[2][2].Name; set => HistoryWeek.StudentItems[2][2].Name = value; }
[Name("Apply2_Asst_A")]
public string StudentItem2Class1AssistantName { get => HistoryWeek.StudentItems[0][2].Assistant; set => HistoryWeek.StudentItems[0][2].Assistant = value; }
[Name("Apply2_Asst_B")]
public string StudentItem2Class2AssistantName { get => HistoryWeek.StudentItems[1][2].Assistant; set => HistoryWeek.StudentItems[1][2].Assistant = value; }
[Name("Apply2_Asst_C")]
public string StudentItem2Class3AssistantName { get => HistoryWeek.StudentItems[2][2].Assistant; set => HistoryWeek.StudentItems[2][2].Assistant = value; }
[Name("Apply3_A")]
public string StudentItem3Class1StudentName { get => HistoryWeek.StudentItems[0][3].Name; set => HistoryWeek.StudentItems[0][3].Name = value; }
[Name("Apply3_B")]
public string StudentItem3Class2StudentName { get => HistoryWeek.StudentItems[1][3].Name; set => HistoryWeek.StudentItems[1][3].Name = value; }
[Name("Apply3_C")]
public string StudentItem3Class3StudentName { get => HistoryWeek.StudentItems[2][3].Name; set => HistoryWeek.StudentItems[2][3].Name = value; }
[Name("Apply3_Asst_A")]
public string StudentItem3Class1AssistantName { get => HistoryWeek.StudentItems[0][3].Assistant; set => HistoryWeek.StudentItems[0][3].Assistant = value; }
[Name("Apply3_Asst_B")]
public string StudentItem3Class2AssistantName { get => HistoryWeek.StudentItems[1][3].Assistant; set => HistoryWeek.StudentItems[1][3].Assistant = value; }
[Name("Apply3_Asst_C")]
public string StudentItem3Class3AssistantName { get => HistoryWeek.StudentItems[2][3].Assistant; set => HistoryWeek.StudentItems[2][3].Assistant = value; }
[Name("Apply4_A")]
public string StudentItem4Class1StudentName { get => HistoryWeek.StudentItems[0][4].Name; set => HistoryWeek.StudentItems[0][4].Name = value; }
[Name("Apply4_B")]
public string StudentItem4Class2StudentName { get => HistoryWeek.StudentItems[1][4].Name; set => HistoryWeek.StudentItems[1][4].Name = value; }
[Name("Apply4_C")]
public string StudentItem4Class3StudentName { get => HistoryWeek.StudentItems[2][4].Name; set => HistoryWeek.StudentItems[2][4].Name = value; }
[Name("Apply4_Asst_A")]
public string StudentItem4Class1AssistantName { get => HistoryWeek.StudentItems[0][4].Assistant; set => HistoryWeek.StudentItems[0][4].Assistant = value; }
[Name("Apply4_Asst_B")]
public string StudentItem4Class2AssistantName { get => HistoryWeek.StudentItems[1][4].Assistant; set => HistoryWeek.StudentItems[1][4].Assistant = value; }
[Name("Apply4_Asst_C")]
public string StudentItem4Class3AssistantName { get => HistoryWeek.StudentItems[2][4].Assistant; set => HistoryWeek.StudentItems[2][4].Assistant = value; }
[Name("Apply1_Study_A")]
public string StudentItem1Study { get => HistoryWeek.StudentItemStudyNumbers[1]; set => HistoryWeek.StudentItemStudyNumbers[1] = value; }
[Name("Apply2_Study_A")]
public string StudentItem2Study { get => HistoryWeek.StudentItemStudyNumbers[2]; set => HistoryWeek.StudentItemStudyNumbers[2] = value; }
[Name("Apply3_Study_A")]
public string StudentItem3Study { get => HistoryWeek.StudentItemStudyNumbers[3]; set => HistoryWeek.StudentItemStudyNumbers[3] = value; }
[Name("Apply4_Study_A")]
public string StudentItem4Study { get => HistoryWeek.StudentItemStudyNumbers[4]; set => HistoryWeek.StudentItemStudyNumbers[4] = value; }
[Ignore]
public MSAHistoryWeek HistoryWeek;
public CLMExplorerHistory()
{
HistoryWeek = new MSAHistoryWeek();
}
}如您所见,它遵循公认答案中的原则,即将公共CSV属性映射到增强的MSAHistoryWeek对象。
结果
这种重构使处理数据变得更加容易(即。写入XML)。
https://stackoverflow.com/questions/70684344
复制相似问题