Is Accessible Property - CSharp System.Reflection

CSharp examples for System.Reflection:PropertyInfo

Description

Is Accessible Property

Demo Code


using System.Reflection;
using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*  ww  w .ja  v a  2s  .  co  m*/

public class Main{
        public static bool IsAccessibleProperty(this PropertyInfo property, bool readCheck, bool writeCheck)
        {
            bool result = true;
            MethodInfo tmp;
            if (readCheck)
            {
                tmp = property.GetMethod;
                result &= property.CanRead && tmp.IsPublic && !tmp.IsStatic;
            }
            if (writeCheck)
            {
                tmp = property.SetMethod;
                result &= property.CanWrite && tmp.IsPublic && !tmp.IsStatic;
            }

            return result;
        }
}

Related Tutorials