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

loresoft / EntityFrameworkCore.Generator / 15072048022

16 May 2025 03:31PM UTC coverage: 55.392% (-1.4%) from 56.772%
15072048022

push

github

pwelter34
enable nullable support

616 of 1271 branches covered (48.47%)

Branch coverage included in aggregate %.

233 of 397 new or added lines in 61 files covered. (58.69%)

17 existing lines in 11 files now uncovered.

1824 of 3134 relevant lines covered (58.2%)

88.56 hits per line

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

84.44
/src/EntityFrameworkCore.Generator.Core/Parsing/RegionReplace.cs
1
using System.Text;
2

3
namespace EntityFrameworkCore.Generator.Parsing;
4

5
public class RegionReplace
6
{
7
    public RegionReplace(RegionParser? regionParser = null)
69✔
8
    {
9
        RegionParser = regionParser ?? new RegionParser();
69✔
10
    }
69✔
11

12
    protected RegionParser RegionParser { get; }
92✔
13

14
    public void MergeFile(string fullPath, string outputContent)
15
    {
16
        if (string.IsNullOrEmpty(fullPath) || string.IsNullOrEmpty(outputContent) || !Path.Exists(fullPath))
46!
NEW
17
            return;
×
18

19
        var originalContent = File.ReadAllText(fullPath);
46✔
20

21
        var finalContent = MergeContent(originalContent, outputContent);
46✔
22

23
        File.WriteAllText(fullPath, finalContent);
46✔
24
    }
46✔
25

26
    public string MergeContent(string originalContent, string outputContent)
27
    {
28
        if (string.IsNullOrEmpty(originalContent) || string.IsNullOrEmpty(outputContent))
46!
NEW
29
            return originalContent;
×
30

31
        var outputRegions = RegionParser.ParseRegions(outputContent);
46✔
32

33
        var originalRegions = RegionParser.ParseRegions(originalContent);
46✔
34
        var originalBuilder = new StringBuilder(originalContent);
46✔
35

36
        int offset = 0;
46✔
37
        foreach (var pair in outputRegions)
320✔
38
        {
39
            var outputRegion = pair.Value;
114✔
40
            if (!originalRegions.TryGetValue(pair.Key, out var originalRegion))
114✔
41
            {
42
                // log error
43
                continue;
44
            }
45

46
            int startIndex = originalRegion.StartIndex + offset;
114✔
47
            int beforeReplace = originalBuilder.Length;
114✔
48
            int length = (originalRegion.EndIndex + offset) - startIndex;
114✔
49

50
            originalBuilder.Remove(startIndex, length);
114✔
51
            originalBuilder.Insert(startIndex, outputRegion.Content);
114✔
52

53
            int afterReplace = originalBuilder.Length;
114✔
54

55
            offset += (afterReplace - beforeReplace);
114✔
56
        }
57

58
        var finalContent = originalBuilder.ToString();
46✔
59

60
        if (originalContent == finalContent)
46✔
61
            return finalContent;
46✔
62

63
        return finalContent;
64
    }
65
}
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