/// <summary> /// Retrieves the dependency property which is referenced by the specified binding expression, if /// the expression is a simple dependency property reference. /// </summary> /// <param name="dataSourceType">The type of the data source to evaluate.</param> /// <param name="expression">The binding expression to evaluate.</param> /// <param name="braces">A value indicating whether the binding expression includes its enclosing braces.</param> /// <returns>The dependency property referenced by the specified expression, or <see langword="null"/> if the specified /// expression is not a simple dependency property reference.</returns> public static DependencyProperty GetSimpleDependencyProperty(Type dataSourceType, String expression, Boolean braces = true) { if (!IsBindingExpression(expression, braces)) { throw new ArgumentException(PresentationStrings.InvalidBindingExpression.Format(expression)); } var expMemberPath = GetBindingMemberPathPart(expression, braces); var expProperty = dataSourceType.GetProperty(expMemberPath); if (expProperty == null) { return(null); } var expAttribute = (CompiledBindingExpressionAttribute)expProperty.GetCustomAttributes(typeof(CompiledBindingExpressionAttribute), false).SingleOrDefault(); if (expAttribute == null) { return(null); } if (expAttribute.SimpleDependencyPropertyOwner == null) { return(null); } return(DependencyProperty.FindByName(expAttribute.SimpleDependencyPropertyName, expAttribute.SimpleDependencyPropertyOwner)); }
/// <summary> /// Determines whether the specified target is a dependency property, routed event, or standard property/event. /// </summary> private static UvmlMutatorTarget GetMutatorTarget(UltravioletContext uv, String name, String value, Type type, out Object target, out Type targetType) { var upf = uv.GetUI().GetPresentationFoundation(); // If this is an attached property/event, find the owner type. var depname = new DependencyName(name); if (depname.IsAttached) { var attachedOwnerType = default(Type); if (!upf.GetKnownType(depname.Owner, out attachedOwnerType)) { throw new UvmlException(PresentationStrings.UnrecognizedType.Format(depname.Owner)); } type = attachedOwnerType; } // Is it a dependency property? var dprop = DependencyProperty.FindByName(depname.Name, type); if (dprop != null) { target = dprop; if (value != null && BindingExpressions.IsBindingExpression(value)) { targetType = typeof(String); return(UvmlMutatorTarget.DependencyPropertyBinding); } targetType = dprop.PropertyType; return(UvmlMutatorTarget.DependencyProperty); } // Is it a routed event? var revt = EventManager.FindByName(depname.Name, type); if (revt != null) { target = revt; targetType = typeof(String); return(UvmlMutatorTarget.RoutedEvent); } // Is it a standard property? var clrprop = type.GetProperty(depname.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (clrprop != null) { target = clrprop; targetType = clrprop.PropertyType; return(UvmlMutatorTarget.StandardProperty); } // Is it a standard event? var clrevt = type.GetEvent(depname.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (clrevt != null) { target = clrevt; targetType = typeof(String); return(UvmlMutatorTarget.StandardEvent); } throw new UvmlException(PresentationStrings.EventOrPropertyDoesNotExist.Format(depname.Name, type.Name)); }