< Summary

Information
Class: CounterDrone.Core.Algorithms.AlgorithmFactory
Assembly: CounterDrone.Core
File(s): C:\Users\Tellme\apps\CounterDroneBackend\src\CounterDrone.Core\Algorithms\AlgorithmFactory.cs
Line coverage
85%
Covered lines: 12
Uncovered lines: 2
Coverable lines: 14
Total lines: 28
Line coverage: 85.7%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%1183.33%
Register(...)100%11100%
Create()50%2280%

File(s)

C:\Users\Tellme\apps\CounterDroneBackend\src\CounterDrone.Core\Algorithms\AlgorithmFactory.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3
 4namespace CounterDrone.Core.Algorithms
 5{
 6    /// <summary>算法工厂 — 统一管理算法组件的创建与替换</summary>
 7    public static class AlgorithmFactory
 8    {
 19        private static readonly Dictionary<Type, Func<object>> _registry = new()
 110        {
 011            [typeof(ICloudDispersionModel)] = () => new GaussianPuffDispersion(),
 112            [typeof(IDamageModel)]          = () => new DamageModelRouter(),
 113            [typeof(IDefenseAdvisor)]       = () => new DefaultDefenseAdvisor(null),
 114        };
 15
 16        public static void Register<TInterface>(Func<object> factory)
 217        {
 218            _registry[typeof(TInterface)] = factory;
 219        }
 20
 21        public static T Create<T>() where T : class
 1522        {
 1523            if (_registry.TryGetValue(typeof(T), out var factory))
 1524                return (T)factory();
 025            throw new InvalidOperationException($"No implementation for {typeof(T).Name}");
 1526        }
 27    }
 28}