private static void SerializeComments(BinaryWriter writer, ConfigurationElement element) { // Write the comment. var comment = element.Comment; writer.Write(comment != null); if (comment != null) { writer.Write(comment.Symbol); writer.Write(comment.Value); } // Write the pre-comments. var preComments = element.mPreComments; bool hasPreComments = preComments != null && preComments.Count > 0; writer.Write(hasPreComments ? preComments.Count : 0); if (hasPreComments) { foreach (var preComment in preComments) { writer.Write(preComment.Symbol); writer.Write(preComment.Value); } } }
private static void DeserializeComments(BinaryReader reader, ConfigurationElement element) { bool hasComment = reader.ReadBoolean(); if (hasComment) { char symbol = reader.ReadChar(); string commentValue = reader.ReadString(); element.Comment = new Comment(commentValue, symbol); } int preCommentCount = reader.ReadInt32(); if (preCommentCount > 0) { element.mPreComments = new List<Comment>(preCommentCount); for (int i = 0; i < preCommentCount; ++i) { char symbol = reader.ReadChar(); string commentValue = reader.ReadString(); element.mPreComments.Add(new Comment(commentValue, symbol)); } } }
private static void SerializeComments(BinaryWriter writer, ConfigurationElement element) { // Write the comment. var commentNullable = element.Comment; writer.Write(commentNullable.HasValue); if (commentNullable.HasValue) { var comment = commentNullable.Value; writer.Write(comment.Symbol); writer.Write(comment.Value); } // Write the pre-comments. // Note: do not access the PreComments property of element, // as it will lazily create a new List of pre-comments. // Access the private field instead. var preComments = element._preComments; bool hasPreComments = (preComments != null && preComments.Count > 0); writer.Write(hasPreComments ? preComments.Count : 0); if (hasPreComments) { foreach (var preComment in preComments) { writer.Write(preComment.Symbol); writer.Write(preComment.Value); } } }