Getinstanceobjgettype try if propertynameindexof

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ameter when /// setting a property value. /// </summary> /// <param name="type">The type to check</param> /// <param name="propertyName">The name of the property</param> /// <returns>The type of the property</returns> public static Type GetPropertyTypeForGetter(Type type, string propertyName) { if (propertyName.IndexOf('.') > -1) { StringTokenizer parser = new StringTokenizer(propertyName, "."); IEnumerator enumerator = parser.GetEnumerator(); while (enumerator.MoveNext()) { propertyName = (string)enumerator.Current; type = ReflectionInfo.GetInstance(type).GetGetterType(propertyName); } } else { type = ReflectionInfo.GetInstance(type).GetGetterType(propertyName); } return type; } private static object GetArrayProperty(object obj, string indexedName) { object value = null; try { int startIndex = indexedName.IndexOf("["); int length = indexedName.IndexOf("]"); string name = indexedName.Substring(0, startIndex); string index = indexedName.Substring( startIndex+1, length-(startIndex+1)); int i = System.Convert.ToInt32(index); if (name.Length > 0) { value = GetProperty(obj, name); } else { value = obj; } if (value is IList) { value = ((IList) value)[i]; } else { throw new ProbeException("The '" + name + "' property of the " + obj.GetType().Name + " class is not a List or Array."); } } catch (ProbeException pe) { throw pe; } catch(Exception e) { throw new ProbeException("Error getting ordinal value from .net object. Cause" + e.Message, e); } return value; } /// <summary> /// /// </summary> /// <param name="obj"></param> /// <param name="propertyName"></param> /// <returns></returns> protected static object GetProperty(object obj, string propertyName) { ReflectionInfo reflectionCache = ReflectionInfo.GetInstance(obj.GetType()); try { object value = null; if (propertyName.IndexOf("[") > -1) { value = GetArray...
View Full Document

Ask a homework question - tutors are online