/// <summary> /// Returns all fields/properties/methods on the type that pass the given filter. /// </summary> /// <param name="filter">The filter to use. You may be interested in some predefined /// filters available in the InspectedMemberFilters type.</param> public List <InspectedMember> GetMembers(IInspectedMemberFilter filter) { VerifyNotCollection(); List <InspectedMember> members; if (_cachedMembers.TryGetValue(filter, out members) == false) { // Not in the cache. Run each item through the filter and then cache the result. members = new List <InspectedMember>(); for (int i = 0; i < _allMembers.Count; ++i) { var member = _allMembers[i]; bool allow; if (member.IsProperty) { allow = filter.IsInterested(member.Property); } else { allow = filter.IsInterested(member.Method); } if (allow) { members.Add(member); } } _cachedMembers[filter] = members; } return(members); }
/// <summary> /// The categories that are used for this type. If the type has no categories defined, then /// this will be empty. /// </summary> public Dictionary <string, List <InspectedMember> > GetCategories(IInspectedMemberFilter filter) { VerifyNotCollection(); Dictionary <string, List <InspectedMember> > categories; if (_categoryCache.TryGetValue(filter, out categories) == false) { // Not in the cache - actually compute the result. // NOTE: we update the cache before actually doing the computation - if for whatever // reason there is an error, we will not redo this computation and just return // an empty result. categories = new Dictionary <string, List <InspectedMember> >(); _categoryCache[filter] = categories; foreach (var member in GetMembers(filter)) { foreach (InspectorCategoryAttribute attr in member.MemberInfo.GetCustomAttributes(typeof(InspectorCategoryAttribute), /*inherit:*/ true)) { if (categories.ContainsKey(attr.Category) == false) { categories[attr.Category] = new List <InspectedMember>(); } categories[attr.Category].Add(member); } } } return(categories); }
/// <summary> /// Returns all methods on the type that pass the filter. /// </summary> /// <param name="filter"> /// The filter to use. You may be interested in some predefined filters /// available in the InspectedMemberFilters type. /// </param> public List <InspectedMethod> GetMethods(IInspectedMemberFilter filter) { VerifyNotCollection(); List <InspectedMethod> methods; if (_cachedMethods.TryGetValue(filter, out methods) == false) { var members = GetMembers(filter); methods = (from member in members where member.IsMethod select member.Method).ToList(); _cachedMethods[filter] = methods; } return(methods); }
/// <summary> /// Returns all fields/properties on the type that pass the given filter. /// </summary> /// <param name="filter"> /// The filter to use. You may be interested in some predefined filters /// available in the InspectedMemberFilters type. /// </param> public List <InspectedProperty> GetProperties(IInspectedMemberFilter filter) { VerifyNotCollection(); List <InspectedProperty> properties; if (_cachedProperties.TryGetValue(filter, out properties) == false) { var members = GetMembers(filter); properties = (from member in members where member.IsProperty select member.Property).ToList(); _cachedProperties[filter] = properties; } return(properties); }
/// <summary> /// The categories that are used for this type. If the type has no /// categories defined, then this will be empty. /// </summary> public Dictionary <string, List <InspectedMember> > GetCategories(IInspectedMemberFilter filter) { VerifyNotCollection(); Dictionary <string, List <InspectedMember> > categories; if (_categoryCache.TryGetValue(filter, out categories) == false) { var defaultCategories = (from oattribute in ReflectedType.Resolve().GetCustomAttributes(typeof(InspectorCategoryAttribute), /*inherit:*/ true) let attribute = (InspectorCategoryAttribute)oattribute select attribute.Category).ToList(); // Not in the cache - actually compute the result. // NOTE: we update the cache before actually doing the // computation - if for whatever reason there is an error, // we will not redo this computation and just return an // empty result. categories = new Dictionary <string, List <InspectedMember> >(); _categoryCache[filter] = categories; foreach (var member in GetMembers(filter)) { var memberCategories = (from oattribute in member.MemberInfo.GetCustomAttributes(typeof(InspectorCategoryAttribute), /*inherit:*/ true) let attribute = (InspectorCategoryAttribute)oattribute select attribute.Category).ToList(); if (memberCategories.Count == 0) { memberCategories = defaultCategories; } foreach (string category in memberCategories) { if (categories.ContainsKey(category) == false) { categories[category] = new List <InspectedMember>(); } categories[category].Add(member); } } } return(categories); }