/// <summary> /// Give an ability to the actor /// </summary> /// <typeparam name="T">The type of the ability</typeparam> /// <param name="doSomething">Ability</param> /// <returns>A new actor with the given ability</returns> public IActorFacade CanUse <T>(T doSomething) where T : class { Guard.ForNull(doSomething, nameof(doSomething)); var abilities = Abilities.Concat(new[] { new KeyValuePair <Type, object>(typeof(T), doSomething) }) .ToDictionary(k => k.Key, k => k.Value); return(new Actor(Name, abilities, InnerActorBuilder)); }
/// <summary> /// Give an ability to the actor /// </summary> /// <typeparam name="T">The type of the ability</typeparam> /// <param name="doSomething">Ability</param> /// <returns>A new actor with the given ability</returns> public IActorFacade CanUse <T>(T doSomething) where T : class { if (doSomething == null) { throw new ArgumentNullException(nameof(doSomething)); } var abilities = Abilities.Concat(new[] { new KeyValuePair <Type, object>(typeof(T), doSomething) }) .ToDictionary(k => k.Key, k => k.Value); return(new Actor(Name, abilities, InnerActorBuilder)); }
/// <summary> /// Give an ability to the actor /// </summary> /// <typeparam name="T">The type of the ability</typeparam> /// <param name="doSomething">Ability</param> /// <returns>A new actor with the given ability</returns> public IActorFacade CanUse <T>(T doSomething) where T : class { if (doSomething == null) { throw new ArgumentNullException(nameof(doSomething)); } var abilities = Abilities.Concat(new[] { new KeyValuePair <Type, object>(GetAbilityType(), doSomething) }) .ToDictionary(k => k.Key, k => k.Value); return(new Actor(Name, abilities, InnerActorBuilder)); Type GetAbilityType() { var type = typeof(T); if (IsLazyType(type)) { return(type.GetGenericArguments()[0]); } return(type); } }