예제 #1
0
        /// <summary>
        /// Checks to see if the Object have a property/field be a given name.
        /// </summary>
        /// <param name="obj">The Object on which to invoke the specified property.</param>
        /// <param name="propertyName">The name of the property to check for.</param>
        /// <returns>
        /// True or false if the property exists and is readable.
        /// </returns>
        public static bool HasReadableProperty(object obj, string propertyName)
        {
            bool hasProperty = false;

            if (obj is IDictionary)
            {
                hasProperty = ((IDictionary)obj).Contains(propertyName);
            }
            else
            {
                if (propertyName.IndexOf('.') > -1)
                {
                    StringTokenizer parser     = new StringTokenizer(propertyName, ".");
                    IEnumerator     enumerator = parser.GetEnumerator();
                    Type            type       = obj.GetType();

                    while (enumerator.MoveNext())
                    {
                        propertyName = (string)enumerator.Current;
                        type         = ReflectionInfo.GetInstance(type).GetGetterType(propertyName);
                        hasProperty  = ReflectionInfo.GetInstance(type).HasReadableMember(propertyName);
                    }
                }
                else
                {
                    hasProperty = ReflectionInfo.GetInstance(obj.GetType()).HasReadableMember(propertyName);
                }
            }

            return(hasProperty);
        }
예제 #2
0
        /// <summary>
        ///  Returns the MemberInfo of the set member on the specified type.
        /// </summary>
        /// <param name="type">The type to check</param>
        /// <param name="memberName">The name of the member</param>
        /// <returns>The type of the member</returns>
        public static MemberInfo GetMemberInfoForSetter(Type type, string memberName)
        {
            MemberInfo memberInfo = null;

            if (memberName.IndexOf('.') > -1)
            {
                StringTokenizer parser     = new StringTokenizer(memberName, ".");
                IEnumerator     enumerator = parser.GetEnumerator();
                Type            parentType = null;

                while (enumerator.MoveNext())
                {
                    memberName = (string)enumerator.Current;
                    parentType = type;
                    type       = ReflectionInfo.GetInstance(type).GetSetterType(memberName);
                }
                memberInfo = ReflectionInfo.GetInstance(parentType).GetSetter(memberName);
            }
            else
            {
                memberInfo = ReflectionInfo.GetInstance(type).GetSetter(memberName);
            }

            return(memberInfo);
        }
예제 #3
0
        /// <summary>
        ///  Returns the type that the get expects to receive as a parameter when
        ///  setting a member value.
        /// </summary>
        /// <param name="type">The type to check</param>
        /// <param name="memberName">The name of the member</param>
        /// <returns>The type of the member</returns>
        public static Type GetMemberTypeForGetter(Type type, string memberName)
        {
            if (memberName.IndexOf('.') > -1)
            {
                StringTokenizer parser     = new StringTokenizer(memberName, ".");
                IEnumerator     enumerator = parser.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    memberName = (string)enumerator.Current;
                    type       = ReflectionInfo.GetInstance(type).GetGetterType(memberName);
                }
            }
            else
            {
                type = ReflectionInfo.GetInstance(type).GetGetterType(memberName);
            }

            return(type);
        }
예제 #4
0
        /// <summary>
        ///  Returns the type that the get expects to receive as a parameter when
        ///  setting a member value.
        /// </summary>
        /// <param name="obj">The object to check</param>
        /// <param name="memberName">The name of the member</param>
        /// <returns>The type of the member</returns>
        public static Type GetMemberTypeForGetter(object obj, string memberName)
        {
            Type type = obj.GetType();

            if (obj is IDictionary)
            {
                IDictionary map   = (IDictionary)obj;
                object      value = map[memberName];
                if (value == null)
                {
                    type = typeof(object);
                }
                else
                {
                    type = value.GetType();
                }
            }
            else
            {
                if (memberName.IndexOf('.') > -1)
                {
                    StringTokenizer parser     = new StringTokenizer(memberName, ".");
                    IEnumerator     enumerator = parser.GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        memberName = (string)enumerator.Current;
                        type       = ReflectionInfo.GetInstance(type).GetGetterType(memberName);
                    }
                }
                else
                {
                    type = ReflectionInfo.GetInstance(type).GetGetterType(memberName);
                }
            }

            return(type);
        }
예제 #5
0
 /// <summary>
 /// Returns an array of the writeable members name exposed by a object
 /// </summary>
 /// <param name="obj">The object</param>
 /// <returns>The members name</returns>
 public static string[] GetWriteableMemberNames(object obj)
 {
     return(ReflectionInfo.GetInstance(obj.GetType()).GetWriteableMemberNames());
 }
예제 #6
0
 /// <summary>
 /// Returns an array of the readable properties names exposed by an object
 /// </summary>
 /// <param name="obj">The object</param>
 /// <returns>The properties name</returns>
 public static string[] GetReadablePropertyNames(object obj)
 {
     return(ReflectionInfo.GetInstance(obj.GetType()).GetReadableMemberNames());
 }