【发布时间】:2015-12-02 11:15:06
【问题描述】:
在这个问题上,有人提出了一种适用于 IEnumerable 的奇妙的 ToDelimitedString 扩展方法:
Overriding ToString() of List<MyClass>
我正在尝试在 Unity 3D 4.0 中使用它,因为系统命名空间被覆盖它会导致问题,因此到目前为止我已经做出了绝对引用:
public static string ToDelimitedString<T> (this IEnumerable<T> source) {
return source.ToDelimitedString (x => x.ToString (),
System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator);
}
public static string ToDelimitedString<T> (this IEnumerable<T> source, System.Func<T, string> converter) {
return source.ToDelimitedString (converter,
System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator);
}
public static string ToDelimitedString<T> (this IEnumerable<T> source, string separator) {
return source.ToDelimitedString (x => x.ToString (), separator);
}
public static string ToDelimitedString<T> (this IEnumerable<T> source, System.Func<T, string> converter, string separator) {
return string.Join (separator, source.Select (converter).ToArray ());
}
让这个在 Unity 3d 中工作是我想要做的,我遇到的错误是:
Assets/Main/Extensions.cs(125,55):错误 CS1061:类型 System.Collections.Generic.IEnumerable<T>' does not contain a definition forSelect' 并且找不到扩展方法 Select' of typeSystem.Collections.Generic.IEnumerable'(您是否缺少 using 指令还是程序集参考?)
注意我已经改变了一些,我无法克服的是“source.Select”我相信,这可能吗?谢谢,它使调试更容易,不必重写扩展,也许有助于序列化。
【问题讨论】: