private static Attribute[] GetAppliedAttributes(Type memberType, Attribute[] attributes) { if (!memberType.IsCollection()) return attributes; PerKeyAttribute perKey = null; PerValueAttribute perValue = null; var isDictionary = memberType.IsImplementerOfRawGeneric(typeof(IDictionary<,>)); for (int i = 0; i < attributes.Length; i++) { var attr = attributes[i]; var perItem = attr as PerItemAttribute; if (perItem != null) { if (isDictionary) { Debug.LogError("PerItem should be applied on lists or arrays, not dictionaries!"); return null; } if (perItem.ExplicitAttributes == null) return null; return attributes.Where(x => !perItem.ExplicitAttributes.Contains(x.GetType().Name.Replace("Attribute", ""))).ToArray(); } if (!isDictionary) continue; if (perKey != null && perValue != null) break; if (perKey == null) perKey = attr as PerKeyAttribute; if (perValue == null) perValue = attr as PerValueAttribute; } if (perKey == null && perValue == null) return attributes; if (perKey != null && perValue != null && (perKey.ExplicitAttributes == null || perValue.ExplicitAttributes == null)) { Debug.LogError("Confusion: If you use both PerKey and PerValue, then you should explictly mention which attributes are applied per key and which per value! (Info: MemberType ({0}) Attributes({1})".FormatWith(memberType.GetNiceName(), string.Join(", ", attributes.Select(x=>x.GetType().Name).ToArray()))); return null; } if (perKey != null) { if (perKey.ExplicitAttributes != null) attributes = attributes.Where(x => !perKey.ExplicitAttributes.Contains(x.GetType().Name.Replace("Attribute", ""))).ToArray(); else attributes = new Attribute[] { perKey }; } if (perValue != null) { if (perValue.ExplicitAttributes != null) attributes = attributes.Where(x => !perValue.ExplicitAttributes.Contains(x.GetType().Name.Replace("Attribute", ""))).ToArray(); else attributes = new Attribute[] { perValue }; } return attributes; }