public bool?Filter(Type t) { if ((Namespace == "*" || t.Parent.Name == Namespace) && (Name == "*" || t.Name == Name)) { bool expose = Expose; if (t.Attributes?.Count > 0 && AttributeFilters?.Count > 0) { foreach (var attr in t.Attributes.Where(a => AttributeFilters.ContainsKey(a.Declaration))) { expose = expose && AttributeFilters[attr.Declaration]; } } return(expose); } return(null); }
public bool?Filter(Member m) { var parentResult = Parent.Filter(m.Parent as Type); if (parentResult == null || !parentResult.Value) { return(parentResult); } if (Name == "*" || m.Name == Name) { bool expose = Expose; if (m.Attributes?.Count > 0 && AttributeFilters?.Count > 0) { foreach (var attr in m.Attributes.Where(a => AttributeFilters.ContainsKey(a.Declaration))) { expose = expose && AttributeFilters[attr.Declaration]; } } return(expose); } return(null); }
/// <summary> /// Serialize query parameters to specified writer /// </summary> /// <param name="writer"><see cref="IBinaryWriter"/> writer used to serialize data to underlying stream.</param> internal void Serialize(IBinaryWriter writer) { // offset, limits and match mode writer.Write(Offset); writer.Write(Limit); writer.Write((int)MatchMode); writer.Write((int)RankingMode); if (RankingMode == MatchRankMode.Expression) { writer.Write(RankingExpression); } // sorting writer.Write((int)SortMode); writer.Write(SortBy); writer.Write(Query); // NOTE: don't use deprecated per-field weights list, use FieldWeights instead writer.Write(0); Indexes.Serialize(writer); // documents id range writer.Write((int)IdSize); writer.Write(MinDocumentId); writer.Write(MaxDocumentId); // filters AttributeFilters.Serialize(writer); // grouping writer.Write((int)GroupFunc); writer.Write(GroupBy); writer.Write(MaxMatches); writer.Write(GroupSort); // cutoff writer.Write(Cutoff); // retry writer.Write(RetryCount); writer.Write(RetryDelay); // group distinct writer.Write(GroupDistinct); // geo anchor GeoAnchor.Serialize(writer); // index weights IndexWeights.Serialize(writer); // max query time writer.Write(MaxQueryTime); // per-field weights FieldWeights.Serialize(writer); // comment writer.Write(Comment); // attribute overrides AttributeOverrides.Serialize(writer); // select clause writer.Write(Select); }
/*========================================================================================================================== | CONSTRUCTOR \-------------------------------------------------------------------------------------------------------------------------*/ /// <summary> /// Given a <see cref="PropertyInfo"/> instance, exposes a set of properties associated with known <see cref="Attribute"/> /// instances. /// </summary> /// <param name="property">The <see cref="PropertyInfo"/> instance to check for <see cref="Attribute"/> values.</param> /// <param name="attributePrefix">The prefix to apply to the attributes.</param> public PropertyConfiguration(PropertyInfo property, string? attributePrefix = "") { /*------------------------------------------------------------------------------------------------------------------------ | Validate parameters \-----------------------------------------------------------------------------------------------------------------------*/ Contract.Requires(property, nameof(property)); /*------------------------------------------------------------------------------------------------------------------------ | Set backing property \-----------------------------------------------------------------------------------------------------------------------*/ Property = property; /*------------------------------------------------------------------------------------------------------------------------ | Set default values \-----------------------------------------------------------------------------------------------------------------------*/ AttributeKey = attributePrefix + property.Name; AttributePrefix = attributePrefix; DefaultValue = null; InheritValue = false; RelationshipKey = AttributeKey; RelationshipType = RelationshipType.Any; CrawlRelationships = Relationships.None; MetadataKey = null; DisableMapping = false; AttributeFilters = new(); FlattenChildren = false; /*------------------------------------------------------------------------------------------------------------------------ | Attributes: Retrieve basic attributes \-----------------------------------------------------------------------------------------------------------------------*/ GetAttributeValue<DefaultValueAttribute>(property, a => DefaultValue = a.Value); GetAttributeValue<InheritAttribute>(property, a => InheritValue = true); GetAttributeValue<AttributeKeyAttribute>(property, a => AttributeKey = attributePrefix + a.Value); GetAttributeValue<MapToParentAttribute>(property, a => MapToParent = true); GetAttributeValue<MapToParentAttribute>(property, a => AttributePrefix += (a.AttributePrefix?? property.Name)); GetAttributeValue<FollowAttribute>(property, a => CrawlRelationships = a.Relationships); GetAttributeValue<FlattenAttribute>(property, a => FlattenChildren = true); GetAttributeValue<MetadataAttribute>(property, a => MetadataKey = a.Key); GetAttributeValue<DisableMappingAttribute>(property, a => DisableMapping = true); /*------------------------------------------------------------------------------------------------------------------------ | Attributes: Determine relationship key and type \-----------------------------------------------------------------------------------------------------------------------*/ GetAttributeValue<RelationshipAttribute>( property, a => { RelationshipKey = a.Key ?? RelationshipKey; RelationshipType = a.Type; } ); if ( RelationshipType is RelationshipType.Any && RelationshipKey.Equals("Children", StringComparison.InvariantCultureIgnoreCase) ) { RelationshipType = RelationshipType.Children; } /*------------------------------------------------------------------------------------------------------------------------ | Attributes: Set attribute filters \-----------------------------------------------------------------------------------------------------------------------*/ var filterByAttribute = property.GetCustomAttributes<FilterByAttributeAttribute>(true); if (filterByAttribute is not null && filterByAttribute.Any()) { foreach (var filter in filterByAttribute) { AttributeFilters.Add(filter.Key, filter.Value); } } }