本文整理汇总了C#中GenericWrapper类的典型用法代码示例。如果您正苦于以下问题:C# GenericWrapper类的具体用法?C# GenericWrapper怎么用?C# GenericWrapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GenericWrapper类属于命名空间,在下文中一共展示了GenericWrapper类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Overloaded
public static GenericWrapper<ISayHello1>[] Overloaded(
GenericWrapper<ISayHello1>[] v) {
return v;
}
示例3: 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);
}