本文整理汇总了C#中Formatter.Format方法的典型用法代码示例。如果您正苦于以下问题:C# Formatter.Format方法的具体用法?C# Formatter.Format怎么用?C# Formatter.Format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Formatter
的用法示例。
在下文中一共展示了Formatter.Format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReverseForeignRelationshipMapping
public ReverseForeignRelationshipMapping(PropertyInfo property, Type type, Type parentType, Formatter<PropertyInfo> keyFormatter)
: base(property)
{
this.type = type;
this.parentType = parentType;
this.ColumnName = keyFormatter.Format(property);
}
示例2: Format_should_accept_TextWriter
public void Format_should_accept_TextWriter()
{
var sut = new Formatter();
var writer = new StringWriter();
writer.NewLine = "\n";
sut.Format(_testGame, writer);
Assert.AreEqual(TestGameString, writer.ToString());
}
示例3: It_Should_Not_Be_null
public void It_Should_Not_Be_null()
{
_objectsToFormat = new List<DummyObject>();
for (int i = 0; i < _numberOfObjects; i++)
{
_objectsToFormat.Add(new DummyObject());
}
_formatter = new Formatter<DummyObject>();
try
{
_formatter.Format(_objectsToFormat);
Assert.Fail("Expected NoFormatSpecificationException to be thrown");
}
catch (NoFormatSpecificationException)
{
// Expect NoFormatSpecificationException to be thrown.
}
}
示例4: Then_Fixed_Length_Should_Be_Applied_To_The_Fields
public void Then_Fixed_Length_Should_Be_Applied_To_The_Fields()
{
var dummyObjects = new List<DummyObject>();
for (int i = 0; i < 10; i++)
{
dummyObjects.Add(new DummyObject() { SomeInt = i, SomeString = "Str" + i});
}
var formatter = new Formatter<DummyObject>()
.With(y => y.SomeInt, 0, 5, y => y.ToString().PadLeft(5, '0'))
.With(y => y.SomeString, 5, 5, y => y.PadRight(5, ' '));
var result = formatter.Format(dummyObjects);
for (int i = 0; i < dummyObjects.Count; i++)
{
string expected = i.ToString().PadLeft(5, '0') + ("Str" + i).PadRight(5, ' ');
string actual = result.ElementAt(i);
Assert.AreEqual(expected, actual);
}
}
示例5: CommentedObjectPropertyTextShouldNotBeChanged
public void CommentedObjectPropertyTextShouldNotBeChanged()
{
const string TEMPLATE = "abcd'\\$\\{Text\\}'efgh${Text}";
const string FORMATTED = "abcd'${Text}'efgh12345";
var model = new TestModel();
model.Text = "12345";
var formatter = new Formatter(TEMPLATE).Parse();
string formatted = formatter.Format(model);
Assert.That(formatted, Is.EqualTo(FORMATTED));
}
示例6: TwoObjectPropertiesTextTemplateShouldBeChanged
public void TwoObjectPropertiesTextTemplateShouldBeChanged()
{
const string TEMPLATE = "abcd${Text}efgh${Text}";
const string FORMATTED = "abcd12345efgh12345";
var model = new TestModel();
model.Text = "12345";
var formatter = new Formatter(TEMPLATE).Parse();
string formatted = formatter.Format(model);
Assert.That(formatted, Is.EqualTo(FORMATTED));
}
示例7: HandleNestedIncludeWithParentDirs
public void HandleNestedIncludeWithParentDirs()
{
var formatter = new Formatter("<sharp:include file='SharpTags/withparent.htm'/>").Parse();
Assert.That(formatter.Format(new TagModel(new Hashtable())),
Is.EqualTo("parent aa"));
}
示例8: HandOverVariableScopeNested
public void HandOverVariableScopeNested()
{
var some = new Hashtable();
some.Add("a", "##");
var table = new Hashtable();
table.Add("some", some);
var formatter = new Formatter("<sharp:include file='SharpTags/b.htm'/>").Parse();
Assert.That(formatter.Format(new TagModel(table)),
Is.EqualTo("bb##bb"));
}
示例9: Then_The_Static_Field_Should_Be_Printed
public void Then_The_Static_Field_Should_Be_Printed()
{
var formatter = new Formatter<DummyObject>()
.With("Hello", 0)
.With(y => y.SomeInt, 1, 5, y => y.ToString("00000"))
.With("World!", 2)
.WithDelimiter(";");
var result = formatter.Format(_objectsToFormat);
for (int i = 0; i < _objectsToFormat.Count; i++)
{
var expected = "Hello;" + _objectsToFormat[i].SomeInt.ToString("00000") + ";World!";
Assert.AreEqual(expected, result.ElementAt(i));
}
}
示例10: And_Prefix_Is_Used_It_Should_Be_Applied_At_Start_Of_Row
public void And_Prefix_Is_Used_It_Should_Be_Applied_At_Start_Of_Row()
{
var prefix = "ThisIsAPrefix";
var formatter = new Formatter<DummyObject>()
.With(y => y.SomeInt, 1, 5, y => y.ToString("00000"))
.With(y => y.SomeString, 2, 6, y => y.ToString().PadLeft(6, '_'))
.WithLinePrefix(prefix)
.WithDelimiter(";");
var result = formatter.Format(_objectsToFormat);
foreach (var item in result)
{
Assert.IsTrue(item.StartsWith(prefix + ";"));
}
}
示例11: It_Should_Throw_Format_Gap_Exception
public void It_Should_Throw_Format_Gap_Exception()
{
var formatter = new Formatter<DummyObject>()
.With(y => y.SomeInt, 0, 4, y => y.ToString())
.With(y => y.SomeString, 5, 3, y => y.ToString());
try
{
IEnumerable<DummyObject> items = new List<DummyObject>();
formatter.Format(items);
Assert.Fail("Should throw MissingFormatSpecificationException");
}
catch (FormatGapException)
{
}
}
示例12: Setting_Local_Affects_Formatting_Of_Number_EN_After_Cout
public void Setting_Local_Affects_Formatting_Of_Number_EN_After_Cout()
{
const string TEMPLATE = "<fmt:setLocale value='en-GB' scope='Page'/><c:out value=\"${'0.00'+'1.00'}%\"/>";
const string FORMATTED = "1.00%";
var model = new TestModel();
model.Text = "";
var formatter = new Formatter(TEMPLATE).Parse();
string formatted = formatter.Format(model);
Assert.That(formatted, Is.EqualTo(FORMATTED));
}
示例13: Setting_Empty_String_Should_Be_Parsed_Correctly
public void Setting_Empty_String_Should_Be_Parsed_Correctly()
{
const string TEMPLATE = "<c:set value='' var='Text' scope='Model'/>";
var model = new TestModel();
model.Text = "aaa";
var formatter = new Formatter(TEMPLATE).Parse();
formatter.Format(model);
Console.WriteLine($"[{model.Text}]");
}
示例14: PlainTextTempalteShouldNotBeChanged
public void PlainTextTempalteShouldNotBeChanged()
{
const string TEMPLATE = "abcdefgh";
var formatter = new Formatter(TEMPLATE).Parse();
string formatted = formatter.Format(new object());
Assert.That(formatted, Is.EqualTo(TEMPLATE));
}
示例15: ParseOfNonCommandTagsShouldNotDistrubtFormatting
public void ParseOfNonCommandTagsShouldNotDistrubtFormatting()
{
const string TEMPLATE = "<a/>bcd${Text}slk";
const string FORMATTED = "<a/>bcd12345slk";
var model = new TestModel();
model.Text = "12345";
var formatter = new Formatter(TEMPLATE).Parse();
string formatted = formatter.Format(model);
Assert.That(formatted, Is.EqualTo(FORMATTED));
Assert.That(formatter.ParsedTemplate.Count, Is.EqualTo(3));
}