Nie podchodzisz do problemu aby zbyt dosłownie?
using System;
using System.Collections.Generic;
using System.Linq;
namespace SomekindUniqTypes
{
class Program
{
public interface ISomekindEvent { };
public class SomekindEvent1 : ISomekindEvent { };
public class SomekindEvent2 : ISomekindEvent { };
public class SomekindEvent3 : ISomekindEvent { };
public static bool containsUniqueTypes(IEnumerable<ISomekindEvent> col)
{
return col.GroupBy(x => x.GetType()).All(t => t.Count() == 1);
}
static void Main(string[] args)
{
List<ISomekindEvent> expected = new List<ISomekindEvent>
{
new SomekindEvent1(),
new SomekindEvent2(),
new SomekindEvent3(),
};
List<ISomekindEvent> invalid = new List<ISomekindEvent>
{
new SomekindEvent3(),
new SomekindEvent3(),
new SomekindEvent3(),
};
Console.WriteLine("expected: {0}", containsUniqueTypes(expected));
Console.WriteLine("invalid: {0}", containsUniqueTypes(invalid));
}
}
}