public static int Compare(Behavior behavior1, Behavior behavior2) { var orderAttribute1 = behavior1.GetType().GetAttribute<OrderAttribute>(); var categoryAttribute1 = behavior1.GetType().GetAttribute<CategoryAttribute>(); var orderAttribute2 = behavior2.GetType().GetAttribute<OrderAttribute>(); var categoryAttribute2 = behavior2.GetType().GetAttribute<CategoryAttribute>(); if (orderAttribute2 == null || categoryAttribute2 == null) { return 1; } if (orderAttribute1 == null || categoryAttribute1 == null) { return -1; } var categoryIndex1 = GetCategoryIndex(categoryAttribute1.Category); var categoryIndex2 = GetCategoryIndex(categoryAttribute2.Category); if (categoryIndex1 == categoryIndex2) { return orderAttribute1.Order.CompareTo(orderAttribute2.Order); } return categoryIndex1.CompareTo(categoryIndex2); }
public static string GetCategory(Behavior behavior) { if (behavior is UserDefinedTool) { return BehaviorCategories.Custom; } var result = BehaviorCategories.Misc; var categoryAttribute = behavior.GetType().GetAttribute<CategoryAttribute>(); if (categoryAttribute != null) { result = categoryAttribute.Category; } return result; }