Gettypefullnamegethashcode foreach object simpleobject

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: ich to invoke the specified property.</param> /// <param name="propertyName">The name of the property to set.</param> /// <param name="propertyValue">The new value to set.</param> public static void SetPropertyValue(object obj, string propertyName, object propertyValue) { if (propertyName.IndexOf('.') > -1) { StringTokenizer parser = new StringTokenizer(propertyName, "."); IEnumerator enumerator = parser.GetEnumerator(); enumerator.MoveNext(); string currentPropertyName = (string)enumerator.Current; object child = obj; while (enumerator.MoveNext()) { Type type = GetPropertyTypeForSetter(child, currentPropertyName); object parent = child; child = GetProperty(parent, currentPropertyName); if (child == null) { try { child = Activator.CreateInstance(type); SetPropertyValue(parent, currentPropertyName, child); } catch (Exception e) { throw new ProbeException("Cannot set value of property '" + propertyName + "' because '" + currentPropertyName + "' is null and cannot be instantiated on instance of " + type.Name + ". Cause:" + e.Message, e); } } currentPropertyName = (string)enumerator.Current; } SetProperty(child, currentPropertyName, propertyValue); } else { SetProperty(obj, propertyName, propertyValue); } } /// <summary> /// Checks to see if a Object has a writable property/field be a given name /// </summary> /// <param name="obj"> The object to check</param> /// <param name="propertyName">The property to check for</param> /// <returns>True if the property exists and is writable</returns> public static bool HasWritableProperty(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 ty...
View Full Document

Ask a homework question - tutors are online