< Summary

Information
Class: ImpromptuInterface.Build.NoTarget
Assembly: ImpromptuInterface
File(s): /home/runner/work/impromptu-interface/impromptu-interface/ImpromptuInterface/src/EmitProxy/NoTarget.cs
Line coverage
53%
Covered lines: 14
Uncovered lines: 12
Coverable lines: 26
Total lines: 74
Line coverage: 53.8%
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
.cctor()100%11100%
.ctor()100%11100%
ThrowIfAbsent(...)100%22100%
Absent()100%11100%
TryGetMember(...)100%11100%
TrySetMember(...)100%210%
TryInvokeMember(...)100%210%
TryInvoke(...)100%210%
TryGetIndex(...)100%210%
TrySetIndex(...)100%210%
TryDeleteMember(...)100%210%
TryDeleteIndex(...)100%210%
TryConvert(...)100%210%
TryUnaryOperation(...)100%210%
TryBinaryOperation(...)100%210%
TryCreateInstance(...)100%210%
GetDynamicMemberNames()100%210%
ToString()100%11100%
Equals(...)100%11100%
GetHashCode()100%11100%

File(s)

/home/runner/work/impromptu-interface/impromptu-interface/ImpromptuInterface/src/EmitProxy/NoTarget.cs

#LineLine coverage
 1//
 2//  Copyright 2011 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;
 17using System.Collections.Generic;
 18using System.Dynamic;
 19
 20namespace ImpromptuInterface.Build
 21{
 22    /// <summary>
 23    /// What a proxy forwards to before it has been given a target: every operation explains
 24    /// that there is nothing to forward to, rather than the proxy binding against null and
 25    /// reporting "Cannot perform runtime binding on a null reference".
 26    /// </summary>
 27    /// <remarks>
 28    /// A stand-in rather than a check on the way in: the emitted members all read the target
 29    /// through <see cref="IActLikeProxy.Original"/> and would be covered by a check there, but
 30    /// <c>Equals</c>, <c>GetHashCode</c>, <c>ToString</c> and <c>GetObjectData</c> read the
 31    /// field directly, and a branch on that property cost about 10% of the time of a forwarded
 32    /// property set. One shared instance, so an un-initialized proxy allocates nothing extra.
 33    /// </remarks>
 34    internal sealed class NoTarget : DynamicObject
 35    {
 136        internal static readonly NoTarget Instance = new NoTarget();
 37
 238        private NoTarget() { }
 39
 40        /// <summary>Throws if <paramref name="target"/> is the stand-in, for a reader that cannot go through it.</summa
 41        internal static void ThrowIfAbsent(object target)
 42        {
 13243            if (ReferenceEquals(target, Instance))
 244                throw Absent();
 13045        }
 46
 47        private static InvalidOperationException Absent() =>
 848            new InvalidOperationException(
 849                "This proxy has no target. A proxy wraps an object and forwards to it, so it cannot be " +
 850                "constructed on its own - Activator.CreateInstance on a proxy type produces one with " +
 851                "nothing to forward to. Use ActLike on the object you want wrapped; for an object with " +
 852                "storage of its own, ActLike over an ExpandoObject.");
 53
 154        public override bool TryGetMember(GetMemberBinder binder, out object result) => throw Absent();
 055        public override bool TrySetMember(SetMemberBinder binder, object value) => throw Absent();
 056        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) => throw Absen
 057        public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) => throw Absent();
 058        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result) => throw Absent();
 059        public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value) => throw Absent();
 060        public override bool TryDeleteMember(DeleteMemberBinder binder) => throw Absent();
 061        public override bool TryDeleteIndex(DeleteIndexBinder binder, object[] indexes) => throw Absent();
 062        public override bool TryConvert(ConvertBinder binder, out object result) => throw Absent();
 063        public override bool TryUnaryOperation(UnaryOperationBinder binder, out object result) => throw Absent();
 064        public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result) => throw Ab
 065        public override bool TryCreateInstance(CreateInstanceBinder binder, object[] args, out object result) => throw A
 066        public override IEnumerable<string> GetDynamicMemberNames() => throw Absent();
 67
 68        // The proxy's own Equals/GetHashCode/ToString forward to these, so they explain
 69        // themselves too rather than answering for the stand-in.
 170        public override string ToString() => throw Absent();
 271        public override bool Equals(object obj) => throw Absent();
 272        public override int GetHashCode() => throw Absent();
 73    }
 74}