// Token: 0x0600069B RID: 1691 RVA: 0x00014F1C File Offset: 0x0001311C
 private void ApplyAutoAliasRules()
 {
     if (typeof(ContentPresenter).IsAssignableFrom(this._type))
     {
         object value = this.GetValue(ContentPresenter.ContentSourceProperty);
         string text  = (value == DependencyProperty.UnsetValue) ? "Content" : ((string)value);
         if (!string.IsNullOrEmpty(text) && !this.IsValueDefined(ContentPresenter.ContentProperty))
         {
             Type targetTypeInternal = this._frameworkTemplate.TargetTypeInternal;
             DependencyProperty dependencyProperty  = DependencyProperty.FromName(text, targetTypeInternal);
             DependencyProperty dependencyProperty2 = DependencyProperty.FromName(text + "Template", targetTypeInternal);
             DependencyProperty dependencyProperty3 = DependencyProperty.FromName(text + "TemplateSelector", targetTypeInternal);
             DependencyProperty dependencyProperty4 = DependencyProperty.FromName(text + "StringFormat", targetTypeInternal);
             if (dependencyProperty == null && value != DependencyProperty.UnsetValue)
             {
                 throw new InvalidOperationException(SR.Get("MissingContentSource", new object[]
                 {
                     text,
                     targetTypeInternal
                 }));
             }
             if (dependencyProperty != null)
             {
                 this.SetValue(ContentPresenter.ContentProperty, new TemplateBindingExtension(dependencyProperty));
             }
             if (!this.IsValueDefined(ContentPresenter.ContentTemplateProperty) && !this.IsValueDefined(ContentPresenter.ContentTemplateSelectorProperty) && !this.IsValueDefined(ContentPresenter.ContentStringFormatProperty))
             {
                 if (dependencyProperty2 != null)
                 {
                     this.SetValue(ContentPresenter.ContentTemplateProperty, new TemplateBindingExtension(dependencyProperty2));
                 }
                 if (dependencyProperty3 != null)
                 {
                     this.SetValue(ContentPresenter.ContentTemplateSelectorProperty, new TemplateBindingExtension(dependencyProperty3));
                 }
                 if (dependencyProperty4 != null)
                 {
                     this.SetValue(ContentPresenter.ContentStringFormatProperty, new TemplateBindingExtension(dependencyProperty4));
                     return;
                 }
             }
         }
     }
     else if (typeof(GridViewRowPresenter).IsAssignableFrom(this._type))
     {
         if (!this.IsValueDefined(GridViewRowPresenter.ContentProperty))
         {
             Type targetTypeInternal2 = this._frameworkTemplate.TargetTypeInternal;
             DependencyProperty dependencyProperty5 = DependencyProperty.FromName("Content", targetTypeInternal2);
             if (dependencyProperty5 != null)
             {
                 this.SetValue(GridViewRowPresenter.ContentProperty, new TemplateBindingExtension(dependencyProperty5));
             }
         }
         if (!this.IsValueDefined(GridViewRowPresenterBase.ColumnsProperty))
         {
             this.SetValue(GridViewRowPresenterBase.ColumnsProperty, new TemplateBindingExtension(GridView.ColumnCollectionProperty));
         }
     }
 }
        public override object ConvertFromString(string value, IValueSerializerContext context)
        {
            ValueSerializer typeSerializer = ValueSerializer.GetSerializerFor(typeof(Type), context);

            if (typeSerializer != null)
            {
                int dotIndex = value.IndexOf('.');
                if (dotIndex >= 0)
                {
                    string typeName  = value.Substring(0, dotIndex - 1);
                    Type   ownerType = typeSerializer.ConvertFromString(typeName, context) as Type;
                    if (ownerType != null)
                    {
                        return(DependencyProperty.FromName(typeName, ownerType));
                    }
                }
            }
            throw GetConvertFromException(value);
        }
        private DependencyProperty Parse(string path)
        {
            string[] parts = path.Split('.');

            string typename = parts[0].Trim();
            string property = parts[1].Trim();

            if (typename == string.Empty || typename.StartsWith("(") == false)
            {
                throw new ArgumentException(string.Format("( expected)"));
            }

            if (property == string.Empty || property.EndsWith(")") == false)
            {
                throw new ArgumentException(string.Format(") expected)"));
            }

            // remove the ( from the type specifier
            typename = typename.Substring(1);

            Type type = null;

            foreach (string ns in _namespaces)
            {
                type = Type.GetType(ns + "." + typename);

                if (type != null)
                {
                    break;
                }
            }

            if (type == null)
            {
                throw new ArgumentException(string.Format("The type or namespace '{0}' could not be found", type));
            }

            // remove the ) from the property name
            property = property.Substring(0, property.Length - 1);

            return(DependencyProperty.FromName(property, type));
        }
Пример #4
0
        // 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);
            }
        }
Пример #5
0
        // 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);
        }