/// <summary> /// Helper method to find the Property <c>set</c>. /// </summary> /// <param name="type">The <see cref="System.Type"/> to find the Property in.</param> /// <param name="propertyName">The name of the mapped Property to set.</param> /// <returns> /// The <see cref="BasicSetter"/> for the Property <c>set</c> or <c>null</c> /// if the Property could not be found. /// </returns> internal static BasicSetter GetSetterOrNull(System.Type type, string propertyName) { if (type == typeof(object) || type == null) { // the full inheritance chain has been walked and we could // not find the Property get return(null); } PropertyInfo property = type.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); if (property != null) { return(new BasicSetter(type, property, propertyName)); } else { // recursively call this method for the base Type BasicSetter setter = GetSetterOrNull(type.BaseType, propertyName); // didn't find anything in the base class - check to see if there is // an explicit interface implementation. if (setter == null) { System.Type[] interfaces = type.GetInterfaces(); for (int i = 0; setter == null && i < interfaces.Length; i++) { setter = GetSetterOrNull(interfaces[i], propertyName); } } return(setter); } }
/// <summary> /// Create a <see cref="BasicSetter"/> for the mapped property. /// </summary> /// <param name="type">The <see cref="System.Type"/> to find the Property in.</param> /// <param name="propertyName">The name of the mapped Property to get.</param> /// <returns> /// The <see cref="BasicSetter"/> to use to set the value of the Property on an /// instance of the <see cref="System.Type"/>. /// </returns> /// <exception cref="PropertyNotFoundException" > /// Thrown when a Property specified by the <c>propertyName</c> could not /// be found in the <see cref="System.Type"/>. /// </exception> public ISetter GetSetter(System.Type type, string propertyName) { BasicSetter result = GetSetterOrNull(type, propertyName); if (result == null) { throw new PropertyNotFoundException(type, propertyName, "setter"); } return(result); }