private static SparseFieldSetExpression IncludeField(SparseFieldSetExpression sparseFieldSet, ResourceFieldAttribute fieldToInclude) { if (sparseFieldSet == null || sparseFieldSet.Fields.Contains(fieldToInclude)) { return(sparseFieldSet); } HashSet <ResourceFieldAttribute> fieldSet = sparseFieldSet.Fields.ToHashSet(); fieldSet.Add(fieldToInclude); return(new SparseFieldSetExpression(fieldSet)); }
private static SparseFieldSetExpression IncludeAttribute(SparseFieldSetExpression sparseFieldSet, AttrAttribute attributeToInclude) { if (sparseFieldSet == null || sparseFieldSet.Attributes.Contains(attributeToInclude)) { return(sparseFieldSet); } var attributeSet = sparseFieldSet.Attributes.ToHashSet(); attributeSet.Add(attributeToInclude); return(new SparseFieldSetExpression(attributeSet)); }
public static SparseFieldSetExpression Excluding <TResource>(this SparseFieldSetExpression sparseFieldSet, Expression <Func <TResource, dynamic> > fieldSelector, IResourceGraph resourceGraph) where TResource : class, IIdentifiable { ArgumentGuard.NotNull(fieldSelector, nameof(fieldSelector)); ArgumentGuard.NotNull(resourceGraph, nameof(resourceGraph)); SparseFieldSetExpression newSparseFieldSet = sparseFieldSet; foreach (ResourceFieldAttribute field in resourceGraph.GetFields(fieldSelector)) { newSparseFieldSet = ExcludeField(newSparseFieldSet, field); } return(newSparseFieldSet); }
private static SparseFieldSetExpression ExcludeField(SparseFieldSetExpression sparseFieldSet, ResourceFieldAttribute fieldToExclude) { // Design tradeoff: When the sparse fieldset is empty, it means all fields will be selected. // Adding an exclusion in that case is a no-op, which results in still retrieving the excluded field from data store. // But later, when serializing the response, the sparse fieldset is first populated with all fields, // so then the exclusion will actually be applied and the excluded field is not returned to the client. if (sparseFieldSet == null || !sparseFieldSet.Fields.Contains(fieldToExclude)) { return(sparseFieldSet); } HashSet <ResourceFieldAttribute> fieldSet = sparseFieldSet.Fields.ToHashSet(); fieldSet.Remove(fieldToExclude); return(new SparseFieldSetExpression(fieldSet)); }
public static SparseFieldSetExpression Excluding <TResource>(this SparseFieldSetExpression sparseFieldSet, Expression <Func <TResource, dynamic> > attributeSelector, IResourceGraph resourceGraph) where TResource : class, IIdentifiable { if (attributeSelector == null) { throw new ArgumentNullException(nameof(attributeSelector)); } if (resourceGraph == null) { throw new ArgumentNullException(nameof(resourceGraph)); } foreach (var attribute in resourceGraph.GetAttributes(attributeSelector)) { sparseFieldSet = ExcludeAttribute(sparseFieldSet, attribute); } return(sparseFieldSet); }
public static SparseFieldSetExpression Including <TResource>(this SparseFieldSetExpression sparseFieldSet, Expression <Func <TResource, dynamic> > fieldSelector, IResourceGraph resourceGraph) where TResource : class, IIdentifiable { if (fieldSelector == null) { throw new ArgumentNullException(nameof(fieldSelector)); } if (resourceGraph == null) { throw new ArgumentNullException(nameof(resourceGraph)); } foreach (var field in resourceGraph.GetFields(fieldSelector)) { sparseFieldSet = IncludeField(sparseFieldSet, field); } return(sparseFieldSet); }
public override QueryExpression VisitSparseFieldSet(SparseFieldSetExpression expression, TArgument argument) { return(expression); }