// Token: 0x060007BD RID: 1981 RVA: 0x00018390 File Offset: 0x00016590 private object ResolvePropertyName(string name, object item, Type ownerType, object context, bool throwOnError) { string text = name; int num; if (PropertyPath.IsParameterIndex(name, out num)) { if (0 <= num && num < this.PathParameters.Count) { object obj = this.PathParameters[num]; if (!PropertyPath.IsValidAccessor(obj)) { throw new InvalidOperationException(SR.Get("PropertyPathInvalidAccessor", new object[] { (obj != null) ? obj.GetType().FullName : "null" })); } return(obj); } else { if (throwOnError) { throw new InvalidOperationException(SR.Get("PathParametersIndexOutOfRange", new object[] { num, this.PathParameters.Count })); } return(null); } } else { if (PropertyPath.IsPropertyReference(name)) { name = name.Substring(1, name.Length - 2); int num2 = name.LastIndexOf('.'); if (num2 >= 0) { text = name.Substring(num2 + 1).Trim(); string text2 = name.Substring(0, num2).Trim(); ownerType = this.GetTypeFromName(text2, context); if (ownerType == null && throwOnError) { throw new InvalidOperationException(SR.Get("PropertyPathNoOwnerType", new object[] { text2 })); } } else { text = name; } } if (!(ownerType != null)) { return(null); } object obj2 = DependencyProperty.FromName(text, ownerType); if (obj2 == null && item is ICustomTypeDescriptor) { obj2 = TypeDescriptor.GetProperties(item)[text]; } if (obj2 == null && (item is INotifyPropertyChanged || item is DependencyObject)) { obj2 = this.GetPropertyHelper(ownerType, text); } if (obj2 == null && item != null) { obj2 = TypeDescriptor.GetProperties(item)[text]; } if (obj2 == null) { obj2 = this.GetPropertyHelper(ownerType, text); } if (obj2 == null && SystemCoreHelper.IsIDynamicMetaObjectProvider(item)) { obj2 = SystemCoreHelper.NewDynamicPropertyAccessor(item.GetType(), text); } if (obj2 == null && throwOnError) { throw new InvalidOperationException(SR.Get("PropertyPathNoProperty", new object[] { ownerType.Name, text })); } return(obj2); } }
// resolve a single DP name object ResolvePropertyName(string name, object item, Type ownerType, object context, bool throwOnError) { string propertyName = name; int index; // first see if the name is an index into the parameter list if (IsParameterIndex(name, out index)) { if (0 <= index && index < PathParameters.Count) { object accessor = PathParameters[index]; // always throw if the accessor isn't valid - this error cannot // be corrected later on. if (!IsValidAccessor(accessor)) { throw new InvalidOperationException(SR.Get(SRID.PropertyPathInvalidAccessor, (accessor != null) ? accessor.GetType().FullName : "null")); } return(accessor); } else if (throwOnError) { throw new InvalidOperationException(SR.Get(SRID.PathParametersIndexOutOfRange, index, PathParameters.Count)); } else { return(null); } } // handle attached-property syntax: (TypeName.PropertyName) if (IsPropertyReference(name)) { name = name.Substring(1, name.Length - 2); int lastIndex = name.LastIndexOf('.'); if (lastIndex >= 0) { // attached property - get the owner type propertyName = name.Substring(lastIndex + 1).Trim(); string ownerName = name.Substring(0, lastIndex).Trim(); ownerType = GetTypeFromName(ownerName, context); if (ownerType == null && throwOnError) { throw new InvalidOperationException(SR.Get(SRID.PropertyPathNoOwnerType, ownerName)); } } else { // simple name in parens - just strip the parens propertyName = name; } } if (ownerType != null) { // get an appropriate accessor from the ownerType and propertyName. // We prefer accessors in a certain order, defined below. object accessor; // 1. DependencyProperty on the given type. accessor = DependencyProperty.FromName(propertyName, ownerType); // 2. PropertyDescriptor from item's custom lookup. // When the item implements custom properties, we must use them. if (accessor == null && item is ICustomTypeDescriptor) { accessor = TypeDescriptor.GetProperties(item)[propertyName]; } // 3a. PropertyInfo, when item exposes INotifyPropertyChanged. // 3b. PropertyInfo, when item is a DependencyObject (bug 1373351). // This uses less working set than PropertyDescriptor, and we don't need // the ValueChanged pattern. (If item is a DO and wants to raise // change notifications, it should make the property a DP.) if (accessor == null && (item is INotifyPropertyChanged || item is DependencyObject)) { accessor = GetPropertyHelper(ownerType, propertyName); } // 4. PropertyDescriptor (obtain from item - this is reputedly // slower than obtaining from type, but the latter doesn't // discover properties obtained from TypeDescriptorProvider - // see bug 1713000). // This supports the WinForms ValueChanged pattern. if (accessor == null && item != null) { accessor = TypeDescriptor.GetProperties(item)[propertyName]; } // 5. PropertyInfo. if (accessor == null) { accessor = GetPropertyHelper(ownerType, propertyName); } // 6. IDynamicMetaObjectProvider // This supports the DLR's dynamic objects if (accessor == null && SystemCoreHelper.IsIDynamicMetaObjectProvider(item)) { accessor = SystemCoreHelper.NewDynamicPropertyAccessor(item.GetType(), propertyName); } if (accessor == null && throwOnError) { throw new InvalidOperationException(SR.Get(SRID.PropertyPathNoProperty, ownerType.Name, propertyName)); } return(accessor); } return(null); }