1

On this question, one guy presents a marvellous ToDelimitedString extension method that works on IEnumerable:

Overriding ToString() of List<MyClass>

I am trying to use it in Unity 3D 4.0, because the System namespace is overridden it causes issues, so far I have made the absolute references thusly:

    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 ());
    }

getting this working in Unity 3d is what I am trying to do, the error I have is:

Assets/Main/Extensions.cs(125,55): error CS1061: Type System.Collections.Generic.IEnumerable<T>' does not contain a definition forSelect' and no extension method Select' of typeSystem.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?)

note i have changed some of it, the one I cannot overcome is "source.Select" i believe, is this possible? Thanks, it makes debug easier to not have to rewrite extensions and perhaps helps with serialisation.

Community
  • 1
  • 1
Richard
  • 135
  • 2
  • 11

1 Answers1

1

You seem to be missing the Linq namespace.

You need :

   using System.Linq;
Everts
  • 10,408
  • 2
  • 34
  • 45