ITeye博客

StringOfArray in web service proxy

huhu_long · 2012-09-29 00:09 · .net · 编程语言 · Markdown

Sometimes we may need reference web service hosted base on java platform. And you are very likely to generate proxy classes with class type "ArrayOf***". So we may have to convert these types to collection or other appropriate type in our own application, and our types to "ArrayOf***".

Here is a sample to convert string to ArrayOfString


public class ArrayOfString : System.Collections.Generic.List<string>
{
}

private static T To<T>(IEnumerable<string> strings) where T : IList<string>, new()
{
    if (strings == null) return default(T);

    var tResult = new T();
    foreach (var s in strings) tResult.Add(s);
    return tResult;
}

var strings = new string[] {"aaa", "BBB", "ccc", "DDD"};

var arrayOfString = To<ArrayOfString>(strings);

评论(3)

  1. #3 楼 · z169351998 · 2013-01-11 17:30

    :arrow:

  2. #2 楼 · z169351998 · 2013-01-11 17:29

    撒大大 8)

  3. #1 楼 · z169351998 · 2013-01-11 17:29

    :o :cry: :cry: :twisted: :evil: :arrow:

    <> ||

    || 阿迪was

评论功能维护中,当前仅展示历史评论。