Пример #1
0
        public bool EvaluateExpression(string ToEvaluate)
        {
            switch (FilterMode)
            {
            case EFilterMode.SubString:
                return(ToEvaluate.Contains(FilterPattern));

            case EFilterMode.StartsWith:
                return(ToEvaluate.StartsWith(FilterPattern));

            case EFilterMode.EndsWith:
                return(ToEvaluate.EndsWith(FilterPattern));

            case EFilterMode.RegEx:
                return(CompiledRegex.Match(ToEvaluate).Success);
            }
            return(false);
        }
        protected virtual ConfigurationSection DeserializeSection(XContainer xml, string name)
        {
            XElement sections = xml.Element(ConfigSectionsElementName);

            if (sections == null)
            {
                return(null);
            }

            XElement sectionDefinition = sections
                                         .Descendants(SectionElementName)
                                         .FirstOrDefault(section => section.Attribute(NameAttributeName).Value == SectionNamePattern.Match(name).Value);

            if (sectionDefinition == null)
            {
                return(null);
            }

            Type sectionType = Type.GetType(sectionDefinition.Attribute(TypeAttributeName).Value, false);

            if (sectionType == null)
            {
                return(null);
            }

            const BindingFlags flags         = BindingFlags.Static | BindingFlags.NonPublic;
            MethodInfo         genericFlavor = typeof(InMemoryConfigurationSource).GetMethods(flags)
                                               .FirstOrDefault(method => method.Name == DeserializeSectionMethodName && method.IsGenericMethod);

            if (genericFlavor == null)
            {
                return(null);
            }

            MethodInfo typedGenericFlavor = genericFlavor.MakeGenericMethod(sectionType);

            try
            {
                return((ConfigurationSection)typedGenericFlavor.Invoke(null, new object[] { xml, name }));
            }
            catch (TargetInvocationException error)
            {
                throw error.InnerException;
            }
        }