Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,7 @@ public abstract class ContractRegistry
/// <summary>
/// Gets an instance of the SignatureDecoder contract for the target.
/// </summary>
public abstract ISignatureDecoder SignatureDecoder { get; }
// public abstract ISignatureDecoder SignatureDecoder { get; }

public abstract TContract GetContract<TContract>() where TContract : IContract;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ namespace Microsoft.Diagnostics.DataContractReader;
public interface IContractFactory<out TContract> where TContract : Contracts.IContract
{
TContract CreateContract(Target target, int version);
Type ContractType => typeof(TContract);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ internal sealed class CachingContractRegistry : ContractRegistry
private readonly Target _target;
private readonly TryGetContractVersionDelegate _tryGetContractVersion;

public CachingContractRegistry(Target target, TryGetContractVersionDelegate tryGetContractVersion, Action<Dictionary<Type, IContractFactory<IContract>>>? configureFactories = null)
public CachingContractRegistry(
Target target,
TryGetContractVersionDelegate tryGetContractVersion,
IEnumerable<IContractFactory<IContract>>? additionalFactories = null,
Action<Dictionary<Type, IContractFactory<IContract>>>? configureFactories = null)
{
_target = target;
_tryGetContractVersion = tryGetContractVersion;
Expand All @@ -45,8 +49,17 @@ public CachingContractRegistry(Target target, TryGetContractVersionDelegate tryG
[typeof(ISHash)] = new SHashFactory(),
[typeof(IGC)] = new GCFactory(),
[typeof(INotifications)] = new NotificationsFactory(),
[typeof(ISignatureDecoder)] = new SignatureDecoderFactory(),
// [typeof(ISignatureDecoder)] = new SignatureDecoderFactory(),
};

if (additionalFactories != null)
{
foreach (IContractFactory<IContract> factory in additionalFactories)
{
_factories[factory.ContractType] = factory;
}
}

configureFactories?.Invoke(_factories);
}

Expand All @@ -69,9 +82,9 @@ public CachingContractRegistry(Target target, TryGetContractVersionDelegate tryG
public override ISHash SHash => GetContract<ISHash>();
public override IGC GC => GetContract<IGC>();
public override INotifications Notifications => GetContract<INotifications>();
public override ISignatureDecoder SignatureDecoder => GetContract<ISignatureDecoder>();
// public override ISignatureDecoder SignatureDecoder => GetContract<ISignatureDecoder>();

private TContract GetContract<TContract>() where TContract : IContract
public override TContract GetContract<TContract>()
{
if (_contracts.TryGetValue(typeof(TContract), out IContract? contractMaybe))
return (TContract)contractMaybe;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using Microsoft.Diagnostics.DataContractReader.Contracts;
using Microsoft.Diagnostics.DataContractReader.Data;

namespace Microsoft.Diagnostics.DataContractReader;
Expand Down Expand Up @@ -108,7 +109,7 @@ public static ContractDescriptorTarget Create(

private ContractDescriptorTarget(Descriptor[] descriptors, DataTargetDelegates dataTargetDelegates)
{
Contracts = new CachingContractRegistry(this, this.TryGetContractVersion);
Contracts = new CachingContractRegistry(this, this.TryGetContractVersion, [new SignatureDecoderFactory()]);
ProcessedData = new DataCache(this);
_config = descriptors[0].Config;
_dataTargetDelegates = dataTargetDelegates;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ int ISOSDacInterface.GetFieldDescData(ClrDataAddress fieldDesc, DacpFieldDescDat

IRuntimeTypeSystem rtsContract = _target.Contracts.RuntimeTypeSystem;
IEcmaMetadata ecmaMetadataContract = _target.Contracts.EcmaMetadata;
ISignatureDecoder signatureDecoder = _target.Contracts.SignatureDecoder;
ISignatureDecoder signatureDecoder = _target.Contracts.GetContract<ISignatureDecoder>();

TargetPointer fieldDescTargetPtr = fieldDesc.ToTargetPointer(_target);
CorElementType fieldDescType = rtsContract.GetFieldDescType(fieldDescTargetPtr);
Expand Down
Loading