Is MemberInfo Readonly - CSharp System.Reflection

CSharp examples for System.Reflection:MethodInfo

Description

Is MemberInfo Readonly

Demo Code


using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System;//from  www  . ja v a2s  .c om

public class Main{
    public static bool IsReadonly(this MemberInfo member)
      {
         if (member is FieldInfo)
         {
            return ((FieldInfo)member).IsInitOnly || ((FieldInfo)member).IsLiteral;
         }
         else if (member is PropertyInfo)
         {
            return !((PropertyInfo)member).CanWrite || ((PropertyInfo)member).GetSetMethod() == null ||
               !((PropertyInfo)member).GetSetMethod().IsPublic;
         }
         return true;
      }
}

Related Tutorials