예제 #1
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);
 }
예제 #2
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));
 }
예제 #3
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));
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
0
 /// <summary>
 /// Gets an instance of ReflectionInfo for the specified type.
 /// </summary>summary>
 /// <param name="type">The type for which to lookup the method cache.</param>
 /// <returns>The properties cache for the type</returns>
 public static ReflectionInfo GetInstance(Type type)
 {
     lock (type)
     {
         ReflectionInfo cache = (ReflectionInfo) _reflectionInfoMap[type];
         if (cache == null)
         {
             cache = new ReflectionInfo(type);
             _reflectionInfoMap.Add(type, cache);
         }
         return cache;
     }
 }
예제 #7
0
 public static string[] GetWriteableMemberNames(object obj)
 {
     return(ReflectionInfo.GetInstance(obj.GetType()).GetWriteableMemberNames());
 }
예제 #8
0
 public static string[] GetReadablePropertyNames(object obj)
 {
     return(ReflectionInfo.GetInstance(obj.GetType()).GetReadableMemberNames());
 }