< Summary

Information
Class: ImpromptuInterface.ActLikeCaster
Assembly: ImpromptuInterface
File(s): /home/runner/work/impromptu-interface/impromptu-interface/ImpromptuInterface/src/ActLikeCaster.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 47
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
TryConvert(...)100%44100%
.ctor(...)100%11100%

File(s)

/home/runner/work/impromptu-interface/impromptu-interface/ImpromptuInterface/src/ActLikeCaster.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Dynamic;
 4using System.Linq;
 5using System.Reflection.Emit;
 6using System.Runtime.Serialization;
 7using System.Text;
 8using ImpromptuInterface.Build;
 9
 10namespace ImpromptuInterface
 11{
 12
 13    public class ActLikeCaster: DynamicObject
 14    {
 15        public object Target { get; }
 16        private List<Type> _interfaceTypes;
 17
 18        public ActLikeMaker Maker {get;set;} = BuildProxy.DefaultProxyMaker;
 19
 20        public override bool TryConvert(System.Dynamic.ConvertBinder binder, out object result)
 21        {
 2622            result = null;
 23
 2624            if (binder.Type.IsInterface)
 25            {
 2426                _interfaceTypes.Insert(0, binder.Type);
 2427                result = Maker.DynamicActLike(Target, _interfaceTypes.ToArray());
 2428                return true;
 29            }
 30
 231            if(binder.Type.IsInstanceOfType(Target))
 32            {
 133                result = Target;
 34            }
 35
 236            return false;
 37        }
 38
 39
 2540        public ActLikeCaster(object target, IEnumerable<Type> types)
 41        {
 2542            Target = target;
 2543            _interfaceTypes = types.ToList();
 2544        }
 45
 46    }
 47}