< Summary

Information
Class: ArturRios.Extensions.ObjectExtensions
Assembly: ArturRios.Extensions
File(s): D:\Repositories\dotnet-extensions\src\ObjectExtensions.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 52
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage
100%
Covered methods: 2
Fully covered methods: 0
Total methods: 2
Method coverage: 100%
Full method coverage: 0%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
NonNullPropertiesToDictionary(...)100%44100%
PropertiesToDictionary(...)100%22100%

File(s)

D:\Repositories\dotnet-extensions\src\ObjectExtensions.cs

#LineLine coverage
 1namespace ArturRios.Extensions;
 2
 3/// <summary>
 4///     Provides extension methods for working with objects
 5/// </summary>
 6public static class ObjectExtensions
 7{
 8    /// <summary>
 9    ///     Provides object helpers for the given instance.
 10    /// </summary>
 11    extension(object @object)
 12    {
 13        /// <summary>
 14        ///     Creates a dictionary of the object's properties containing only those with non-null values.
 15        /// </summary>
 16        /// <returns>A dictionary mapping property names to non-null values.</returns>
 17        public Dictionary<string, object> NonNullPropertiesToDictionary()
 118        {
 119            Dictionary<string, object> dictionary = new();
 20
 921            foreach (var propertyInfo in @object.GetType().GetProperties())
 322            {
 323                var value = propertyInfo.GetValue(@object);
 24
 325                if (value is not null)
 226                {
 227                    dictionary[propertyInfo.Name] = value;
 228                }
 329            }
 30
 131            return dictionary;
 32        }
 33
 34        /// <summary>
 35        ///     Creates a dictionary of the object's properties including those with null values.
 36        /// </summary>
 37        /// <returns>A dictionary mapping property names to values, possibly null.</returns>
 38        public Dictionary<string, object?> PropertiesToDictionary()
 139        {
 140            Dictionary<string, object?> dictionary = new();
 41
 942            foreach (var propertyInfo in @object.GetType().GetProperties())
 343            {
 344                var value = propertyInfo.GetValue(@object);
 45
 346                dictionary[propertyInfo.Name] = value;
 347            }
 48
 149            return dictionary;
 50        }
 51    }
 52}