Example #1
0
 private PatternDefinition(bool traceEnabled, NamespaceMatcher namespaceMatcher, ClassMatcher classMatcher, MemberMatcher memberMatcher, Dictionary <string, string> parameters, string originalExpression)
 {
     _traceEnabled           = traceEnabled;
     _namespaceMatcher       = namespaceMatcher;
     _classMatcher           = classMatcher;
     _memberMatcher          = memberMatcher;
     _originalExpression     = originalExpression;
     _cachedNamespaceMatcher = new CachingDecorator <string>(namespaceMatcher);
     _cachedClassMatcher     = new CachingDecorator <TypeDefinition>(classMatcher);
     _parameters             = parameters ?? new Dictionary <string, string>();
 }
Example #2
0
        internal static PatternDefinition BuildUpDefinition(string pattern, bool traceEnabled, Dictionary <string, string> parameters = null)
        {
            if (pattern == "*" || pattern == "*.*" || pattern == "..")
            {
                pattern = "..*.*";
            }

            var memberSeparatorIdx = pattern.LastIndexOf('.');

            if (memberSeparatorIdx <= 0)
            {
                throw new Exception($"Invalid pattern format {pattern}");
            }

            var classSeparatorIdx = pattern.LastIndexOf('.', memberSeparatorIdx - 1);

            if (classSeparatorIdx <= 0)
            {
                throw new Exception($"Invalid pattern format {pattern}");
            }



            var memberPart    = pattern.Substring(memberSeparatorIdx + 1);
            var classPart     = pattern.Substring(classSeparatorIdx + 1, memberSeparatorIdx - classSeparatorIdx - 1);
            var nameSpacePart = pattern.Substring(0, classSeparatorIdx);

            //fixing weird dottings
            if (nameSpacePart.Length > 2)
            {
                if (nameSpacePart[0] == '.' && nameSpacePart[1] != '.')
                {
                    nameSpacePart = "." + nameSpacePart;
                }
                if (nameSpacePart[nameSpacePart.Length - 1] == '.' && nameSpacePart[nameSpacePart.Length - 2] != '.')
                {
                    nameSpacePart = nameSpacePart + ".";
                }
            }
            else
            {
                if (nameSpacePart[0] == '.')
                {
                    nameSpacePart = "." + nameSpacePart;
                }
            }

            return(new PatternDefinition(traceEnabled, new NamespaceMatcher(nameSpacePart), ClassMatcher.Create(classPart), MemberMatcher.Create(memberPart),
                                         parameters, pattern));
        }