public static MethodInfo MapInterfaceMethodToImplementationIfNecessary(MethodInfo methodInfo, System.Type implementingType) { AssertUtils.ArgumentNotNull(methodInfo, "methodInfo"); AssertUtils.ArgumentNotNull(implementingType, "implementingType"); AssertUtils.IsTrue(methodInfo.DeclaringType.IsAssignableFrom(implementingType), "methodInfo and implementingType are unrelated"); MethodInfo concreteMethodInfo = methodInfo; if (methodInfo.DeclaringType.IsInterface) { InterfaceMapping interfaceMapping = implementingType.GetInterfaceMap(methodInfo.DeclaringType); int methodIndex = Array.IndexOf(interfaceMapping.InterfaceMethods, methodInfo); concreteMethodInfo = interfaceMapping.TargetMethods[methodIndex]; } return(concreteMethodInfo); }
public static string[] Split( string s, string delimiters, bool trimTokens, bool ignoreEmptyTokens, string quoteChars) { if (s == null) { return(new string[0]); } if (string.IsNullOrEmpty(delimiters)) { return(new string[] { s }); } if (quoteChars == null) { quoteChars = string.Empty; } AssertUtils.IsTrue(quoteChars.Length % 2 == 0, "the number of quote characters must be even"); char[] delimiterChars = delimiters.ToCharArray(); // ɨÃè·Ö¸î·ûλÖà int[] delimiterPositions = new int[s.Length]; int count = MakeDelimiterPositionList(s, delimiterChars, quoteChars, delimiterPositions); List <string> tokens = new List <string>(count + 1); int startIndex = 0; for (int ixSep = 0; ixSep < count; ixSep++) { string token = s.Substring(startIndex, delimiterPositions[ixSep] - startIndex); if (trimTokens) { token = token.Trim(); } if (!(ignoreEmptyTokens && token.Length == 0)) { tokens.Add(token); } startIndex = delimiterPositions[ixSep] + 1; } if (startIndex < s.Length) { string token = s.Substring(startIndex); if (trimTokens) { token = token.Trim(); } if (!(ignoreEmptyTokens && token.Length == 0)) { tokens.Add(token); } } else if (startIndex == s.Length) { if (!(ignoreEmptyTokens)) { tokens.Add(string.Empty); } } return(tokens.ToArray()); }