Is Conform With Binding Flags - CSharp System.Reflection

CSharp examples for System.Reflection:Binding

Description

Is Conform With Binding Flags

Demo Code


using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System;//  ww w. j ava 2  s  .  co m

public class Main{
        private static bool IsConformWithBindingFlags(FieldInfo method, BindingFlags bindingFlags)
        {
            if (method.IsPublic && !bindingFlags.HasFlag(BindingFlags.Public))
                return false;
            if (method.IsPrivate && !bindingFlags.HasFlag(BindingFlags.NonPublic))
                return false;
            if (method.IsStatic && !bindingFlags.HasFlag(BindingFlags.Static))
                return false;
            if (!method.IsStatic && !bindingFlags.HasFlag(BindingFlags.Instance))
                return false;

            return true;
        }
        private static bool IsConformWithBindingFlags(MethodBase method, BindingFlags bindingFlags)
        {
            if (method.IsPublic && !bindingFlags.HasFlag(BindingFlags.Public))
                return false;
            if (method.IsPrivate && !bindingFlags.HasFlag(BindingFlags.NonPublic))
                return false;
            if (method.IsStatic && !bindingFlags.HasFlag(BindingFlags.Static))
                return false;
            if (!method.IsStatic && !bindingFlags.HasFlag(BindingFlags.Instance))
                return false;

            return true;
        }
}

Related Tutorials