< Summary

Class:DCL.ECSComponents.UIAbstractElements.UIElementRegisterBase[T,THandler,TFeedbackResult]
Assembly:DCL.ECSComponents.AbstractElements
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/UIAbstractElements/UIElementRegisterBase.cs
Covered lines:9
Uncovered lines:1
Coverable lines:10
Total lines:84
Line coverage:90% (9 of 10)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UIElementRegisterBase(...)0%220100%
Dispose()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/UIAbstractElements/UIElementRegisterBase.cs

#LineLine coverage
 1using DCL.ECS7.InternalComponents;
 2using DCL.ECSRuntime;
 3using Google.Protobuf;
 4using System;
 5
 6namespace DCL.ECSComponents.UIAbstractElements
 7{
 8    /// <summary>
 9    /// Base class to register deserializer and serializer of UI Component,
 10    /// and create a builder for handler.
 11    /// </summary>
 12    /// <typeparam name="T">Type of component</typeparam>
 13    /// <typeparam name="THandler">Type of handler</typeparam>
 14    /// <typeparam name="TFeedbackResult">Type of feedback component (such as 'text value' for TextField)</typeparam>
 15    public abstract class UIElementRegisterBase<T, THandler, TFeedbackResult> : UIElementRegisterBase<T, THandler>
 16        where T: IMessage<T>, new()
 17        where THandler: class, IECSComponentHandler<T>
 18        where TFeedbackResult : IMessage<TFeedbackResult>, new()
 19    {
 20        private readonly int feedbackResultComponentId;
 21
 22        protected UIElementRegisterBase(int componentId, int feedbackResultComponentId,
 23            ECSComponentsFactory factory, IECSComponentWriter componentWriter,
 24            IInternalECSComponent<InternalUiContainer> internalUiContainer,
 25            HandlerBuilder handlerBuilder)
 4226            : base(componentId, factory, componentWriter, internalUiContainer, handlerBuilder)
 27        {
 4228            this.feedbackResultComponentId = feedbackResultComponentId;
 29
 4230            factory.AddOrReplaceComponent(feedbackResultComponentId, ProtoSerialization.Deserialize<TFeedbackResult>,
 031                () => null);
 32
 4233            componentWriter.AddOrReplaceComponentSerializer<TFeedbackResult>(feedbackResultComponentId, ProtoSerializati
 4234        }
 35
 36        public sealed override void Dispose()
 37        {
 438            factory.RemoveComponent(feedbackResultComponentId);
 439            componentWriter.RemoveComponentSerializer(feedbackResultComponentId);
 40
 441            base.Dispose();
 442        }
 43    }
 44
 45    /// <summary>
 46    /// Base class to register deserializer and serializer of UI Component,
 47    /// and create a builder for handler.
 48    /// </summary>
 49    /// <typeparam name="T">Type of component</typeparam>
 50    /// <typeparam name="THandler">Type of handler</typeparam>
 51    public abstract class UIElementRegisterBase<T, THandler> : IDisposable
 52        where T: IMessage<T>, new()
 53        where THandler: class, IECSComponentHandler<T>
 54    {
 55        protected internal delegate THandler HandlerBuilder(IInternalECSComponent<InternalUiContainer> container, int co
 56
 57        protected readonly ECSComponentsFactory factory;
 58        protected readonly IECSComponentWriter componentWriter;
 59        private readonly int componentId;
 60
 61        protected UIElementRegisterBase(int componentId, ECSComponentsFactory factory,
 62            IECSComponentWriter componentWriter, IInternalECSComponent<InternalUiContainer> internalUiContainer,
 63            HandlerBuilder handlerBuilder)
 64        {
 65            factory.AddOrReplaceComponent(componentId, ProtoSerialization.Deserialize<T>,
 66                () => handlerBuilder(internalUiContainer, componentId));
 67
 68            componentWriter.AddOrReplaceComponentSerializer<T>(componentId, ProtoSerialization.Serialize);
 69
 70            this.factory = factory;
 71            this.componentWriter = componentWriter;
 72            this.componentId = componentId;
 73        }
 74
 75        protected virtual void DisposeImpl() { }
 76
 77        public virtual void Dispose()
 78        {
 79            factory.RemoveComponent(componentId);
 80            componentWriter.RemoveComponentSerializer(componentId);
 81            DisposeImpl();
 82        }
 83    }
 84}