Exemple #1
0
        public void GetRuntimeEvent()
        {
            var types = GetTypes();

            Assert.Throws<ArgumentNullException>(() =>
            {
                RuntimeReflectionExtensions.GetRuntimeEvent(null, "foo");
            });


            Assert.Throws<ArgumentNullException>(() =>
            {
                typeof(RuntimeReflectionExtensionsTests).GetRuntimeEvent(null);
            });

            List<String> events = new List<String>();

            foreach (TypeInfo type in types)
            {
                if (!type.Namespace.Equals("EventDefinitions", StringComparison.Ordinal))
                    continue;

                if (type.IsInterface)
                    continue;

                events.Clear();
                events.AddRange((IEnumerable<String>)type.GetDeclaredField("PublicEvents").GetValue(null));

                foreach (String eventName in events)
                {
                    Assert.NotNull(type.AsType().GetRuntimeEvent(eventName));
                }
            }
        }
Exemple #2
0
        public static EventInfo GetRuntimeEvent(this Type type, string name)
        {
#if UNITY_METRO && !UNITY_EDITOR
            return(RuntimeReflectionExtensions.GetRuntimeEvent(type, name));
#else
            return(type.GetEvent(name));
#endif
        }
Exemple #3
0
        public void GetRuntimeEvent()
        {
            var types = GetTypes();

            AssertExtensions.Throws <ArgumentNullException>("type", () =>
            {
                RuntimeReflectionExtensions.GetRuntimeEvent(default(Type), "foo");
            });


            Assert.Throws <ArgumentNullException>("name", () =>
            {
                typeof(RuntimeReflectionExtensionsTests).GetRuntimeEvent(null);
            });

            Assert.Null(typeof(TestType).GetRuntimeEvent(""));

            List <string> events = new List <string>();

            foreach (TypeInfo type in types)
            {
                if (!type.Namespace.Equals("EventDefinitions", StringComparison.Ordinal))
                {
                    continue;
                }

                if (type.IsInterface)
                {
                    continue;
                }

                events.Clear();
                events.AddRange((IEnumerable <string>)type.GetDeclaredField("PublicEvents").GetValue(null));

                foreach (string eventName in events)
                {
                    Assert.NotNull(type.AsType().GetRuntimeEvent(eventName));
                }
            }

            Assert.Equal(typeof(TestType).GetEvent("StuffHappened"), typeof(TestType).GetRuntimeEvent("StuffHappened"));
        }