当前位置: 首页>>代码示例>>C#>>正文


C# GenericWrapper类代码示例

本文整理汇总了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);
        }
开发者ID:yallie,项目名称:zyan,代码行数:53,代码来源:WrapperTests.cs

示例2: Overloaded

        public static GenericWrapper<ISayHello1>[] Overloaded(
                                              GenericWrapper<ISayHello1>[] v) {

            return v;
        }
开发者ID:sdpython,项目名称:pythonnet3,代码行数:5,代码来源:methodtest.cs

示例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);
        }
开发者ID:yallie,项目名称:zyan,代码行数:63,代码来源:WrapperTests.cs


注:本文中的GenericWrapper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。