/// <summary>
        /// Initialises an instance of the actual security type.
        /// </summary>
        /// <param name="name">The name of the type to find.</param>
        /// <returns>The security type, or an instance of <see cref="ServerSecurity"/> if the security type
        /// is unknown.</returns>
        private ServerSecurity InitialiseActualType(string name)
        {
            ServerSecurity value = new ServerSecurity();

            // Retrieve all the types that inherit from ServerSecurity and attempt to find one that has
            // a matching reflector name.
            List <Type> serverSecurityModes = Util.GetAllServerSecurityModes();

            foreach (Type securityMode in serverSecurityModes)
            {
                ReflectorNameAttribute attribute = Util.GetCustomAttribute <ReflectorNameAttribute>(securityMode);
                if ((attribute != null) && (attribute.Name == name))
                {
                    // Once the matching name has been found, instantiate an instance and exit
                    value = Activator.CreateInstance(securityMode) as ServerSecurity;
                    break;
                }
            }

            return(value);
        }
Example #2
0
        /// <summary>
        /// Gets a list of properties for the specified object that contain a reflector name attribute,
        /// do not have a reflector ignore attribute and are publicly readable and writeable.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns></returns>
        public List <PropertyInfo> GetReflectorProperies(T obj)
        {
            List <PropertyInfo> props = new List <PropertyInfo> ();
            Type objType = obj.GetType();

            PropertyInfo [] propArray = objType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            foreach (PropertyInfo pi in propArray)
            {
                // see if the property has a reflector name attribute
                ReflectorNameAttribute rna = Util.GetCustomAttribute <ReflectorNameAttribute> (pi);
                // make sure it doesn't have a reflector ignore attribute
                ReflectorIgnoreAttribute ria = Util.GetCustomAttribute <ReflectorIgnoreAttribute> (pi);
                // we also need to check that both the get and set methods of the property are public.
                bool canRead  = pi.CanRead && pi.GetGetMethod(false) != null;
                bool canWrite = pi.CanRead && pi.GetSetMethod(false) != null;
                if (rna != null && ria == null && canRead && canWrite)
                {
                    props.Add(pi);
                }
            }
            return(props);
        }