Entitas  0.35.0
Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
CollectionExtension.cs
1 using System.Collections.Generic;
2 
3 namespace Entitas {
4 
5  public static class CollectionExtension {
6 
7  /// Returns the only entity in the collection.
8  /// It will throw an exception if the collection doesn't have
9  /// exactly one entity.
10  public static Entity SingleEntity(this ICollection<Entity> collection) {
11  if(collection.Count != 1) {
12  throw new SingleEntityException(collection.Count);
13  }
14 
15  return System.Linq.Enumerable.First(collection);
16  }
17  }
18 
20  public SingleEntityException(int count) : base(
21  "Expected exactly one entity in collection but found " + count + "!",
22  "Use collection.SingleEntity() only when you are sure that there " +
23  "is exactly one entity.") {
24  }
25  }
26 }
static Entity SingleEntity(this ICollection< Entity > collection)
Base exception used by Entitas.