public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value) { var s = (string)value; var lastDot = s.LastIndexOf('.'); if (lastDot == -1) { throw new NotSupportedException("PerspexProperties must currently be fully qualified."); } var typeName = s.Substring(0, lastDot); var propertyName = s.Substring(lastDot + 1); var type = context.TypeRepository.GetByQualifiedName(typeName)?.UnderlyingType; var styleType = context.TypeRepository.GetXamlType(typeof(Style)); // ATTN: SuperJMN //var style = ((XamlTypeConverterContext)context).TopDownValueContext.GetLastInstance(styleType); if (type == null) { throw new XamlParseException($"Could not find type '{typeName}'."); } // First look for non-attached property on the type and then look for an attached property. var property = PerspexObject.GetRegisteredProperties(type) .FirstOrDefault(x => x.Name == propertyName); if (property == null) { property = PerspexObject.GetAttachedProperties(type) .FirstOrDefault(x => x.Name == propertyName); } if (property == null) { throw new XamlParseException( $"Could not find PerspexProperty '{typeName}'.{propertyName}."); } return(property); }
public void GetRegisteredProperties_Returns_Registered_Properties_For_Base_Types() { string[] names = PerspexObject.GetRegisteredProperties(typeof(Class2)).Select(x => x.Name).ToArray(); Assert.Equal(new[] { "Bar", "Flob", "Fred", "Foo", "Baz", "Qux", "Attached" }, names); }