public ISortInputTypeDescriptor <T> Ignore(Expression <Func <T, object> > property) { if (property.ExtractMember() is PropertyInfo p) { Fields.GetOrAddDescriptor(p, () => IgnoredSortingFieldDescriptor.CreateOperation(p, Context)); return(this); } throw new ArgumentException( SortingResources.SortInputTypeDescriptor_Ignore_OnlyPopertiesAreAllowed, nameof(property)); }
public ISortInputTypeDescriptor <T> Ignore(Expression <Func <T, object> > property) { if (property.ExtractMember() is PropertyInfo p) { Fields.GetOrAddDescriptor(p, () => IgnoredSortingFieldDescriptor.CreateOperation(p, Context)); return(this); } // TODO : resources throw new ArgumentException( "Only properties are allowed for input types.", nameof(property)); }
public void GetOrAddDescriptor_Should_ReplaceDescriptorIfDifferentType() { //arrange IList <SortOperationDescriptorBase> list = new List <SortOperationDescriptorBase>(); var descriptorToRemove = IgnoredSortingFieldDescriptor.CreateOperation(_propertyInfo, _descriptorContext); var descriptorToAdd = SortOperationDescriptor.CreateOperation(_propertyInfo, _descriptorContext); Func <SortOperationDescriptor> valueFactory = () => descriptorToAdd; list.Add(descriptorToRemove); //act SortOperationDescriptor result = list.GetOrAddDescriptor(_propertyInfo, valueFactory); //assert Assert.Single(list); Assert.Same(descriptorToAdd, list[0]); Assert.Same(descriptorToAdd, result); Assert.NotSame(descriptorToRemove, result); }