int ptr = 0;
int start = ptr;
+ var formatter = provider != null ? provider.GetFormat (typeof (ICustomFormatter)) as ICustomFormatter : null;
+
while (ptr < format.length) {
char c = format[ptr ++];
object arg = args[n];
string str;
- ICustomFormatter formatter = null;
- if (provider != null)
- formatter = provider.GetFormat (typeof (ICustomFormatter))
- as ICustomFormatter;
if (arg == null)
str = Empty;
else if (formatter != null)
str = formatter.Format (arg_format, arg, provider);
- else if (arg is IFormattable)
- str = ((IFormattable)arg).ToString (arg_format, provider);
else
- str = arg.ToString ();
+ str = null;
- // pad formatted string and append to result
+ if (str == null) {
+ if (arg is IFormattable)
+ str = ((IFormattable)arg).ToString (arg_format, provider);
+ else
+ str = arg.ToString ();
+ }
+ // pad formatted string and append to result
if (width > str.length) {
const char padchar = ' ';
int padlen = width - str.length;
result.Append (padchar, padlen);
result.Append (str);
}
- }
- else
+ } else {
result.Append (str);
+ }
start = ptr;
}
[TestFixture]
public class StringTest
{
+ class NullFormatter : IFormatProvider, ICustomFormatter
+ {
+ public string Format (string format, object arg, IFormatProvider provider)
+ {
+ return null;
+ }
+
+ public object GetFormat (Type formatType)
+ {
+ return this;
+ }
+ }
+
+
private CultureInfo orgCulture;
[SetUp]
}
}
+ [Test]
+ public void Format ()
+ {
+ var s = String.Format (new NullFormatter (), "{0:}", "test");
+ Assert.AreEqual ("test", s);
+ }
+
[Test]
public void TestGetEnumerator ()
{