Is Type Child Of another Type - CSharp System

CSharp examples for System:Type

Description

Is Type Child Of another Type

Demo Code


using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from ww w. ja v  a  2  s .  co m

public class Main{
        public static bool IsChildOf(this Type tc, Type tf)
        {
            if (tf.IsInterface)
            {
                return tc.GetInterfaces().Any(type => type.Equals(tf));
            }
            return tc.IsSubclassOf(tf);
        }
}

Related Tutorials