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

JaCraig / Mecha / 20790333246

07 Jan 2026 05:27PM UTC coverage: 82.197% (-0.2%) from 82.431%
20790333246

push

github

web-flow
Merge pull request #378 from JaCraig/dependabot/nuget/Mecha.Core/dependencies-bddfd397ad

fix: Bump the dependencies group with 1 update

763 of 1060 branches covered (71.98%)

Branch coverage included in aggregate %.

1347 of 1507 relevant lines covered (89.38%)

10364631.25 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;
6✔
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
34,438,200!
46
                && (SliceValueLookup.Slice?.ContainsKey(parameter.ParameterType.GetHashCode()) ?? false);
34,438,200✔
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))
124,581✔
59
                return new("Slice Generator", null);
4✔
60
            try
61
            {
62
                min ??= max;
124,577✔
63
                max ??= min;
124,577✔
64
                if (min is null)
124,577✔
65
                    return new("Slice Generator", FastActivator.CreateInstance(parameter.ParameterType));
65✔
66
                var Key = parameter.ParameterType.GetHashCode();
124,512✔
67
                return new("Slice Generator", SliceValueLookup.Slice?[Key](min!, max!) ?? false);
124,512!
68
            }
69
            catch
×
70
            {
71
                return new("Slice Generator", FastActivator.CreateInstance(parameter.ParameterType));
×
72
            }
73
        }
124,577✔
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