Permalink
Browse files

[Contrib][T4] Remove unnecessary Bracket from DefaultValue

  • Loading branch information...
1 parent 759debf commit 77a0fcda527f0058d7bd5848d4733bc6e23fd405 @spaccabit committed Dec 1, 2012
Showing with 42 additions and 6 deletions.
  1. +2 −2 src/FluentMigrator.T4/CodeGenerator.cs
  2. +40 −4 src/FluentMigrator.T4/Extensions/StringExtension.cs
@@ -63,7 +63,7 @@ public string GetColumnDefaultValue(Column col)
case System.Data.DbType.UInt16:
case System.Data.DbType.UInt32:
case System.Data.DbType.UInt64:
- sysType = col.DefaultValue.Replace("'", "").Replace("\"", "");
+ sysType = col.DefaultValue.Replace("'", "").Replace("\"", "").CleanBracket();
break;
case System.Data.DbType.Guid:
if (col.DefaultValue.IsGuid(out guid))
@@ -85,7 +85,7 @@ public string GetColumnDefaultValue(Column col)
}
else
{
- sysType = "\"" + col.DefaultValue + "\"";
+ sysType = "\"" + col.DefaultValue.CleanBracket() + "\"";
}
break;
default:
@@ -73,11 +73,11 @@ static class StringExtension
internal static bool IsGuid(this string candidate, out Guid output)
{
output = Guid.Empty;
- if (string.IsNullOrEmpty(candidate))
+ if (string.IsNullOrEmpty(candidate))
return false;
-
+
bool isValid = false;
-
+
if (candidate != null)
{
@@ -86,7 +86,7 @@ internal static bool IsGuid(this string candidate, out Guid output)
if (m != null && m.Success)
{
- output = new Guid(string.Format("{{{0}}}", m.Groups[1].Value));
+ output = new Guid(string.Format("{{{0}}}", m.Groups[1].Value));
isValid = true;
}
@@ -96,5 +96,41 @@ internal static bool IsGuid(this string candidate, out Guid output)
return isValid;
}
+
+ static internal string Clean(this string source, char start)
+ {
+ return source.Clean(start, start);
+ }
+
+ static internal string Clean(this string source, char start, char end)
+ {
+ if (string.IsNullOrEmpty(source) == false)
+ {
+ source = source.Trim();
+ if (source.Length > 0)
+ {
+ var trimStart = -1;
+ var trimEnd = -1;
+ var chars = source.ToCharArray();
+ var i = 0;
+ var y = chars.Length - 1;
+ while (chars[i++] == start && chars[y--] == end)
+ {
+ trimStart = i;
+ trimEnd = y;
+ }
+ var trimSize = trimEnd - trimStart + 1;
+ if (trimStart > -1 && trimSize > 0)
+ source = source.Substring(trimStart, trimSize);
+ }
+ }
+ return source;
+ }
+
+
+ static internal string CleanBracket(this string source)
+ {
+ return source.Clean('(', ')');
+ }
}
}

0 comments on commit 77a0fcd

Please sign in to comment.