static bool TryParseHelper(string text, out MethodName result) { result = default(MethodName); text = text.Trim(); string name, declaring; string myReturnType = null; string parameters; // LAMESPEC - though only op_Explicit and op_Implict are meant to be encoded // using the tilde, we have observed it is uncommon. It is more common to encode // using the `to` syntax. We also allow this return type tilde syntax to be used // on _any_ method though .NET doesn't consider return type in method signatures int tilde = text.LastIndexOf('~'); if (tilde >= 0) { myReturnType = text.Substring(tilde + 1); text = text.Substring(0, tilde); } name = SplitMemberName(text, out declaring, out parameters); if (parameters.Length > 0 && parameters.Last() != ')' && parameters[0] != '(') { return(false); } if (parameters.Length > 0) { parameters = parameters.Substring(1, parameters.Length - 2).Trim(); } int mangle; string rawName = SplitRawNameFromMangle(name, out mangle); TypeName rt; ParameterData[] pms; TypeName type = null; if (declaring.Length == 0 || TypeName.TryParse(declaring, out type)) { var s = new DefaultMethodName( type, rawName, DefaultMethodName.SetGenericMangle(mangle) ); HelperParseParametersAndReturnType(s, myReturnType, parameters, out pms, out rt); result = s.WithParameters(pms).WithReturnType(rt); return(true); } return(false); }
static void HelperParseParametersAndReturnType(DefaultMethodName s, string myReturnType, string parameters, out ParameterData[] pms, out TypeName returnType) { pms = null; returnType = null; if (myReturnType == null && s.Name == "op_Explicit" || s.Name == "op_Implicit") { var toSyntaxParams = Regex.Split(parameters, @"\s+to\s+"); if (toSyntaxParams.Length == 2) { returnType = TypeCodeReference.ParseTypeName(toSyntaxParams[1], s); pms = MethodCodeReference.SplitParameters(toSyntaxParams[0], s); return; } } if (myReturnType != null) { returnType = TypeCodeReference.ParseTypeName(myReturnType, s); } pms = MethodCodeReference.SplitParameters(parameters, s); }