Beispiel #1
0
 public void ListMethods_ShouldReturnOverLoadedInterfaceMethods()
 {
     MethodInfo[] methods = typeof(IEnumerable <string>).ListMethods().ToArray();
     Assert.That(methods.Length, Is.EqualTo(2));
     Assert.That(methods.Contains((MethodInfo)MemberInfoExtensions.ExtractFrom <IEnumerable <string> >(i => i.GetEnumerator())));
     Assert.That(methods.Contains((MethodInfo)MemberInfoExtensions.ExtractFrom <IEnumerable>(i => i.GetEnumerator())));
 }
Beispiel #2
0
 public void ListProperties_ShouldReturnOverLoadedInterfaceProperties()
 {
     PropertyInfo[] properties = typeof(IEnumerator <string>).ListProperties().ToArray();
     Assert.That(properties.Length, Is.EqualTo(2));
     Assert.That(properties.Contains((PropertyInfo)MemberInfoExtensions.ExtractFrom <IEnumerator <string> >(i => i.Current)));
     Assert.That(properties.Contains((PropertyInfo)MemberInfoExtensions.ExtractFrom <IEnumerator>(i => i.Current)));
 }
Beispiel #3
0
        public void ListMethods_ShouldReturnMethodsFromTheWholeHierarchy()
        {
            MethodInfo[] methods = typeof(IGrandChild).ListMethods().ToArray();

            Assert.That(methods.Length, Is.EqualTo(3));
            Assert.That(methods.Contains((MethodInfo)MemberInfoExtensions.ExtractFrom <IParent>(i => i.Foo())));
            Assert.That(methods.Contains((MethodInfo)MemberInfoExtensions.ExtractFrom <IChild>(i => i.Bar())));
            Assert.That(methods.Contains((MethodInfo)MemberInfoExtensions.ExtractFrom <IGrandChild>(i => i.Baz())));
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new <see cref="MethodContext"/> instance.
        /// </summary>
        /// <remarks>Calling this constructor is time consuming operation. It is strongly advised to cache the created instances.</remarks>
        public MethodContext(Func <object, object?[], object?> dispatch)
        {
            if (dispatch is null)
            {
                throw new ArgumentNullException(nameof(dispatch));
            }

            ExtendedMemberInfo memberInfo = MemberInfoExtensions.ExtractFrom(dispatch);

            Member   = memberInfo.Member;
            Method   = memberInfo.Method;
            Dispatch = dispatch;
        }