AjTalk.Language.BaseBehavior.AddTrait C# (CSharp) Метод

AddTrait() публичный Метод

public AddTrait ( IBehavior trait ) : void
trait IBehavior
Результат void
        public void AddTrait(IBehavior trait)
        {
            if (this.traits == null)
                this.traits = new List<IBehavior>();

            this.traits.Add(trait);
        }

Usage Example

Пример #1
0
        public void AddBehaviorAsTrait()
        {
            BaseBehavior behavior = new BaseBehavior(null, null, this.machine);
            IMethod method = new Method("method");

            behavior.DefineInstanceMethod(method);

            BaseBehavior trait = new BaseBehavior(null, null, this.machine);
            IMethod method2 = new Method("method2");

            trait.DefineInstanceMethod(method2);

            behavior.AddTrait(trait);

            IMethod result = behavior.GetInstanceMethod("method");
            Assert.IsNotNull(result);
            Assert.AreSame(method, result);
            result = behavior.GetInstanceMethod("method2");
            Assert.IsNotNull(result);
            Assert.AreSame(method2, result);
        }