< Summary

Information
Class: ImpromptuInterface.Impromptu
Assembly: ImpromptuInterface
File(s): /home/runner/work/impromptu-interface/impromptu-interface/ImpromptuInterface/src/Impromptu.cs
Line coverage
92%
Covered lines: 12
Uncovered lines: 1
Coverable lines: 13
Total lines: 114
Line coverage: 92.3%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ActLike(...)100%11100%
UndoActLike(...)100%22100%
ActLike(...)100%11100%
Create()100%210%
Create(...)100%11100%
ActLikeProperties(...)100%11100%
AllActLike(...)100%11100%
DynamicActLike(...)100%11100%

File(s)

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

#LineLine coverage
 1//
 2//  Copyright 2010  Ekon Benefits
 3//
 4//    Licensed under the Apache License, Version 2.0 (the "License");
 5//    you may not use this file except in compliance with the License.
 6//    You may obtain a copy of the License at
 7//
 8//        http://www.apache.org/licenses/LICENSE-2.0
 9//
 10//    Unless required by applicable law or agreed to in writing, software
 11//    distributed under the License is distributed on an "AS IS" BASIS,
 12//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13//    See the License for the specific language governing permissions and
 14//    limitations under the License.
 15
 16using System.Collections.Generic;
 17using System.Reflection.Emit;
 18using ImpromptuInterface.Build;
 19
 20namespace ImpromptuInterface
 21{
 22    using System;
 23
 24
 25    /// <summary>
 26    /// Main API
 27    /// </summary>
 28    public static class Impromptu
 29    {
 30
 31        /// <summary>
 32        /// Extension Method that Wraps an existing object with an Explicit interface definition
 33        /// </summary>
 34        /// <typeparam name="TInterface">The type of the interface.</typeparam>
 35        /// <param name="originalDynamic">The original object can be annoymous type, System.DynamicObject as well as any
 36        /// <param name="otherInterfaces">Optional other interfaces.</param>
 37        /// <returns></returns>
 38        public static TInterface ActLike<TInterface>(this object originalDynamic, params Type[] otherInterfaces) where T
 7939         => BuildProxy.DefaultProxyMaker.ActLike<TInterface>(originalDynamic, otherInterfaces);
 40
 41
 42        /// <summary>
 43        /// Unwraps the act like proxy (if wrapped).
 44        /// </summary>
 45        /// <param name="proxiedObject">The proxied object.</param>
 46        /// <returns></returns>
 47        public static dynamic UndoActLike(this object proxiedObject)
 48        {
 49
 350            var actLikeProxy = proxiedObject as IActLikeProxy;
 351            if (actLikeProxy != null)
 52            {
 253                object original = actLikeProxy.Original;
 54                // Where the stand-in would be handed out rather than used; Initialize
 55                // guards the way back in.
 256                Build.NoTarget.ThrowIfAbsent(original);
 157                return original;
 58            }
 159            return proxiedObject;
 60        }
 61
 62
 63        /// <summary>
 64        /// Extension Method that Wraps an existing object with an Interface of what it is implicitly assigned to.
 65        /// </summary>
 66        /// <param name="originalDynamic">The original dynamic.</param>
 67        /// <param name="otherInterfaces">The other interfaces.</param>
 68        /// <returns></returns>
 69        public static dynamic ActLike(this object originalDynamic, params Type[] otherInterfaces)
 1070            => BuildProxy.DefaultProxyMaker.ActLike(originalDynamic, otherInterfaces);
 71
 72
 73        public static TInterface Create<TTarget, TInterface>() where TTarget : new() where TInterface : class
 074            => BuildProxy.DefaultProxyMaker.Create<TTarget, TInterface>();
 75
 76        public static TInterface Create<TTarget, TInterface>(params object[] args) where TInterface : class
 1277            => BuildProxy.DefaultProxyMaker.Create<TTarget, TInterface>(args);
 78
 79
 80        /// <summary>
 81        /// Makes static methods for the passed in property spec, designed to be used with old api's that reflect proper
 82        /// </summary>
 83        /// <param name="originalDynamic">The original dynamic.</param>
 84        /// <param name="propertySpec">The property spec.</param>
 85        /// <returns></returns>
 86        public static dynamic ActLikeProperties(this object originalDynamic, IDictionary<string, Type> propertySpec)
 187         => BuildProxy.DefaultProxyMaker.ActLikeProperties(originalDynamic, propertySpec);
 88
 89
 90        /// <summary>
 91        /// Chainable Linq to Objects Method, allows you to wrap a list of objects with an Explict interface defintion
 92        /// </summary>
 93        /// <typeparam name="TInterface">The type of the interface.</typeparam>
 94        /// <param name="originalDynamic">The original dynamic.</param>
 95        /// <param name="otherInterfaces">The other interfaces.</param>
 96        /// <returns></returns>
 97        public static IEnumerable<TInterface> AllActLike<TInterface>(this IEnumerable<object> originalDynamic, params Ty
 198            => BuildProxy.DefaultProxyMaker.AllActLike<TInterface>(originalDynamic, otherInterfaces);
 99
 100        /// <summary>
 101        ///
 102        /// Static Method that wraps an existing dynamic object with a explicit interface type
 103        /// </summary>
 104        /// <param name="originalDynamic">The original dynamic.</param>
 105        /// <param name="otherInterfaces">The other interfaces.</param>
 106        /// <returns></returns>
 107        public static dynamic DynamicActLike(object originalDynamic, params Type[] otherInterfaces)
 7108            => BuildProxy.DefaultProxyMaker.DynamicActLike(originalDynamic, otherInterfaces);
 109
 110
 111
 112    }
 113
 114}