How to use Capture method of Microsoft.TestPlatform.AdapterUtilities.ManagedNameUtilities.ManagedNameParser class

Best Vstest code snippet using Microsoft.TestPlatform.AdapterUtilities.ManagedNameUtilities.ManagedNameParser.Capture

ManagedNameParser.cs

Source:ManagedNameParser.cs Github

copy

Full Screen

...71 string message = string.Format(CultureInfo.CurrentCulture, Resources.ErrorUnexpectedCharactersAtEnd, pos);72 throw new InvalidManagedNameException(message);73 }74 }75 private static string Capture(string managedMethodName, int start, int end)76 => managedMethodName.Substring(start, end - start);77 private static int ParseMethodName(string managedMethodName, int start, out string methodName, out int arity)78 {79 var i = start;80 var quoted = false;81 for (; i < managedMethodName.Length; i++)82 {83 var c = managedMethodName[i];84 if (c == '\'' || quoted)85 {86 quoted = c == '\'' ? !quoted : quoted;87 continue;88 }89 switch (c)90 {91 case var w when char.IsWhiteSpace(w):92 string message = string.Format(CultureInfo.CurrentCulture, Resources.ErrorWhitespaceNotValid, i);93 throw new InvalidManagedNameException(message);94 case '`':95 methodName = Capture(managedMethodName, start, i);96 return ParseArity(managedMethodName, i, out arity);97 case '(':98 methodName = Capture(managedMethodName, start, i);99 arity = 0;100 return i;101 }102 }103 methodName = Capture(managedMethodName, start, i);104 arity = 0;105 return i;106 }107 // parse arity in the form `nn where nn is an integer value.108 private static int ParseArity(string managedMethodName, int start, out int arity)109 {110 arity = 0;111 Debug.Assert(managedMethodName[start] == '`');112 int i = start + 1; // skip initial '`' char113 for (; i < managedMethodName.Length; i++)114 {115 if (managedMethodName[i] == '(') break;116 }117 if (!int.TryParse(Capture(managedMethodName, start + 1, i), out arity))118 {119 string message = string.Format(CultureInfo.CurrentCulture, Resources.ErrorMethodArityMustBeNumeric);120 throw new InvalidManagedNameException(message);121 }122 return i;123 }124 private static int ParseParameterTypeList(string managedMethodName, int start, out string[] parameterTypes)125 {126 parameterTypes = null;127 if (start == managedMethodName.Length)128 {129 return start;130 }131 Debug.Assert(managedMethodName[start] == '(');132 var types = new List<string>();133 int i = start + 1; // skip initial '(' char134 for (; i < managedMethodName.Length; i++)135 {136 switch (managedMethodName[i])137 {138 case ')':139 if (types.Count != 0)140 {141 parameterTypes = types.ToArray();142 }143 return i + 1; // consume right parens144 case ',':145 break;146 default:147 i = ParseParameterType(managedMethodName, i, out var parameterType);148 types.Add(parameterType);149 break;150 }151 }152 string message = string.Format(CultureInfo.CurrentCulture, Resources.ErrorIncompleteManagedName);153 throw new InvalidManagedNameException(message);154 }155 private static int ParseParameterType(string managedMethodName, int start, out string parameterType)156 {157 parameterType = string.Empty;158 var quoted = false;159 int i = start;160 for (i = start; i < managedMethodName.Length; i++)161 {162 if (managedMethodName[i] == '\'' || quoted)163 {164 quoted = managedMethodName[i] == '\'' ? !quoted : quoted;165 continue;166 }167 switch (managedMethodName[i])168 {169 case '<':170 i = ParseGenericBrackets(managedMethodName, i + 1);171 break;172 case '[':173 i = ParseArrayBrackets(managedMethodName, i + 1);174 break;175 case ',':176 case ')':177 parameterType = Capture(managedMethodName, start, i);178 return i - 1;179 case var w when char.IsWhiteSpace(w):180 string message = string.Format(CultureInfo.CurrentCulture, Resources.ErrorWhitespaceNotValid, i);181 throw new InvalidManagedNameException(message);182 }183 }184 return i;185 }186 private static int ParseArrayBrackets(string managedMethodName, int start)187 {188 var quoted = false;189 for (int i = start; i < managedMethodName.Length; i++)190 {191 if (managedMethodName[i] == '\'' || quoted)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Vstest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful