< Summary

Information
Class: ImpromptuInterface.Optimization.Util
Assembly: ImpromptuInterface
File(s): /home/runner/work/impromptu-interface/impromptu-interface/ImpromptuInterface/src/Optimization/Util.cs
Line coverage
95%
Covered lines: 23
Uncovered lines: 1
Coverable lines: 24
Total lines: 131
Line coverage: 95.8%
Branch coverage
83%
Covered branches: 10
Total branches: 12
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IsAnonymousType(...)83.33%66100%
.cctor()100%11100%
GetTargetContext(...)75%44100%
FixContext(...)100%22100%
GetValue(...)100%210%

File(s)

/home/runner/work/impromptu-interface/impromptu-interface/ImpromptuInterface/src/Optimization/Util.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
 16
 17using System;
 18using System.Collections.Generic;
 19using System.ComponentModel;
 20using System.Dynamic;
 21using System.Linq;
 22using System.Reflection;
 23using System.Runtime.CompilerServices;
 24using System.Runtime.Serialization;
 25using System.Threading;
 26using Dynamitey;
 27using Microsoft.CSharp.RuntimeBinder;
 28
 29
 30
 31namespace ImpromptuInterface.Optimization
 32{
 33    /// <summary>
 34    /// Utility Class
 35    /// </summary>
 36    public static class Util
 37    {
 38        /// <summary>
 39        /// Determines whether [is anonymous type] [the specified target].
 40        /// </summary>
 41        /// <param name="target">The target.</param>
 42        /// <returns>
 43        ///   <c>true</c> if [is anonymous type] [the specified target]; otherwise, <c>false</c>.
 44        /// </returns>
 45        public static bool IsAnonymousType(object target)
 46        {
 447            if(target ==null)
 148                return false;
 49
 350            var type = target as Type ?? target.GetType();
 51
 352            return type.IsNotPublic
 353                   && Attribute.IsDefined(
 354                       type,
 355                       typeof (CompilerGeneratedAttribute),
 356                       false);
 57        }
 58
 59        static Util()
 60        {
 161            IsMono = Type.GetType("Mono.Runtime") != null;
 62
 163        }
 64
 65
 66
 67        /// <summary>
 68        /// Gets the target context.
 69        /// </summary>
 70        /// <param name="target">The target.</param>
 71        /// <param name="context">The context.</param>
 72        /// <param name="staticContext">if set to <c>true</c> [static context].</param>
 73        /// <returns></returns>
 74        public static object GetTargetContext(this object target, out Type context, out bool staticContext)
 75        {
 12976            var tInvokeContext = target as InvokeContext;
 12977            staticContext = false;
 12978            if (tInvokeContext != null)
 79            {
 180                staticContext = tInvokeContext.StaticContext;
 181                context = tInvokeContext.Context;
 182                context = context.FixContext();
 183                return tInvokeContext.Target;
 84            }
 85
 12886            context = target as Type ?? target.GetType();
 12887            context = context.FixContext();
 12888            return target;
 89        }
 90
 91
 92        /// <summary>
 93        /// Fixes the context.
 94        /// </summary>
 95        /// <param name="context">The context.</param>
 96        /// <returns></returns>
 97        public static Type FixContext(this Type context)
 98        {
 38599            if (context.IsArray)
 100            {
 1101                return typeof (object);
 102            }
 384103            return context;
 104        }
 105
 106
 107
 108#if !SILVERLIGHT
 109        /// <summary>
 110        /// Gets the value. Conveinence Ext method
 111        /// </summary>
 112        /// <typeparam name="T"></typeparam>
 113        /// <param name="info">The info.</param>
 114        /// <param name="name">The name.</param>
 115        /// <returns></returns>
 116        public static T GetValue<T>(this SerializationInfo info, string name)
 117        {
 0118            return (T) info.GetValue(name, typeof (T));
 119        }
 120#endif
 121
 122
 123
 124    /// <summary>
 125    /// Is Current Runtime Mono?
 126    /// </summary>
 127    public static readonly bool IsMono;
 128
 129
 130    }
 131}