public void Load(string data) { Message = data; Presentation = ""; StringReader reader = new StringReader(data); OpinionModel currentOpinion = null; StringBuilder builder = new StringBuilder(); while (true) { var line = reader.ReadLine(); if (line == null) { break; } if (line.StartsWith("Proposal", StringComparison.InvariantCultureIgnoreCase)) { if (currentOpinion != null && builder != null) { currentOpinion.Content = builder.ToString(); } else if (builder != null) { Presentation = builder.ToString(); } currentOpinion = new OpinionModel(); Opinions.Add(currentOpinion); builder = new StringBuilder(); currentOpinion.Name = line.Split(':').Last().Trim(); } else if (line.StartsWith("Approval", StringComparison.InvariantCultureIgnoreCase) && currentOpinion != null) { var approval = line.Split(':').Last().Trim(); currentOpinion.Approve = approval.Equals("Yes", StringComparison.InvariantCultureIgnoreCase) ? Approval.Yes : approval.Equals("No", StringComparison.InvariantCultureIgnoreCase) ? Approval.No: Approval.NA; } else { if (builder != null) { builder.AppendLine(line); } } } if (currentOpinion != null && builder != null) { currentOpinion.Content = builder.ToString(); } else if (builder != null) { Presentation = builder.ToString(); } }
public void Load(string data) { Message = data; Presentation = ""; StringReader reader = new StringReader(data); OpinionModel currentOpinion = null; StringBuilder builder = new StringBuilder(); while(true) { var line = reader.ReadLine(); if(line == null) break; if(line.StartsWith("Proposal", StringComparison.InvariantCultureIgnoreCase)) { if(currentOpinion != null && builder != null) currentOpinion.Content = builder.ToString(); else if(builder != null) Presentation = builder.ToString(); currentOpinion = new OpinionModel(); Opinions.Add(currentOpinion); builder = new StringBuilder(); currentOpinion.Name = line.Split(':').Last().Trim(); } else if(line.StartsWith("Approval", StringComparison.InvariantCultureIgnoreCase) && currentOpinion != null) { var approval = line.Split(':').Last().Trim(); currentOpinion.Approve = approval.Equals("Yes", StringComparison.InvariantCultureIgnoreCase) ? Approval.Yes : approval.Equals("No", StringComparison.InvariantCultureIgnoreCase) ? Approval.No: Approval.NA; } else { if(builder != null) builder.AppendLine(line); } } if(currentOpinion != null && builder != null) currentOpinion.Content = builder.ToString(); else if(builder != null) Presentation = builder.ToString(); }