private static void ParseControlAttributes(ConsoleControl control, ParserContext context)
{
foreach (var attribute in context.CurrentElement.Attributes)
{
var extensions = control.GetType().Attrs<MarkupExtensionAttribute>().Where(a => a.AttributeName == attribute.Name);
if(extensions.Count() > 1)
{
throw new InvalidOperationException("More than 1 extension registered for property "+attribute.Name);
}
else if(extensions.Count() == 1)
{
extensions.First().Processor.Process(context);
}
else
{
var propertyInfo = control.GetType().GetProperty(attribute.Name);
var methodInfo = control.GetType().GetMethod(attribute.Name);
if (propertyInfo.GetGetMethod() == null || propertyInfo.GetSetMethod() == null)
{
if (propertyInfo.PropertyType == typeof(Event))
{
// there is special handling for events downstream so let this through
}
else
{
throw new InvalidOperationException($"Property {control.GetType().FullName}.{attribute.Name} does not have a public getter and setter");
}
}
SetPropertyFromTextValue(context, control, propertyInfo, attribute.Value);
}
}
}