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); }
public MethodSearch SetOwnerType(string typeName) { Context.SearchFor = Context.SearchFor | MethodSearchFlags.OwnerType; Context.OwnerType = SignatureType.FromTypeString(typeName); if (Context.OwnerType.IsStatic) { SetMethodType(MethodType.Static); } return(this); }
public static MethodSignature FromMethodInfo(MethodInfo methodInfo) { var ms = new MethodSignature(); ms.OwnerType = SignatureType.FromType(methodInfo.ReflectedType); ms.MethodName = methodInfo.Name; ms.ParameterTypes = methodInfo.GetParameters().Select(SignatureType.FromParameterInfo).ToList(); ms.GenericArguments = methodInfo.GetGenericArguments().Select(SignatureType.FromType).ToList(); ms.AccessModifier = methodInfo.GetAccessModifier(); ms.ReturnType = SignatureType.FromType(methodInfo.ReturnType); ms.MethodType = methodInfo.IsStatic ? MethodType.Static : MethodType.Instance; return(ms); }
public MethodSearch SetOwnerType(Type type) { if (type == null) { return(this); } Context.SearchFor = Context.SearchFor | MethodSearchFlags.OwnerType; Context.OwnerType = SignatureType.FromType(type); if (Context.OwnerType.IsStatic) { SetMethodType(MethodType.Static); } return(this); }
public MethodSearch SetReturnType(Type type) { Context.SearchFor = Context.SearchFor | MethodSearchFlags.ReturnType; Context.ReturnType = SignatureType.FromType(type); return(this); }
public MethodSearch SetReturnType(string typeName) { Context.SearchFor = Context.SearchFor | MethodSearchFlags.ReturnType; Context.ReturnType = SignatureType.FromTypeString(typeName); return(this); }