• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JaCraig / Mecha / 19320036518

13 Nov 2025 03:59AM UTC coverage: 82.353% (+0.5%) from 81.847%
19320036518

push

github

web-flow
Merge pull request #366 from JaCraig/dependabot/nuget/Mecha.Core.Tests/dependencies-f8dc83ce5f

chore: Bump Microsoft.CodeAnalysis.NetAnalyzers and Microsoft.NET.Test.Sdk

762 of 1060 branches covered (71.89%)

Branch coverage included in aggregate %.

1352 of 1507 relevant lines covered (89.71%)

9802799.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.29
/Mecha.Core/Generator/DefaultGenerators/SliceGenerator.cs
1
/*
2
Copyright 2021 James Craig
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

17
using Fast.Activator;
18
using Mecha.Core.Generator.DefaultGenerators.Utils;
19
using Mecha.Core.Generator.Interfaces;
20
using System.Reflection;
21

22
namespace Mecha.Core.Generator.DefaultGenerators
23
{
24
    /// <summary>
25
    /// Slice generator
26
    /// </summary>
27
    /// <seealso cref="IGenerator"/>
28
    public class SliceGenerator : IGenerator
29
    {
30
        /// <summary>
31
        /// Gets the order.
32
        /// </summary>
33
        /// <value>The order.</value>
34
        public int Order => 1;
3✔
35

36
        /// <summary>
37
        /// Determines whether this instance can generate the specified parameter.
38
        /// </summary>
39
        /// <param name="parameter">The parameter.</param>
40
        /// <returns>
41
        /// <c>true</c> if this instance can generate the specified parameter; otherwise, <c>false</c>.
42
        /// </returns>
43
        public bool CanGenerate(ParameterInfo? parameter)
44
        {
45
            return parameter?.HasDefaultValue == false
11,177,866!
46
                && (SliceValueLookup.Slice?.ContainsKey(parameter.ParameterType.GetHashCode()) ?? false);
11,177,866✔
47
        }
48

49
        /// <summary>
50
        /// Generates the next object of the specified parameter type.
51
        /// </summary>
52
        /// <param name="parameter">The parameter.</param>
53
        /// <param name="min">The minimum.</param>
54
        /// <param name="max">The maximum.</param>
55
        /// <returns>The next object.</returns>
56
        public ParameterValue? Next(ParameterInfo? parameter, object? min, object? max)
57
        {
58
            if (parameter is null || !CanGenerate(parameter))
51,624✔
59
                return new("Slice Generator", null);
2✔
60
            try
61
            {
62
                min ??= max;
51,622✔
63
                max ??= min;
51,622✔
64
                if (min is null)
51,622!
65
                    return new("Slice Generator", FastActivator.CreateInstance(parameter.ParameterType));
×
66
                var Key = parameter.ParameterType.GetHashCode();
51,622✔
67
                return new("Slice Generator", SliceValueLookup.Slice?[Key](min!, max!) ?? false);
51,622!
68
            }
69
            catch
4✔
70
            {
71
                return new("Slice Generator", FastActivator.CreateInstance(parameter.ParameterType));
4✔
72
            }
73
        }
51,622✔
74
    }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc