本文整理汇总了C#中ObjectContainer.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectContainer.ToString方法的具体用法?C# ObjectContainer.ToString怎么用?C# ObjectContainer.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectContainer
的用法示例。
在下文中一共展示了ObjectContainer.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToString_NoParameters_ReturnsDescription
public void ToString_NoParameters_ReturnsDescription()
{
ObjectContainer locator = new ObjectContainer();
locator.RegisterSingleton<object>(c => { return new object(); });
var log = new Mock<ILogger>();
locator.Register<ILogger>(c => { return log.Object; });
locator.Configuration["Object"]=new object();
var result = locator.ToString();
Assert.IsInstanceOf<string>(result);
//Console.WriteLine(result);
}
示例2: ShouldListRegistrationsInToString
public void ShouldListRegistrationsInToString()
{
// given
var container = new ObjectContainer();
container.RegisterTypeAs<VerySimpleClass, IInterface1>();
container.RegisterInstanceAs<IInterface1>(new SimpleClassWithDefaultCtor { Status = "instance1" });
container.RegisterTypeAs<VerySimpleClass, IInterface1>("one");
container.RegisterInstanceAs<IInterface1>(new SimpleClassWithDefaultCtor { Status = "instance2" }, "two");
container.RegisterInstanceAs<IInterface1>(new SimpleClassWithFailingToString(), "three");
// when
var result = container.ToString();
Console.WriteLine(result);
// then
result.ShouldContain("BoDi.IObjectContainer -> <self>");
result.ShouldContain("BoDi.Tests.IInterface1 -> Instance: SimpleClassWithDefaultCtor: instance1");
result.ShouldContain("BoDi.Tests.IInterface1('one') -> Type: BoDi.Tests.VerySimpleClass");
result.ShouldContain("BoDi.Tests.IInterface1('two') -> Instance: SimpleClassWithDefaultCtor: instance2");
result.ShouldContain("BoDi.Tests.IInterface1('three') -> Instance: simulated error");
}
示例3: ObjectContainerTextSaveState
public void ObjectContainerTextSaveState(ObjectContainer o)
{
TextWriter.Null.Write(o.ToString());
}