TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
David Smith
NA
2k
0
Save XML Data Logic
Jul 30 2013 10:41 AM
Can someone help me better redesign logic below. I am saving data to XML file via serialization / deserialization. Review Logic Below. I want to simply this logic below.
private
ColorObjectItems colorObject
;
private void WriteDataToFile()
{
try
{
int PartElement = 0;
foreach (ColorPartNum cpn in colorPartNums)
{
m_file.PartNums.Add(new Color_PartNumber() { colorPartNumbers = cpn.PartNumber });
List<Color_SerialNumner> colorSerialNumberList = new List<Color_SerialNumner>(cpn.SerialNumbers.Count());
m_file.PartNums[PartElement].SerialNumbers = colorSerialNumberList;
int serialElement = 0;
foreach (ColorSerialNum csn in cpn.SerialNumbers)
{
colorSerialNumberList.Add(new Color_SerialNumber() { colorSerialNumber = csn.SerialNumber });
List<Color_ColorObject> newColorObjectList = new List<Color_ColorObject>(csn.Colors.Count());
colorSerialNumberList[serialElement].Colors = newColorObjectList;
foreach (Color color in sn.Colors)
{
newColorList.Add(new newColorObjectList()
{
colorDatetime = DateTime.Now,
isColorValidated = color.IsColorValidated
});
}
++serialElement;
}
++PartElement;
}
XmlSerializer serializer = new XmlSerializer(typeof(ColorObjectItems));
using (TextWriter textWriter = new StreamWriter(filename))
{
serializer.Serialize(textWriter, colorObject);
textWriter.Flush();
textWriter.Close();
}
}
catch (Exception e)
{
MessageBox.Show("Error Occured: " + e.Message);
}
}
Reply
Answers (
3
)
video Player in asp.net
array in c#