public static bool TryGetCanonical(IList <string> components, bool stripDdas, out string canonicalAddress) { if (components.Count > X400AddressParser.CanonicalOrder.Length) { canonicalAddress = null; return(false); } int num = X400AddressParser.CanonicalOrder.Length; if (stripDdas) { num -= 4; } StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < num; i++) { X400ComponentType x400ComponentType = X400AddressParser.CanonicalOrder[i]; if (x400ComponentType < (X400ComponentType)components.Count) { string text = components[(int)x400ComponentType]; if (text != null) { X400AddressParser.AddComponent(stringBuilder, x400ComponentType, text); } } } canonicalAddress = stringBuilder.ToString(); return(true); }
private static void AddComponent(StringBuilder builder, X400ComponentType type, string value) { if (type < X400ComponentType.DDA) { builder.Append(X400AddressParser.Keys[(int)type]); builder.Append(X400AddressParser.KeySeparators[0]); } else { builder.Append(X400AddressParser.Keys[17]); builder.Append(X400AddressParser.KeySeparators[1]); } foreach (char c in value) { if (c == ';' || c == '\\') { builder.Append('\\'); } builder.Append(c); } builder.Append(';'); }
private static bool TryParse(string s, int maxComponentsCount, bool addressSpace, bool locallyScoped, out IList <string> components, out bool endingWithSemicolon) { if (maxComponentsCount <= 0 || maxComponentsCount > 21) { throw new InvalidOperationException("maxComponentsCount is out of range"); } endingWithSemicolon = false; components = null; if (s == null) { return(false); } int num = 0; char c = '/'; if (s.Length >= 2 && s[0] == c) { num++; } else { c = ';'; } List <string> list = new List <string>(maxComponentsCount); for (int i = 0; i < maxComponentsCount; i++) { list.Add(null); } int num2 = 0; int j = num; int length = s.Length; while (j < length) { while (j < length && (' ' == s[j] || '\t' == s[j])) { j++; } if (j == length) { break; } int num3 = s.IndexOfAny(X400AddressParser.KeySeparators, j); if (-1 == num3 || j == num3) { return(false); } X400ComponentType componentType = X400AddressParser.GetComponentType(s, j, num3 - j); if (X400ComponentType.Unsupported == componentType) { return(false); } if ((componentType == X400ComponentType.DDA && s[num3] != X400AddressParser.KeySeparators[1]) || (componentType != X400ComponentType.DDA && s[num3] != X400AddressParser.KeySeparators[0])) { return(false); } if (addressSpace && X400ComponentType.X121Address == componentType) { return(false); } string text; j = X400AddressParser.GetUnescapedValue(s, num3 + 1, locallyScoped, c, out text, out endingWithSemicolon); if (X400AddressParser.MaxComponentLengths[(int)componentType] < text.Length) { return(false); } if (componentType == X400ComponentType.DDA && num2++ == 4) { return(false); } if (maxComponentsCount > (int)componentType) { if (componentType != X400ComponentType.DDA) { list[(int)componentType] = text; } else { int num4 = 17 + num2 - 1; if (num4 < maxComponentsCount) { list[num4] = text; } } } } bool flag = false; for (int k = 4; k <= 7; k++) { if (flag) { list[k] = null; } else { flag = string.IsNullOrEmpty(list[k]); } } components = list; return(true); }