Exemple #1
0
        public void TestFindInstanceMethod()
        {
            MethodInfo method = typeof(object).Method("ID");

            Assert.Null(method);

            AnimalInstanceMethodNames.Select(s => typeof(Animal).Method(s)).ForEach(Assert.NotNull);
            SnakeInstanceMethodNames.Select(s => typeof(Snake).Method(s)).ForEach(Assert.NotNull);
        }
Exemple #2
0
        public void TestFindMethodInstanceWithDeclaredOnly()
        {
            Flags flags = Flags.InstanceAnyVisibility | Flags.DeclaredOnly;

            AnimalInstanceMethodNames.Select(s => typeof(Animal).Method(s, flags)).ForEach(Assert.NotNull);
            ReptileDeclaredInstanceMethodNames.Select(s => typeof(Reptile).Method(s, flags)).ForEach(Assert.NotNull);
            ReptileInstanceMethodNames.Where(s => !ReptileDeclaredInstanceMethodNames.Contains(s)).Select(s => typeof(Reptile).Method(s, flags)).ForEach(Assert.Null);
            SnakeDeclaredInstanceMethodNames.Select(s => typeof(Snake).Method(s, flags)).ForEach(Assert.NotNull);
            SnakeInstanceMethodNames.Where(s => !SnakeDeclaredInstanceMethodNames.Contains(s)).Select(s => typeof(Snake).Method(s, flags)).ForEach(Assert.Null);
        }
Exemple #3
0
        public void TestFindMethodsInstance()
        {
            var methods = typeof(Animal).Methods();

            Assert.Equal(AnimalInstanceMethodNames.OrderBy(n => n), methods.Select(m => m.Name).OrderBy(n => n).ToList());

            methods = typeof(Reptile).Methods();
            Assert.Equal(ReptileInstanceMethodNames.OrderBy(n => n), methods.Select(m => m.Name).OrderBy(n => n).ToList());

            methods = typeof(Snake).Methods();
            Assert.Equal(SnakeInstanceMethodNames.OrderBy(n => n), methods.Select(m => m.Name.Contains(".") ? m.Name.Substring(m.Name.LastIndexOf(".") + 1) : m.Name).OrderBy(n => n).ToList());
        }
Exemple #4
0
        public void TestFindMethodInstanceIgnoreCase()
        {
            Flags flags = Flags.InstanceAnyVisibility | Flags.IgnoreCase;

            AnimalInstanceMethodNames.Select(s => s.ToLower()).Select(s => typeof(Animal).Method(s)).ForEach(Assert.Null);
            AnimalInstanceMethodNames.Select(s => s.ToLower()).Select(s => typeof(Animal).Method(s, flags)).ForEach(Assert.NotNull);

            ReptileInstanceMethodNames.Select(s => s.ToLower()).Select(s => typeof(Reptile).Method(s)).ForEach(Assert.Null);
            ReptileInstanceMethodNames.Select(s => s.ToLower()).Select(s => typeof(Reptile).Method(s, flags)).ForEach(Assert.NotNull);

            SnakeInstanceMethodNames.Select(s => s.ToLower()).Select(s => typeof(Snake).Method(s)).ForEach(Assert.Null);
            SnakeInstanceMethodNames.Select(s => s.ToLower()).Select(s => typeof(Snake).Method(s, flags)).ForEach(Assert.NotNull);
        }
Exemple #5
0
        public void TestFindMethodInstanceWithExcludeBackingMembers()
        {
            Flags flags = Flags.InstanceAnyVisibility | Flags.ExcludeBackingMembers;

            AnimalInstanceMethodNames.Select(s => typeof(Animal).Method(s)).ForEach(Assert.NotNull);
            AnimalInstanceMethodNames.Where(s => s.Contains("_")).Select(s => typeof(Animal).Method(s, flags)).ForEach(Assert.Null);
            AnimalInstanceMethodNames.Where(s => !s.Contains("_")).Select(s => typeof(Animal).Method(s, flags)).ForEach(Assert.NotNull);

            ReptileInstanceMethodNames.Select(s => typeof(Reptile).Method(s)).ForEach(Assert.NotNull);
            ReptileInstanceMethodNames.Where(s => s.Contains("_")).Select(s => typeof(Reptile).Method(s, flags)).ForEach(Assert.Null);
            ReptileInstanceMethodNames.Where(s => !s.Contains("_")).Select(s => typeof(Reptile).Method(s, flags)).ForEach(Assert.NotNull);

            SnakeInstanceMethodNames.Select(s => typeof(Snake).Method(s)).ForEach(Assert.NotNull);
            SnakeInstanceMethodNames.Where(s => s.Contains("_")).Select(s => typeof(Snake).Method(s, flags)).ForEach(Assert.Null);
            SnakeInstanceMethodNames.Where(s => !s.Contains("_")).Select(s => typeof(Snake).Method(s, flags)).ForEach(Assert.NotNull);
        }
Exemple #6
0
        public void TestFindMethodsInstanceWithPartialNameMatch()
        {
            Flags flags = Flags.InstanceAnyVisibility | Flags.PartialNameMatch;

            var methods = typeof(Animal).Methods(flags, "B");

            Assert.Equal(AnimalInstanceMethodNames.Where(s => s.Contains("B")).OrderBy(n => n).ToList(), methods.Select(m => m.Name).OrderBy(n => n).ToList());

            methods = typeof(Reptile).Methods(flags, "et_");
            Assert.Equal(ReptileInstanceMethodNames.Where(s => s.Contains("et_")).OrderBy(n => n).ToList(), methods.Select(m => m.Name).OrderBy(n => n).ToList());

            methods = typeof(Snake).Methods(flags, "get", "C");
            Assert.Equal(SnakeInstanceMethodNames.Where(s => s.Contains("get") || s.Contains("C")).OrderBy(n => n).ToList(), methods.Select(m => m.Name).OrderBy(n => n).ToList());

            methods = typeof(Snake).Methods(flags, "_");
            Assert.Equal(SnakeInstanceMethodNames.Where(s => s.Contains("_")).OrderBy(n => n).ToList(), methods.Select(m => m.Name).OrderBy(n => n).ToList());

            methods = typeof(Snake).Methods(flags);
            Assert.Equal(SnakeInstanceMethodNames.OrderBy(n => n), methods.Select(m => m.Name.TrimExplicitlyImplementedName()).OrderBy(n => n).ToList());
        }
        public void TestFindMethodsInstanceWithPartialNameMatch()
        {
            FasterflectFlags flags = FasterflectFlags.InstanceAnyVisibility | FasterflectFlags.PartialNameMatch;

            IList <MethodInfo> methods = typeof(Animal).Methods(flags, "B");

            CollectionAssert.AreEquivalent(AnimalInstanceMethodNames.Where(s => s.Contains("B")).ToList(), methods.Select(m => m.Name).ToList());

            methods = typeof(Reptile).Methods(flags, "et_");
            CollectionAssert.AreEquivalent(ReptileInstanceMethodNames.Where(s => s.Contains("et_")).ToList(), methods.Select(m => m.Name).ToList());

            methods = typeof(Snake).Methods(flags, "get", "C");
            CollectionAssert.AreEquivalent(SnakeInstanceMethodNames.Where(s => s.Contains("get") || s.Contains("C")).ToList(), methods.Select(m => m.Name).ToList());

            methods = typeof(Snake).Methods(flags, "_");
            CollectionAssert.AreEquivalent(SnakeInstanceMethodNames.Where(s => s.Contains("_")).ToList(), methods.Select(m => m.Name).ToList());

            methods = typeof(Snake).Methods(flags);
            CollectionAssert.AreEquivalent(SnakeInstanceMethodNames, methods.Select(m => m.Name.TrimExplicitlyImplementedName()).ToList());
        }