using System.Collections.Generic; using System.Linq; using JD.Reflection; using JD.Reflection.Attributes; using TeaBox; using TeaBox.Gui.PropertyGrid; using UAFPropertyEditorAttribute = JD.Interfaces.Editors.PropertyEditorAttribute; namespace JD.Controls { [Export(typeof(ICellGetters))] public class CellGetters : ICellGetters { public ICellViewer GetViewer(IGridDataRow row) { return row.Attributes.OfType() .Concat(row.ValueType.GetAttributes(true)) .Select(attribute => attribute.GetEditor()) .FirstOrDefault(viewer => viewer != null); } public CellEditor GetEditor(IGridDataRow row) { var cellEditor = GetTypeFromPropertyEditorAttribute(row); if (cellEditor != null) { return cellEditor; } var editorAttribute = GetTypeFromPropertyEditorAttribute(row) ?? row.GetAttributeByInterface() ?? row.ValueType.GetAttribute(); if (editorAttribute != null) { return editorAttribute.GetEditor(row); } return null; } public IEnumerable GetEditorExtensionProviderAttributes(IAttributeProvider provider) { var editorAttributes = provider.Attributes.OfType(); return editorAttributes.SelectMany(attribute => attribute.GetEditors()); } private T GetTypeFromPropertyEditorAttribute(IAttributeProvider attributeProvider) where T : class { var attribute = attributeProvider.GetAttributeByInterface(); return attribute != null ? attribute.GetEditor() : null; } } }