Example #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);
        }
Example #2
0
        public static Type GetMemberTypeForSetter(object obj, string memberName)
        {
            Type setterType = obj.GetType();

            if (obj is IDictionary)
            {
                IDictionary dictionary = (IDictionary)obj;
                object      obj2       = dictionary[memberName];
                if (obj2 == null)
                {
                    return(typeof(object));
                }
                return(obj2.GetType());
            }
            if (memberName.IndexOf('.') > -1)
            {
                IEnumerator enumerator = new StringTokenizer(memberName, ".").GetEnumerator();
                while (enumerator.MoveNext())
                {
                    memberName = (string)enumerator.Current;
                    setterType = ReflectionInfo.GetInstance(setterType).GetSetterType(memberName);
                }
                return(setterType);
            }
            return(ReflectionInfo.GetInstance(setterType).GetSetterType(memberName));
        }
Example #3
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);
        }
Example #4
0
 public static Type GetMemberTypeForGetter(Type type, string memberName)
 {
     if (memberName.IndexOf('.') > -1)
     {
         IEnumerator enumerator = new StringTokenizer(memberName, ".").GetEnumerator();
         while (enumerator.MoveNext())
         {
             memberName = (string)enumerator.Current;
             type       = ReflectionInfo.GetInstance(type).GetGetterType(memberName);
         }
         return(type);
     }
     type = ReflectionInfo.GetInstance(type).GetGetterType(memberName);
     return(type);
 }
Example #5
0
 public static MemberInfo GetMemberInfoForSetter(Type type, string memberName)
 {
     if (memberName.IndexOf('.') > -1)
     {
         IEnumerator enumerator = new StringTokenizer(memberName, ".").GetEnumerator();
         Type        type2      = null;
         while (enumerator.MoveNext())
         {
             memberName = (string)enumerator.Current;
             type2      = type;
             type       = ReflectionInfo.GetInstance(type).GetSetterType(memberName);
         }
         return(ReflectionInfo.GetInstance(type2).GetSetter(memberName));
     }
     return(ReflectionInfo.GetInstance(type).GetSetter(memberName));
 }
Example #6
0
        public static bool HasWritableProperty(object obj, string propertyName)
        {
            bool flag = false;

            if (obj is IDictionary)
            {
                return(((IDictionary)obj).Contains(propertyName));
            }
            if (propertyName.IndexOf('.') > -1)
            {
                IEnumerator enumerator = new StringTokenizer(propertyName, ".").GetEnumerator();
                Type        getterType = obj.GetType();
                while (enumerator.MoveNext())
                {
                    propertyName = (string)enumerator.Current;
                    getterType   = ReflectionInfo.GetInstance(getterType).GetGetterType(propertyName);
                    flag         = ReflectionInfo.GetInstance(getterType).HasWritableMember(propertyName);
                }
                return(flag);
            }
            return(ReflectionInfo.GetInstance(obj.GetType()).HasWritableMember(propertyName));
        }
Example #7
0
        /// <summary>
        ///  Returns the type that the set expects to receive as a parameter when
        ///  setting a member value.
        /// </summary>
        /// <param name="type">The class type to check</param>
        /// <param name="memberName">The name of the member</param>
        /// <returns>The type of the member</returns>
        public static Type GetMemberTypeForSetter(Type type, string memberName)
        {
            Type memberType = type;

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

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

            return(memberType);
        }
Example #8
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);
        }
Example #9
0
 public static string[] GetWriteableMemberNames(object obj)
 {
     return(ReflectionInfo.GetInstance(obj.GetType()).GetWriteableMemberNames());
 }
Example #10
0
 public static string[] GetReadablePropertyNames(object obj)
 {
     return(ReflectionInfo.GetInstance(obj.GetType()).GetReadableMemberNames());
 }