/// <summary> /// Get attributes from MethodInfo, PropertyInfo, ParameterInfo, and FieldInfo /// </summary> /// <param name="value">MethodInfo, PropertyInfo, ParameterInfo, and FieldInfo</param> /// <returns>attributes</returns> public IEnumerable <Attribute> GetAttributes(object value) { if (value == null) { return(ImmutableLinkedList <Attribute> .Empty); } var values = _knownValues.GetValueOrDefault(value); if (values != null) { return(values); } Attribute[] attributes; var type = value as Type; if (type != null) { attributes = type.GetTypeInfo().GetCustomAttributes()?.ToArray(); } else { var parameterInfo = value as ParameterInfo; if (parameterInfo != null) { attributes = parameterInfo.GetCustomAttributes()?.ToArray(); } else { var memberInfo = value as MemberInfo; if (memberInfo != null) { attributes = memberInfo.GetCustomAttributes <Attribute>()?.ToArray(); } else { throw new NotSupportedException( $"Getting attributes on type {value.GetType().Name} is not supported"); } } } if (attributes == null || attributes.Length == 0) { return(ImmutableLinkedList <Attribute> .Empty); } var list = ImmutableLinkedList.From(attributes); return(ImmutableHashTree.ThreadSafeAdd(ref _knownValues, value, list)); }
public void ImmutableLinkedList_From() { var list = ImmutableLinkedList.From(new[] { 5, 10, 15 }); var newList = new List <int>(list); Assert.Equal(3, newList.Count); Assert.Contains(5, newList); Assert.Contains(10, newList); Assert.Contains(15, newList); }
/// <summary> /// Default Constructor /// </summary> /// <param name="typeFilters"></param> public GenericFilterGroup(params Func <T, bool>[] typeFilters) { if (typeFilters == null) { throw new ArgumentNullException(nameof(typeFilters)); } _typeFilters = typeFilters.Length == 0 ? ImmutableLinkedList <Func <T, bool> > .Empty : ImmutableLinkedList.From(typeFilters); }
public void ImmutableLinkedList_Null_Reference_Check() { var value = (ImmutableLinkedList <int>)null; Assert.Throws <ArgumentNullException>(() => ImmutableLinkedList.ThreadSafeAddRange(ref value, new [] { 5 })); value = ImmutableLinkedList <int> .Empty; Assert.Throws <ArgumentNullException>(() => ImmutableLinkedList.ThreadSafeAddRange(ref value, null)); Assert.Throws <ArgumentNullException>(() => ImmutableLinkedList <int> .Empty.Visit(null)); Assert.Throws <ArgumentNullException>(() => ImmutableLinkedList <int> .Empty.AddRange(null)); Assert.Throws <ArgumentNullException>(() => ImmutableLinkedList.From <int>(null)); }