diff --git a/XmlSchemaClassGenerator/CodeUtilities.cs b/XmlSchemaClassGenerator/CodeUtilities.cs index a2780954..72e148b7 100644 --- a/XmlSchemaClassGenerator/CodeUtilities.cs +++ b/XmlSchemaClassGenerator/CodeUtilities.cs @@ -220,5 +220,12 @@ public static string GetUniqueFieldName(this TypeModel typeModel, PropertyModel return string.Format("{0}{1}", propBackingFieldName, i); } + + static readonly Regex NormalizeNewlinesRegex = new Regex(@"(^|[^\r])\n",RegexOptions.Compiled); + + internal static string NormalizeNewlines(string text) + { + return NormalizeNewlinesRegex.Replace(text, "$1\r\n"); + } } } \ No newline at end of file diff --git a/XmlSchemaClassGenerator/TypeModel.cs b/XmlSchemaClassGenerator/TypeModel.cs index 541d5e01..aab6dc35 100644 --- a/XmlSchemaClassGenerator/TypeModel.cs +++ b/XmlSchemaClassGenerator/TypeModel.cs @@ -75,9 +75,9 @@ public static IEnumerable GetComments(IEnumerable d.Language)) { + var text = doc.Text; var comment = string.Format(@"{1}", - string.IsNullOrEmpty(doc.Language) ? "" : string.Format(@" xml:lang=""{0}""", doc.Language), - Regex.Replace(doc.Text, @"(^|[^\r])\n", "$1\r\n")); // normalize newlines + string.IsNullOrEmpty(doc.Language) ? "" : string.Format(@" xml:lang=""{0}""", doc.Language), CodeUtilities.NormalizeNewlines(text)); yield return new CodeCommentStatement(comment, true); } @@ -435,7 +435,7 @@ internal static string GetAccessors(string memberName, string backingFieldName, switch (typeCode) { case PropertyValueTypeCode.ValueType: - return string.Format(@" + return CodeUtilities.NormalizeNewlines(string.Format(@" {{ get {{ @@ -449,9 +449,9 @@ internal static string GetAccessors(string memberName, string backingFieldName, OnPropertyChanged(""{1}""); }} }} - }}", backingFieldName, memberName, (privateSetter ? "private " : string.Empty)); + }}", backingFieldName, memberName, (privateSetter ? "private " : string.Empty))); case PropertyValueTypeCode.Other: - return string.Format(@" + return CodeUtilities.NormalizeNewlines(string.Format(@" {{ get {{ @@ -467,9 +467,9 @@ internal static string GetAccessors(string memberName, string backingFieldName, OnPropertyChanged(""{1}""); }} }} - }}", backingFieldName, memberName, (privateSetter ? "private " : string.Empty)); + }}", backingFieldName, memberName, (privateSetter ? "private " : string.Empty))); case PropertyValueTypeCode.Array: - return string.Format(@" + return CodeUtilities.NormalizeNewlines(string.Format(@" {{ get {{ @@ -485,23 +485,23 @@ internal static string GetAccessors(string memberName, string backingFieldName, OnPropertyChanged(""{1}""); }} }} - }}", backingFieldName, memberName, (privateSetter ? "private " : string.Empty)); + }}", backingFieldName, memberName, (privateSetter ? "private " : string.Empty))); } } if (privateSetter) { - return string.Format(@" + return CodeUtilities.NormalizeNewlines(string.Format(@" {{ get {{ return this.{0}; }} - }}", backingFieldName); + }}", backingFieldName)); } else { - return string.Format(@" + return CodeUtilities.NormalizeNewlines(string.Format(@" {{ get {{ @@ -511,7 +511,7 @@ internal static string GetAccessors(string memberName, string backingFieldName, {{ this.{0} = value; }} - }}", backingFieldName); + }}", backingFieldName)); } }