本文整理汇总了C#中GenericWrapper.GetDefault方法的典型用法代码示例。如果您正苦于以下问题:C# GenericWrapper.GetDefault方法的具体用法?C# GenericWrapper.GetDefault怎么用?C# GenericWrapper.GetDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericWrapper
的用法示例。
在下文中一共展示了GenericWrapper.GetDefault方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestGenericWrapper
public void TestGenericWrapper()
{
var test = new GenericWrapper(new NonGenericWrapper(new GenericClass()));
var prioritySet = false;
// GetDefault
Assert.AreEqual(default(int), test.GetDefault<int>());
Assert.AreEqual(default(string), test.GetDefault<string>());
Assert.AreEqual(default(Guid), test.GetDefault<Guid>());
// Equals
Assert.IsTrue(test.Equals(123, 123));
Assert.IsFalse(test.Equals("Some", null));
// GetVersion
Assert.AreEqual("DoSomething wasn't called yet", test.GetVersion());
// DoSomething
test.DoSomething(123, 'x', "y");
Assert.AreEqual("DoSomething: A = 123, B = x, C = y", test.GetVersion());
// Compute
var dt = test.Compute<Guid, DateTime>(Guid.Empty, 123, "123");
Assert.AreEqual(default(DateTime), dt);
// CreateGuid
var guid = test.CreateGuid(dt, 12345);
Assert.AreEqual("00003039-0001-0001-0000-000000000000", guid.ToString());
// LastDate
Assert.AreEqual(dt, test.LastDate);
test.LastDate = dt = DateTime.Now;
Assert.AreEqual(dt, test.LastDate);
// Name
Assert.AreEqual("GenericClass, priority = 123", test.Name);
// add OnPrioritySet
EventHandler<EventArgs> handler = (s, a) => prioritySet = true;
test.OnPrioritySet += handler;
Assert.IsFalse(prioritySet);
// Priority
test.Priority = 321;
Assert.IsTrue(prioritySet);
Assert.AreEqual("GenericClass, priority = 321", test.Name);
// remove OnPrioritySet
prioritySet = false;
test.OnPrioritySet -= handler;
test.Priority = 111;
Assert.IsFalse(prioritySet);
}
示例2: TestGenericWrapperOverZyan
public void TestGenericWrapperOverZyan()
{
var serverProto = new IpcBinaryServerProtocolSetup("Test");
var clientProto = new IpcBinaryClientProtocolSetup();
var host = new ZyanComponentHost("TestServer", serverProto);
host.RegisterComponent<INonGenericInterface>(() => new NonGenericWrapper(new GenericClass()), ActivationType.Singleton);
var conn = new ZyanConnection("ipc://Test/TestServer");
var proxy = conn.CreateProxy<INonGenericInterface>();
// same as usual
var test = new GenericWrapper(proxy);
var prioritySet = false;
// GetDefault
Assert.AreEqual(default(int), test.GetDefault<int>());
Assert.AreEqual(default(string), test.GetDefault<string>());
Assert.AreEqual(default(Guid), test.GetDefault<Guid>());
// Equals
Assert.IsTrue(test.Equals(123, 123));
Assert.IsFalse(test.Equals("Some", null));
// GetVersion
Assert.AreEqual("DoSomething wasn't called yet", test.GetVersion());
// DoSomething
test.DoSomething(123, 'x', "y");
Assert.AreEqual("DoSomething: A = 123, B = x, C = y", test.GetVersion());
// Compute
var dt = test.Compute<Guid, DateTime>(Guid.Empty, 123, "123");
Assert.AreEqual(default(DateTime), dt);
// CreateGuid
var guid = test.CreateGuid(dt, 12345);
Assert.AreEqual("00003039-0001-0001-0000-000000000000", guid.ToString());
// LastDate
Assert.AreEqual(dt, test.LastDate);
test.LastDate = dt = DateTime.Now;
Assert.AreEqual(dt, test.LastDate);
// Name
Assert.AreEqual("GenericClass, priority = 123", test.Name);
// add OnPrioritySet
EventHandler<EventArgs> handler = (s, a) => prioritySet = true;
test.OnPrioritySet += handler;
Assert.IsFalse(prioritySet);
// Priority
test.Priority = 321;
Assert.IsTrue(prioritySet);
Assert.AreEqual("GenericClass, priority = 321", test.Name);
// remove OnPrioritySet
prioritySet = false;
test.OnPrioritySet -= handler;
test.Priority = 111;
Assert.IsFalse(prioritySet);
}