示例#1
0
        /// <summary>
        /// Gets all properties of the deriving class
        /// </summary>
        /// <param name="accessType">The <see cref="PropertyAccessType"/> of the properties (optional, default = Read | Write)</param>
        /// <param name="onlyPublic"><see langword="true"/> to get only public properties, otherwise <see langword="false"/> (optional, default = <see langword="true"/></param>
        /// <returns></returns>
        protected List <string> GetProperties(PropertyAccessType accessType = PropertyAccessType.Read | PropertyAccessType.Write, bool onlyPublic = true)
        {
            if (!GetType().IsClass)
            {
                return(new List <string>());
            }

            List <PropertyInfo> properties;

            switch ((int)accessType)
            {
            case 1:
                properties = GetType().GetProperties().Where(w => w.CanRead).ToList();
                break;

            case 2:
                properties = GetType().GetProperties().Where(w => w.CanWrite).ToList();
                break;

            case 3:
                properties = GetType().GetProperties().Where(w => w.CanRead && w.CanWrite).ToList();
                break;

            default:
                properties = GetType().GetProperties().ToList();
                break;
            }

            return(onlyPublic
                ? properties.Where(w => w.GetMethod.IsPublic).Select(s => s.Name).ToList()
                : properties.Select(s => s.Name).ToList());
        }
示例#2
0
 public BusinessProperty(Type classType, Type propertyType, string name, bool isNullable,
                         PropertyAccessType accessType)
 {
     _classType    = classType;
     _propertyType = propertyType;
     _name         = name;
     _isNullable   = isNullable;
     _accessType   = accessType;
 }
        /// <summary>
        /// Get properties
        /// </summary>
        /// <param name="type"></param>
        /// <param name="accessType"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="InvalidOperationException"></exception>
        public static IEnumerable <PropertyInfo> GetProperties(this Type type, PropertyAccessType accessType)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            switch (accessType)
            {
            case PropertyAccessType.Getters:
                return(type.GetPropertiesWithPublicInstanceGetters());

            case PropertyAccessType.Setters:
                return(type.GetPropertiesWithPublicInstanceSetters());

            default:
                throw new InvalidOperationException("Invalid operation for unknown access type");
            }
        }
示例#4
0
 public StringProperty(string name, bool isNullable, PropertyAccessType accessType)
     : base(name, isNullable, accessType)
 {
 }
 /// <summary>
 /// Get properties
 /// </summary>
 /// <param name="accessType"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static IEnumerable <PropertyInfo> GetProperties <T>(PropertyAccessType accessType) => typeof(T).GetProperties(accessType);