Exemple #1
0
        public static MethodSummary FromString(string signature)
        {
            var regex = new Regex(@"^(((\[(?<OwnerTypeAlias>\w*)\])?(?<OwnerType>:?<MethodType>\S+)?)?(\s)?(?<AccessModifier>.*)?\s)?(?<ReturnType>\S+)\s(\[(?<MethodNameAlias>\w*)\])?(?<MethodName>\w*)([\[\<](?<GenericArguments>.*)[\]\>])?\((?<ParameterTypes>.*)\)");

            var match = regex.Match(signature);

            if (!match.Success)
            {
                return(null);
            }

            var msig = new MethodSummary();

            msig.MethodName       = match.Groups["MethodName"]?.Value;
            msig.GenericArguments = match.Groups["GenericArguments"]?.Value.Split(',')
                                    .Select(a => a.Trim()).Where(a => !string.IsNullOrWhiteSpace(a)).Select(SignatureType.FromTypeString).ToList();

            msig.ParameterTypes = match.Groups["ParameterTypes"]?.Value.Split(',').Select(a => a.Trim()).Where(a => !string.IsNullOrWhiteSpace(a))
                                  .Select(p => {
                var regMatch = new Regex(@"(\[(?<genericPart>.+)\])?(?<typePart>.*)").Match(p);

                var gen = regMatch.Groups["genericPart"]?.Value;
                var typ = regMatch.Groups["typePart"]?.Value;

                var sigType = SignatureType.FromTypeString(typ);

                if (!String.IsNullOrWhiteSpace(gen))
                {
                    sigType = sigType.SetGenericName(gen);
                }

                return(sigType);
            }).ToList();

            msig.ReturnType = SignatureType.FromTypeString(match.Groups["ReturnType"]?.Value);
            var accessModifier = match.Groups["AccessModifier"]?.Value;

            if (accessModifier != null)
            {
                msig.AccessModifier = Enum <MethodAccessModifier> .Find(accessModifier);

                if (accessModifier.Contains(" ") && msig.AccessModifier == MethodAccessModifier.Unknown)
                {
                    accessModifier      = string.Join(" ", accessModifier.Split(' ').Reverse());
                    msig.AccessModifier = Enum <MethodAccessModifier> .Find(accessModifier);
                }
            }

            msig.OwnerType = SignatureType.FromTypeString(match.Groups["OwnerType"]?.Value);

            msig.MethodNameAlias = match.Groups["MethodNameAlias"]?.Value;
            msig.OwnerTypeAlias  = match.Groups["OwnerTypeAlias"]?.Value;
            msig.MethodType      = Enum <MethodType> .Find(match.Groups["MethodType"]?.Value);

            return(msig);
        }
Exemple #2
0
        public MethodInfoRating RateAgainst(MethodSummary search, MethodSearchFlags searchFlags)
        {
            var result = new MethodInfoRating();



            if (searchFlags.HasFlag(MethodSearchFlags.OwnerType))
            {
                if (this.OwnerType.FoundMatchingType != search.OwnerType.FoundMatchingType)
                {
                    return(result.SetFailed());
                }
            }

            if (searchFlags.HasFlag(MethodSearchFlags.AccessModifier))
            {
                if (!search.AccessModifier.HasFlag(AccessModifier))
                {
                    return(result.SetFailed());
                }
            }

            if (searchFlags.HasFlag(MethodSearchFlags.ReturnType))
            {
                if (this.ReturnType != search.ReturnType)
                {
                    return(result.SetFailed());
                }
            }

            if (searchFlags.HasFlag(MethodSearchFlags.MethodName))
            {
                result.SetMethodNameRating(GetMethodNameRating(search.MethodName));
            }

            if (searchFlags.HasFlag(MethodSearchFlags.GenericArguments))
            {
                if (search.GenericArguments.Count == GenericArguments.Count)
                {
                }
                else
                {
                    return(result.SetFailed());
                }
            }

            if (searchFlags.HasFlag(MethodSearchFlags.ParameterTypes))
            {
                result.SetParameterTypesRating(GetParameterTypesRating(search.ParameterTypes));
            }

            return(result);
        }