Entity NumberOfComponents Property Delta Engine Documentation

Namespace: DeltaEngine.Entities
Assembly: DeltaEngine (in DeltaEngine.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public int NumberOfComponents { get; }

Property Value

Type: Int32
Remarks

Tests: DeltaEngine.Tests.Entities.EntityTests
Examples

5 unit tests call DeltaEngine.Entities.Entity.NumberOfComponents
[Test]
public void CheckNameAndDefaultValues()
{
    Assert.AreEqual(0, entityWithTags.NumberOfComponents);
    Assert.IsTrue(entityWithTags.IsActive);
}
[Test]
public void AddAndRemoveComponent()
{
    Assert.AreEqual(1, entities.NumberOfEntities);
    var entity = new MockEntity().Add(new object());
    Assert.AreEqual(2, entities.NumberOfEntities);
    Assert.AreEqual(1, entity.NumberOfComponents);
    Assert.IsNotNull(entity.Get<object>());
    entity.Remove<object>();
    Assert.AreEqual(0, entity.NumberOfComponents);
    Assert.IsFalse(entity.Contains<object>());
    Assert.Throws<ArgumentNullException>(() => new MockEntity().Add<object>(null));
}
[Test]
public void SaveAndLoadEmptyEntityFromMemoryStream()
{
    var data = BinaryDataExtensions.SaveToMemoryStream(new MockEntity());
    byte[] savedBytes = data.ToArray();
    Assert.AreEqual(GetShortNameLength("MockEntity") + 1 + 4 + 1 + 1, savedBytes.Length);
    var loadedEntity = data.CreateFromMemoryStream() as Entity;
    Assert.AreEqual(0, loadedEntity.NumberOfComponents);
    Assert.IsTrue(loadedEntity.IsActive);
}
See Also