File: Data\GC\Generation.cs
Web Access
Project: src\src\runtime\src\native\managed\cdac\Microsoft.Diagnostics.DataContractReader.Contracts\Microsoft.Diagnostics.DataContractReader.Contracts.csproj (Microsoft.Diagnostics.DataContractReader.Contracts)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.Diagnostics.DataContractReader.Data;

internal sealed class Generation : IData<Generation>
{
    static Generation IData<Generation>.Create(Target target, TargetPointer address) => new Generation(target, address);
    public Generation(Target target, TargetPointer address)
    {
        Target.TypeInfo type = target.GetTypeInfo(DataType.Generation);

        AllocationContext = target.ProcessedData.GetOrAdd<GCAllocContext>(address + (ulong)type.Fields[nameof(AllocationContext)].Offset);
        StartSegment = target.ReadPointerField(address, type, nameof(StartSegment));

        // Fields only exist segment GC builds
        if (type.Fields.ContainsKey(nameof(AllocationStart)))
            AllocationStart = target.ReadPointerField(address, type, nameof(AllocationStart));
    }

    public GCAllocContext AllocationContext { get; }
    public TargetPointer StartSegment { get; }
    public TargetPointer? AllocationStart { get; }
}