public static DrawerInfo GetDrawerMethod(Type type) { DrawerInfo drawerInfo; if (!m_drawerMethodsCache.TryGetValue(type, out drawerInfo)) { drawerInfo = new DrawerInfo() { Drawer = null, CopyOp = null, IsNullable = false }; foreach (var drawerClass in m_drawerClasses) { var methods = drawerClass.GetMethods(BindingFlags.Public | BindingFlags.Static); foreach (var method in methods) { if (method.GetCustomAttributes <InspectorDrawerAttribute>().FirstOrDefault(attribute => attribute.Match(type)) != null) { drawerInfo.Drawer = method; FindDrawerResult(ref drawerInfo, drawerClass); m_drawerMethodsCache.Add(type, drawerInfo); break; } } if (drawerInfo.Drawer != null) { break; } } } return(drawerInfo); }
public static void FindDrawerResult(ref DrawerInfo info, Type drawerClass) { if (info.Drawer == null) { return; } var resultAttribute = info.Drawer.GetCustomAttribute <InspectorDrawerResultAttribute>(); if (resultAttribute == null) { return; } info.IsNullable = resultAttribute.IsNullable; info.CopyOp = drawerClass.GetMethod(info.Drawer.Name + "CopyOp", BindingFlags.Public | BindingFlags.Static); }
private static Type GetDrawerCore(Type fieldType) { if (_drawerMap == null) { _drawerMap = new Dictionary <Type, DrawerInfo>(); IEnumerable <Type> drawers = from assembly in AppDomain.CurrentDomain.GetAssemblies() from t in assembly.GetTypes() where t.IsSubclassOf(typeof(DataDrawer)) select t; foreach (Type drawer in drawers) { IEnumerable <CustomDataDrawerAttribute> drawnTypes = from attr in drawer.GetCustomAttributes(typeof(CustomDataDrawerAttribute), false) select attr as CustomDataDrawerAttribute; foreach (CustomDataDrawerAttribute drawn in drawnTypes) { _drawerMap.Add(drawn.Type, new DrawerInfo { DrawerType = drawer, Attr = drawn }); } } } DrawerInfo output = null; Type drawnType = fieldType; do { } while ((drawnType != null) && !((_drawerMap.TryGetValue(drawnType, out output) && ((fieldType == drawnType) || output.Attr.UseForSubclass)) || ((drawnType = drawnType.BaseType) == null)) ); if ((output == null) && fieldType.IsEnum) { if (fieldType.GetCustomAttributes(typeof(FlagsAttribute), false).Any()) { return(typeof(EnumMaskDrawer)); } return(typeof(EnumDrawer)); } return(output?.DrawerType); }