Login
Два статических метода... или 4 строки LINQ?
515 просмотров
Перейти к просмотру всей ветки
Murr патриот
Два статических метода... или 4 строки LINQ?
internal static void AddImports(CodeNamespace codeNamespace, string[] namespaces){string[] strArrays = namespaces;for (int i = 0; i < (int)strArrays.Length; i++){string str = strArrays;codeNamespace.Imports.Add(new CodeNamespaceImport(str));}}
internal static string[] GetNamespacesForTypes(Type[] types){Hashtable hashtables = new Hashtable();for (int i = 0; i < (int)types.Length; i++){string fullName = types.FullName;int num = fullName.LastIndexOf('.');if (num > 0){hashtables[fullName.Substring(0, num)] = types;}}string[] strArrays = new string[hashtables.Keys.Count];hashtables.Keys.CopyTo(strArrays, 0);return strArrays;}
вызов - однократный - второй метод отдает результат первомu
Замена:
public void AddCodeNamespaces(Type[] pTypes){CodeNamespaceImport[] uniqueKeys = pTypes.Where(t => t.FullName.LastIndexOf('.') > 0).Distinct().Select(n => new CodeNamespaceImport(n.FullName.Substring(0, n.FullName.LastIndexOf('.')))).ToArray();codeNamespace.Imports.AddRange(uniqueKeys);}
Если все так симпатично - пошто мелкомягкие пишуть два метода?