Esempio n. 1
0
 private static bool ApplyFilter(Attribute attribute, FilterNode filter)
 {
     if (filter == null)
     {
         return(true);
     }
     return(filter.Eval(attribute));
 }
Esempio n. 2
0
 public FilteringBindingProvider(
     INameResolver nameResolver,
     IBindingProvider inner,
     FilterNode description)
 {
     _nameResolver = nameResolver;
     _inner        = inner;
     _description  = description;
 }
Esempio n. 3
0
 public FilteringBindingProvider(
     IConfiguration configuration,
     INameResolver nameResolver,
     IBindingProvider inner,
     FilterNode description)
 {
     _configuration = configuration;
     _nameResolver  = nameResolver;
     _inner         = inner;
     _description   = description;
 }
Esempio n. 4
0
        public IEnumerable <BindingRule> GetRules()
        {
            IBindingRuleProvider inner = _inner as IBindingRuleProvider;

            if (inner != null)
            {
                foreach (var rule in inner.GetRules())
                {
                    rule.Filter = FilterNode.And(_description, rule.Filter);
                    yield return(rule);
                }
            }
        }
        public IEnumerable <BindingRule> GetRules()
        {
            var accessProp = typeof(TAttribute).GetProperty("access", BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);

            foreach (var type in new Type[]
            {
                typeof(Stream),
            })
            {
                yield return(new BindingRule
                {
                    SourceAttribute = typeof(TAttribute),
                    Filter = FilterNode.NotNull(accessProp), // For stream, Must specify Read vs. Write
                    UserType = OpenType.FromType(type)
                });
            }

            // Read
            foreach (var filter in new FilterNode[]
            {
                FilterNode.IsEqual(accessProp, FileAccess.Read),
                FilterNode.Null(accessProp) // Not write
            })
            {
                foreach (var type in new Type[]
                {
                    typeof(TextReader),
                    typeof(string),
                    typeof(byte[])
                })
                {
                    yield return(new BindingRule
                    {
                        Filter = filter,
                        SourceAttribute = typeof(TAttribute),
                        UserType = OpenType.FromType(type)
                    });
                }
            }

            // Write
            foreach (var filter in new FilterNode[]
            {
                FilterNode.IsEqual(accessProp, FileAccess.Write),
                FilterNode.Null(accessProp) // Not Read
            })
            {
                foreach (var type in new Type[]
                {
                    typeof(TextWriter),
                    typeof(string).MakeByRefType(),
                    typeof(byte[]).MakeByRefType()
                })
                {
                    yield return(new BindingRule
                    {
                        Filter = filter,
                        SourceAttribute = typeof(TAttribute),
                        UserType = OpenType.FromType(type)
                    });
                }
            }
        }