From 15c3bab951f1190a6647b3d12a6f2e83e0269995 Mon Sep 17 00:00:00 2001 From: Washi Date: Thu, 20 Apr 2023 18:17:40 +0200 Subject: [PATCH 1/3] Add LazyVariable --- src/AsmResolver.DotNet/AssemblyDefinition.cs | 8 +- src/AsmResolver.DotNet/AssemblyDescriptor.cs | 16 ++-- src/AsmResolver.DotNet/AssemblyReference.cs | 16 ++-- src/AsmResolver.DotNet/ClassLayout.cs | 8 +- src/AsmResolver.DotNet/Constant.cs | 16 ++-- src/AsmResolver.DotNet/CustomAttribute.cs | 24 +++--- src/AsmResolver.DotNet/EventDefinition.cs | 24 +++--- src/AsmResolver.DotNet/ExportedType.cs | 24 +++--- src/AsmResolver.DotNet/FieldDefinition.cs | 72 ++++++++--------- src/AsmResolver.DotNet/FileReference.cs | 16 ++-- src/AsmResolver.DotNet/GenericParameter.cs | 16 ++-- .../GenericParameterConstraint.cs | 16 ++-- src/AsmResolver.DotNet/ImplementationMap.cs | 24 +++--- .../InterfaceImplementation.cs | 16 ++-- src/AsmResolver.DotNet/ManifestResource.cs | 24 +++--- src/AsmResolver.DotNet/MemberReference.cs | 24 +++--- src/AsmResolver.DotNet/MethodDefinition.cs | 64 +++++++-------- src/AsmResolver.DotNet/MethodSemantics.cs | 16 ++-- src/AsmResolver.DotNet/MethodSpecification.cs | 16 ++-- src/AsmResolver.DotNet/ModuleDefinition.cs | 56 ++++++------- src/AsmResolver.DotNet/ModuleReference.cs | 8 +- src/AsmResolver.DotNet/ParameterDefinition.cs | 32 ++++---- src/AsmResolver.DotNet/PropertyDefinition.cs | 32 ++++---- src/AsmResolver.DotNet/SecurityDeclaration.cs | 16 ++-- src/AsmResolver.DotNet/StandAloneSignature.cs | 8 +- src/AsmResolver.DotNet/TypeDefinition.cs | 40 +++++----- src/AsmResolver.DotNet/TypeReference.cs | 28 +++---- src/AsmResolver.DotNet/TypeSpecification.cs | 8 +- src/AsmResolver/LazyVariable.cs | 79 +++++++++++++++++-- 29 files changed, 406 insertions(+), 341 deletions(-) diff --git a/src/AsmResolver.DotNet/AssemblyDefinition.cs b/src/AsmResolver.DotNet/AssemblyDefinition.cs index e379cf590..e0b488f06 100644 --- a/src/AsmResolver.DotNet/AssemblyDefinition.cs +++ b/src/AsmResolver.DotNet/AssemblyDefinition.cs @@ -24,7 +24,7 @@ public class AssemblyDefinition : AssemblyDescriptor, IModuleProvider, IHasSecur { private IList? _modules; private IList? _securityDeclarations; - private readonly LazyVariable _publicKey; + private readonly LazyVariable _publicKey; private byte[]? _publicKeyToken; /// @@ -98,7 +98,7 @@ public static AssemblyDefinition FromImage(IPEImage peImage, ModuleReaderParamet protected AssemblyDefinition(MetadataToken token) : base(token) { - _publicKey = new LazyVariable(GetPublicKey); + _publicKey = new LazyVariable(x => x.GetPublicKey()); } /// @@ -169,10 +169,10 @@ public IList SecurityDeclarations /// public byte[]? PublicKey { - get => _publicKey.Value; + get => _publicKey.GetValue(this); set { - _publicKey.Value = value; + _publicKey.SetValue(value); _publicKeyToken = null; } } diff --git a/src/AsmResolver.DotNet/AssemblyDescriptor.cs b/src/AsmResolver.DotNet/AssemblyDescriptor.cs index ed22fb622..2447823a7 100644 --- a/src/AsmResolver.DotNet/AssemblyDescriptor.cs +++ b/src/AsmResolver.DotNet/AssemblyDescriptor.cs @@ -19,8 +19,8 @@ public abstract class AssemblyDescriptor : MetadataMember, IHasCustomAttribute, { private const int PublicKeyTokenLength = 8; - private readonly LazyVariable _name; - private readonly LazyVariable _culture; + private readonly LazyVariable _name; + private readonly LazyVariable _culture; private IList? _customAttributes; /// @@ -30,8 +30,8 @@ public abstract class AssemblyDescriptor : MetadataMember, IHasCustomAttribute, protected AssemblyDescriptor(MetadataToken token) : base(token) { - _name = new LazyVariable(GetName); - _culture = new LazyVariable(GetCulture); + _name = new LazyVariable(x => x.GetName()); + _culture = new LazyVariable(x => x.GetCulture()); Version = new Version(0, 0, 0, 0); } @@ -43,8 +43,8 @@ protected AssemblyDescriptor(MetadataToken token) /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } string? INameProvider.Name => Name; @@ -175,8 +175,8 @@ protected virtual IList GetCustomAttributes() => /// public Utf8String? Culture { - get => _culture.Value; - set => _culture.Value = value; + get => _culture.GetValue(this); + set => _culture.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/AssemblyReference.cs b/src/AsmResolver.DotNet/AssemblyReference.cs index d4432896c..308e46655 100644 --- a/src/AsmResolver.DotNet/AssemblyReference.cs +++ b/src/AsmResolver.DotNet/AssemblyReference.cs @@ -15,8 +15,8 @@ public class AssemblyReference : IOwnedCollectionElement, IImplementation { - private readonly LazyVariable _publicKeyOrToken; - private readonly LazyVariable _hashValue; + private readonly LazyVariable _publicKeyOrToken; + private readonly LazyVariable _hashValue; private byte[]? _publicKeyToken; /// @@ -26,8 +26,8 @@ public class AssemblyReference : protected AssemblyReference(MetadataToken token) : base(token) { - _publicKeyOrToken = new LazyVariable(GetPublicKeyOrToken); - _hashValue = new LazyVariable(GetHashValue); + _publicKeyOrToken = new LazyVariable(x => x.GetPublicKeyOrToken()); + _hashValue = new LazyVariable(x => x.GetHashValue()); } /// @@ -107,8 +107,8 @@ public ModuleDefinition? Module /// public byte[]? PublicKeyOrToken { - get => _publicKeyOrToken.Value; - set => _publicKeyOrToken.Value = value; + get => _publicKeyOrToken.GetValue(this); + set => _publicKeyOrToken.SetValue(value); } /// @@ -116,8 +116,8 @@ public byte[]? PublicKeyOrToken /// public byte[]? HashValue { - get => _hashValue.Value; - set => _hashValue.Value = value; + get => _hashValue.GetValue(this); + set => _hashValue.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/ClassLayout.cs b/src/AsmResolver.DotNet/ClassLayout.cs index d550dac7a..8c38f54ae 100644 --- a/src/AsmResolver.DotNet/ClassLayout.cs +++ b/src/AsmResolver.DotNet/ClassLayout.cs @@ -7,7 +7,7 @@ namespace AsmResolver.DotNet /// public class ClassLayout : MetadataMember { - private readonly LazyVariable _parent; + private readonly LazyVariable _parent; /// /// Initializes the class layout with a metadata token. @@ -16,7 +16,7 @@ public class ClassLayout : MetadataMember protected ClassLayout(MetadataToken token) : base(token) { - _parent = new LazyVariable(GetParent); + _parent = new LazyVariable(x => x.GetParent()); } /// @@ -58,8 +58,8 @@ public uint ClassSize /// public TypeDefinition? Parent { - get => _parent.Value; - internal set => _parent.Value = value; + get => _parent.GetValue(this); + internal set => _parent.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/Constant.cs b/src/AsmResolver.DotNet/Constant.cs index adb4789a7..0448b5386 100644 --- a/src/AsmResolver.DotNet/Constant.cs +++ b/src/AsmResolver.DotNet/Constant.cs @@ -9,8 +9,8 @@ namespace AsmResolver.DotNet /// public class Constant : MetadataMember { - private readonly LazyVariable _parent; - private readonly LazyVariable _value; + private readonly LazyVariable _parent; + private readonly LazyVariable _value; /// /// Initializes the constant with a metadata token. @@ -19,8 +19,8 @@ public class Constant : MetadataMember protected Constant(MetadataToken token) : base(token) { - _parent = new LazyVariable(GetParent); - _value = new LazyVariable(GetValue); + _parent = new LazyVariable(x => x.GetParent()); + _value = new LazyVariable(x => x.GetValue()); } /// @@ -50,8 +50,8 @@ public ElementType Type /// public IHasConstant? Parent { - get => _parent.Value; - internal set => _parent.Value = value; + get => _parent.GetValue(this); + internal set => _parent.SetValue(value); } /// @@ -59,8 +59,8 @@ public IHasConstant? Parent /// public DataBlobSignature? Value { - get => _value.Value; - set => _value.Value = value; + get => _value.GetValue(this); + set => _value.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/CustomAttribute.cs b/src/AsmResolver.DotNet/CustomAttribute.cs index ddfc5d11e..119ec86ab 100644 --- a/src/AsmResolver.DotNet/CustomAttribute.cs +++ b/src/AsmResolver.DotNet/CustomAttribute.cs @@ -9,9 +9,9 @@ namespace AsmResolver.DotNet /// public class CustomAttribute : MetadataMember, IOwnedCollectionElement { - private readonly LazyVariable _parent; - private readonly LazyVariable _constructor; - private readonly LazyVariable _signature; + private readonly LazyVariable _parent; + private readonly LazyVariable _constructor; + private readonly LazyVariable _signature; /// /// Initializes an empty custom attribute. @@ -20,9 +20,9 @@ public class CustomAttribute : MetadataMember, IOwnedCollectionElement(GetParent); - _constructor = new LazyVariable(GetConstructor); - _signature = new LazyVariable(GetSignature); + _parent = new LazyVariable(x => x.GetParent()); + _constructor = new LazyVariable(x => x.GetConstructor()); + _signature = new LazyVariable(x => x.GetSignature()); } /// @@ -53,8 +53,8 @@ public CustomAttribute(ICustomAttributeType? constructor, CustomAttributeSignatu /// public IHasCustomAttribute? Parent { - get => _parent.Value; - private set => _parent.Value = value; + get => _parent.GetValue(this); + private set => _parent.SetValue(value); } IHasCustomAttribute? IOwnedCollectionElement.Owner @@ -68,8 +68,8 @@ public IHasCustomAttribute? Parent /// public ICustomAttributeType? Constructor { - get => _constructor.Value; - set => _constructor.Value = value; + get => _constructor.GetValue(this); + set => _constructor.SetValue(value); } /// @@ -77,8 +77,8 @@ public ICustomAttributeType? Constructor /// public CustomAttributeSignature? Signature { - get => _signature.Value; - set => _signature.Value = value; + get => _signature.GetValue(this); + set => _signature.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/EventDefinition.cs b/src/AsmResolver.DotNet/EventDefinition.cs index cc36a78d7..0e5f7d13f 100644 --- a/src/AsmResolver.DotNet/EventDefinition.cs +++ b/src/AsmResolver.DotNet/EventDefinition.cs @@ -18,9 +18,9 @@ public class EventDefinition : IHasCustomAttribute, IOwnedCollectionElement { - private readonly LazyVariable _name; - private readonly LazyVariable _declaringType; - private readonly LazyVariable _eventType; + private readonly LazyVariable _name; + private readonly LazyVariable _declaringType; + private readonly LazyVariable _eventType; private IList? _semantics; private IList? _customAttributes; @@ -31,9 +31,9 @@ public class EventDefinition : protected EventDefinition(MetadataToken token) : base(token) { - _name = new LazyVariable(() => GetName()); - _eventType = new LazyVariable(GetEventType); - _declaringType = new LazyVariable(GetDeclaringType); + _name = new LazyVariable(x => x.GetName()); + _eventType = new LazyVariable(x => x.GetEventType()); + _declaringType = new LazyVariable(x => x.GetDeclaringType()); } /// @@ -87,8 +87,8 @@ public bool IsRuntimeSpecialName /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } string? INameProvider.Name => Name; @@ -101,8 +101,8 @@ public Utf8String? Name /// public ITypeDefOrRef? EventType { - get => _eventType.Value; - set => _eventType.Value = value; + get => _eventType.GetValue(this); + set => _eventType.SetValue(value); } /// @@ -113,8 +113,8 @@ public ITypeDefOrRef? EventType /// public TypeDefinition? DeclaringType { - get => _declaringType.Value; - private set => _declaringType.Value = value; + get => _declaringType.GetValue(this); + private set => _declaringType.SetValue(value); } ITypeDescriptor? IMemberDescriptor.DeclaringType => DeclaringType; diff --git a/src/AsmResolver.DotNet/ExportedType.cs b/src/AsmResolver.DotNet/ExportedType.cs index c6253d0ba..dce1c0767 100644 --- a/src/AsmResolver.DotNet/ExportedType.cs +++ b/src/AsmResolver.DotNet/ExportedType.cs @@ -16,9 +16,9 @@ public class ExportedType : ITypeDescriptor, IOwnedCollectionElement { - private readonly LazyVariable _name; - private readonly LazyVariable _namespace; - private readonly LazyVariable _implementation; + private readonly LazyVariable _name; + private readonly LazyVariable _namespace; + private readonly LazyVariable _implementation; private IList? _customAttributes; /// @@ -28,9 +28,9 @@ public class ExportedType : protected ExportedType(MetadataToken token) : base(token) { - _name = new LazyVariable(GetName); - _namespace = new LazyVariable(GetNamespace); - _implementation = new LazyVariable(GetImplementation); + _name = new LazyVariable(x => x.GetName()); + _namespace = new LazyVariable(x => x.GetNamespace()); + _implementation = new LazyVariable(x => x.GetImplementation()); } /// @@ -73,8 +73,8 @@ public uint TypeDefId /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } string? INameProvider.Name => Name; @@ -87,8 +87,8 @@ public Utf8String? Name /// public Utf8String? Namespace { - get => _namespace.Value; - set => _namespace.Value = value; + get => _namespace.GetValue(this); + set => _namespace.SetValue(value); } string? ITypeDescriptor.Namespace => Namespace; @@ -114,8 +114,8 @@ public ModuleDefinition? Module /// public IImplementation? Implementation { - get => _implementation.Value; - set => _implementation.Value = value; + get => _implementation.GetValue(this); + set => _implementation.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/FieldDefinition.cs b/src/AsmResolver.DotNet/FieldDefinition.cs index 0d464fb01..87152c14b 100644 --- a/src/AsmResolver.DotNet/FieldDefinition.cs +++ b/src/AsmResolver.DotNet/FieldDefinition.cs @@ -23,14 +23,14 @@ public class FieldDefinition : IHasFieldMarshal, IOwnedCollectionElement { - private readonly LazyVariable _name; - private readonly LazyVariable _signature; - private readonly LazyVariable _declaringType; - private readonly LazyVariable _constant; - private readonly LazyVariable _marshalDescriptor; - private readonly LazyVariable _implementationMap; - private readonly LazyVariable _fieldRva; - private readonly LazyVariable _fieldOffset; + private readonly LazyVariable _name; + private readonly LazyVariable _signature; + private readonly LazyVariable _declaringType; + private readonly LazyVariable _constant; + private readonly LazyVariable _marshalDescriptor; + private readonly LazyVariable _implementationMap; + private readonly LazyVariable _fieldRva; + private readonly LazyVariable _fieldOffset; private IList? _customAttributes; @@ -41,14 +41,14 @@ public class FieldDefinition : protected FieldDefinition(MetadataToken token) : base(token) { - _name = new LazyVariable(GetName); - _signature = new LazyVariable(GetSignature); - _declaringType = new LazyVariable(GetDeclaringType); - _constant = new LazyVariable(GetConstant); - _marshalDescriptor = new LazyVariable(GetMarshalDescriptor); - _implementationMap = new LazyVariable(GetImplementationMap); - _fieldRva = new LazyVariable(GetFieldRva); - _fieldOffset = new LazyVariable(GetFieldOffset); + _name = new LazyVariable(x => x.GetName()); + _signature = new LazyVariable(x => x.GetSignature()); + _declaringType = new LazyVariable(x => x.GetDeclaringType()); + _constant = new LazyVariable(x => x.GetConstant()); + _marshalDescriptor = new LazyVariable(x => x.GetMarshalDescriptor()); + _implementationMap = new LazyVariable(x => x.GetImplementationMap()); + _fieldRva = new LazyVariable(x => x.GetFieldRva()); + _fieldOffset = new LazyVariable(x => x.GetFieldOffset()); } /// @@ -89,8 +89,8 @@ public FieldDefinition(Utf8String name, FieldAttributes attributes, TypeSignatur /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } string? INameProvider.Name => Name; @@ -100,8 +100,8 @@ public Utf8String? Name /// public FieldSignature? Signature { - get => _signature.Value; - set => _signature.Value = value; + get => _signature.GetValue(this); + set => _signature.SetValue(value); } /// @@ -308,8 +308,8 @@ public bool HasFieldRva /// public TypeDefinition? DeclaringType { - get => _declaringType.Value; - private set => _declaringType.Value = value; + get => _declaringType.GetValue(this); + private set => _declaringType.SetValue(value); } TypeDefinition? IOwnedCollectionElement.Owner @@ -334,29 +334,29 @@ public IList CustomAttributes /// public Constant? Constant { - get => _constant.Value; - set => _constant.Value = value; + get => _constant.GetValue(this); + set => _constant.SetValue(value); } /// public MarshalDescriptor? MarshalDescriptor { - get => _marshalDescriptor.Value; - set => _marshalDescriptor.Value = value; + get => _marshalDescriptor.GetValue(this); + set => _marshalDescriptor.SetValue(value); } /// public ImplementationMap? ImplementationMap { - get => _implementationMap.Value; + get => _implementationMap.GetValue(this); set { - if (value?.MemberForwarded is {}) + if (value?.MemberForwarded is not null) throw new ArgumentException("Cannot add an implementation map that was already added to another member."); - if (_implementationMap.Value is {}) - _implementationMap.Value.MemberForwarded = null; - _implementationMap.Value = value; - if (value is {}) + if (_implementationMap.GetValue(this) is { } map) + map.MemberForwarded = null; + _implementationMap.SetValue(value); + if (value is not null) value.MemberForwarded = this; } } @@ -371,8 +371,8 @@ public ImplementationMap? ImplementationMap /// public ISegment? FieldRva { - get => _fieldRva.Value; - set => _fieldRva.Value = value; + get => _fieldRva.GetValue(this); + set => _fieldRva.SetValue(value); } /// @@ -380,8 +380,8 @@ public ISegment? FieldRva /// public int? FieldOffset { - get => _fieldOffset.Value; - set => _fieldOffset.Value = value; + get => _fieldOffset.GetValue(this); + set => _fieldOffset.SetValue(value); } FieldDefinition IFieldDescriptor.Resolve() => this; diff --git a/src/AsmResolver.DotNet/FileReference.cs b/src/AsmResolver.DotNet/FileReference.cs index 48401e611..d8650d029 100644 --- a/src/AsmResolver.DotNet/FileReference.cs +++ b/src/AsmResolver.DotNet/FileReference.cs @@ -15,8 +15,8 @@ public class FileReference : IManagedEntryPoint, IOwnedCollectionElement { - private readonly LazyVariable _name; - private readonly LazyVariable _hashValue; + private readonly LazyVariable _name; + private readonly LazyVariable _hashValue; private IList? _customAttributes; /// @@ -26,8 +26,8 @@ public class FileReference : protected FileReference(MetadataToken token) : base(token) { - _name = new LazyVariable(GetName); - _hashValue = new LazyVariable(GetHashValue); + _name = new LazyVariable(x => x.GetName()); + _hashValue = new LazyVariable(x => x.GetHashValue()); } /// @@ -78,8 +78,8 @@ public bool ContainsNoMetadata /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } string? INameProvider.Name => Name; @@ -105,8 +105,8 @@ public ModuleDefinition? Module /// public byte[]? HashValue { - get => _hashValue.Value; - set => _hashValue.Value = value; + get => _hashValue.GetValue(this); + set => _hashValue.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/GenericParameter.cs b/src/AsmResolver.DotNet/GenericParameter.cs index a4021ca53..898dd6a11 100644 --- a/src/AsmResolver.DotNet/GenericParameter.cs +++ b/src/AsmResolver.DotNet/GenericParameter.cs @@ -16,8 +16,8 @@ public class GenericParameter : IModuleProvider, IOwnedCollectionElement { - private readonly LazyVariable _name; - private readonly LazyVariable _owner; + private readonly LazyVariable _name; + private readonly LazyVariable _owner; private IList? _constraints; private IList? _customAttributes; @@ -28,8 +28,8 @@ public class GenericParameter : protected GenericParameter(MetadataToken token) : base(token) { - _name = new LazyVariable(GetName); - _owner = new LazyVariable(GetOwner); + _name = new LazyVariable(x => x.GetName()); + _owner = new LazyVariable(x => x.GetOwner()); } /// @@ -59,8 +59,8 @@ public GenericParameter(Utf8String? name, GenericParameterAttributes attributes) /// public IHasGenericParameters? Owner { - get => _owner.Value; - private set => _owner.Value = value; + get => _owner.GetValue(this); + private set => _owner.SetValue(value); } IHasGenericParameters? IOwnedCollectionElement.Owner @@ -77,8 +77,8 @@ public IHasGenericParameters? Owner /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } string? INameProvider.Name => Name; diff --git a/src/AsmResolver.DotNet/GenericParameterConstraint.cs b/src/AsmResolver.DotNet/GenericParameterConstraint.cs index a90888bdd..b1ee65d6d 100644 --- a/src/AsmResolver.DotNet/GenericParameterConstraint.cs +++ b/src/AsmResolver.DotNet/GenericParameterConstraint.cs @@ -14,8 +14,8 @@ public class GenericParameterConstraint : IModuleProvider, IOwnedCollectionElement { - private readonly LazyVariable _owner; - private readonly LazyVariable _constraint; + private readonly LazyVariable _owner; + private readonly LazyVariable _constraint; private IList? _customAttributes; /// @@ -25,8 +25,8 @@ public class GenericParameterConstraint : protected GenericParameterConstraint(MetadataToken token) : base(token) { - _owner = new LazyVariable(GetOwner); - _constraint = new LazyVariable(GetConstraint); + _owner = new LazyVariable(x => x.GetOwner()); + _constraint = new LazyVariable(x => x.GetConstraint()); } /// @@ -44,8 +44,8 @@ public GenericParameterConstraint(ITypeDefOrRef? constraint) /// public GenericParameter? Owner { - get => _owner.Value; - private set => _owner.Value = value; + get => _owner.GetValue(this); + private set => _owner.SetValue(value); } /// @@ -60,8 +60,8 @@ public GenericParameter? Owner /// public ITypeDefOrRef? Constraint { - get => _constraint.Value; - set => _constraint.Value = value; + get => _constraint.GetValue(this); + set => _constraint.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/ImplementationMap.cs b/src/AsmResolver.DotNet/ImplementationMap.cs index b846d8f42..1de68d443 100644 --- a/src/AsmResolver.DotNet/ImplementationMap.cs +++ b/src/AsmResolver.DotNet/ImplementationMap.cs @@ -9,9 +9,9 @@ namespace AsmResolver.DotNet /// public class ImplementationMap : MetadataMember, IFullNameProvider { - private readonly LazyVariable _name; - private readonly LazyVariable _scope; - private readonly LazyVariable _memberForwarded; + private readonly LazyVariable _name; + private readonly LazyVariable _scope; + private readonly LazyVariable _memberForwarded; /// /// Initializes the with a metadata token. @@ -20,9 +20,9 @@ public class ImplementationMap : MetadataMember, IFullNameProvider protected ImplementationMap(MetadataToken token) : base(token) { - _name = new LazyVariable(GetName); - _scope = new LazyVariable(GetScope); - _memberForwarded = new LazyVariable(GetMemberForwarded); + _name = new LazyVariable(x => x.GetName()); + _scope = new LazyVariable(x => x.GetScope()); + _memberForwarded = new LazyVariable(x => x.GetMemberForwarded()); } /// @@ -53,8 +53,8 @@ public ImplementationMapAttributes Attributes /// public IMemberForwarded? MemberForwarded { - get => _memberForwarded.Value; - internal set => _memberForwarded.Value = value; + get => _memberForwarded.GetValue(this); + internal set => _memberForwarded.SetValue(value); } /// @@ -65,8 +65,8 @@ public IMemberForwarded? MemberForwarded /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } string? INameProvider.Name => Name; @@ -81,8 +81,8 @@ public Utf8String? Name /// public ModuleReference? Scope { - get => _scope.Value; - set => _scope.Value = value; + get => _scope.GetValue(this); + set => _scope.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/InterfaceImplementation.cs b/src/AsmResolver.DotNet/InterfaceImplementation.cs index 5184cc074..f34351608 100644 --- a/src/AsmResolver.DotNet/InterfaceImplementation.cs +++ b/src/AsmResolver.DotNet/InterfaceImplementation.cs @@ -14,8 +14,8 @@ public class InterfaceImplementation : IOwnedCollectionElement, IHasCustomAttribute { - private readonly LazyVariable _class; - private readonly LazyVariable _interface; + private readonly LazyVariable _class; + private readonly LazyVariable _interface; private IList? _customAttributes; /// @@ -25,8 +25,8 @@ public class InterfaceImplementation : protected InterfaceImplementation(MetadataToken token) : base(token) { - _class = new LazyVariable(GetClass); - _interface = new LazyVariable(GetInterface); + _class = new LazyVariable(x => x.GetClass()); + _interface = new LazyVariable(x => x.GetInterface()); } /// @@ -44,8 +44,8 @@ public InterfaceImplementation(ITypeDefOrRef? interfaceType) /// public TypeDefinition? Class { - get => _class.Value; - private set => _class.Value = value; + get => _class.GetValue(this); + private set => _class.SetValue(value); } /// @@ -60,8 +60,8 @@ public TypeDefinition? Class /// public ITypeDefOrRef? Interface { - get => _interface.Value; - set => _interface.Value = value; + get => _interface.GetValue(this); + set => _interface.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/ManifestResource.cs b/src/AsmResolver.DotNet/ManifestResource.cs index 4034e9142..ad21436e3 100644 --- a/src/AsmResolver.DotNet/ManifestResource.cs +++ b/src/AsmResolver.DotNet/ManifestResource.cs @@ -18,9 +18,9 @@ public class ManifestResource : IHasCustomAttribute, IOwnedCollectionElement { - private readonly LazyVariable _name; - private readonly LazyVariable _implementation; - private readonly LazyVariable _embeddedData; + private readonly LazyVariable _name; + private readonly LazyVariable _implementation; + private readonly LazyVariable _embeddedData; private IList? _customAttributes; /// @@ -30,9 +30,9 @@ public class ManifestResource : protected ManifestResource(MetadataToken token) : base(token) { - _name = new LazyVariable(GetName); - _implementation = new LazyVariable(GetImplementation); - _embeddedData = new LazyVariable(GetEmbeddedDataSegment); + _name = new LazyVariable(x => x.GetName()); + _implementation = new LazyVariable(x => x.GetImplementation()); + _embeddedData = new LazyVariable(x => x.GetEmbeddedDataSegment()); } /// @@ -110,8 +110,8 @@ public bool IsPrivate /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } string? INameProvider.Name => Name; @@ -121,8 +121,8 @@ public Utf8String? Name /// public IImplementation? Implementation { - get => _implementation.Value; - set => _implementation.Value = value; + get => _implementation.GetValue(this); + set => _implementation.SetValue(value); } /// @@ -135,8 +135,8 @@ public IImplementation? Implementation /// public ISegment? EmbeddedDataSegment { - get => _embeddedData.Value; - set => _embeddedData.Value = value; + get => _embeddedData.GetValue(this); + set => _embeddedData.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/MemberReference.cs b/src/AsmResolver.DotNet/MemberReference.cs index 276ebb1a7..af8606b23 100644 --- a/src/AsmResolver.DotNet/MemberReference.cs +++ b/src/AsmResolver.DotNet/MemberReference.cs @@ -13,9 +13,9 @@ namespace AsmResolver.DotNet /// public class MemberReference : MetadataMember, ICustomAttributeType, IFieldDescriptor { - private readonly LazyVariable _parent; - private readonly LazyVariable _name; - private readonly LazyVariable _signature; + private readonly LazyVariable _parent; + private readonly LazyVariable _name; + private readonly LazyVariable _signature; private IList? _customAttributes; /// @@ -25,9 +25,9 @@ public class MemberReference : MetadataMember, ICustomAttributeType, IFieldDescr protected MemberReference(MetadataToken token) : base(token) { - _parent = new LazyVariable(GetParent); - _name = new LazyVariable(GetName); - _signature = new LazyVariable(GetSignature); + _parent = new LazyVariable(x => x.GetParent()); + _name = new LazyVariable(x => x.GetName()); + _signature = new LazyVariable(x => x.GetSignature()); } /// @@ -50,8 +50,8 @@ public MemberReference(IMemberRefParent? parent, Utf8String? name, MemberSignatu /// public IMemberRefParent? Parent { - get => _parent.Value; - set => _parent.Value = value; + get => _parent.GetValue(this); + set => _parent.SetValue(value); } /// @@ -62,8 +62,8 @@ public IMemberRefParent? Parent /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// @@ -77,8 +77,8 @@ public Utf8String? Name /// public CallingConventionSignature? Signature { - get => _signature.Value; - set => _signature.Value = value; + get => _signature.GetValue(this); + set => _signature.SetValue(value); } MethodSignature? IMethodDescriptor.Signature => Signature as MethodSignature; diff --git a/src/AsmResolver.DotNet/MethodDefinition.cs b/src/AsmResolver.DotNet/MethodDefinition.cs index 2e40249fc..234396cb2 100644 --- a/src/AsmResolver.DotNet/MethodDefinition.cs +++ b/src/AsmResolver.DotNet/MethodDefinition.cs @@ -27,13 +27,13 @@ public class MethodDefinition : IHasSecurityDeclaration, IManagedEntryPoint { - private readonly LazyVariable _name; - private readonly LazyVariable _declaringType; - private readonly LazyVariable _signature; - private readonly LazyVariable _methodBody; - private readonly LazyVariable _implementationMap; - private readonly LazyVariable _semantics; - private readonly LazyVariable _exportInfo; + private readonly LazyVariable _name; + private readonly LazyVariable _declaringType; + private readonly LazyVariable _signature; + private readonly LazyVariable _methodBody; + private readonly LazyVariable _implementationMap; + private readonly LazyVariable _semantics; + private readonly LazyVariable _exportInfo; private IList? _parameterDefinitions; private ParameterCollection? _parameters; private IList? _customAttributes; @@ -47,13 +47,13 @@ public class MethodDefinition : protected MethodDefinition(MetadataToken token) : base(token) { - _name =new LazyVariable(GetName); - _declaringType = new LazyVariable(GetDeclaringType); - _signature = new LazyVariable(GetSignature); - _methodBody = new LazyVariable(GetBody); - _implementationMap = new LazyVariable(GetImplementationMap); - _semantics = new LazyVariable(GetSemantics); - _exportInfo = new LazyVariable(GetExportInfo); + _name = new LazyVariable(x => GetName()); + _declaringType = new LazyVariable(x => GetDeclaringType()); + _signature = new LazyVariable(x => x.GetSignature()); + _methodBody = new LazyVariable(x => x.GetBody()); + _implementationMap = new LazyVariable(x => x.GetImplementationMap()); + _semantics = new LazyVariable(x => x.GetSemantics()); + _exportInfo = new LazyVariable(x => x.GetExportInfo()); } /// @@ -83,8 +83,8 @@ public MethodDefinition(Utf8String? name, MethodAttributes attributes, MethodSig /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } string? INameProvider.Name => Name; @@ -95,8 +95,8 @@ public Utf8String? Name /// public MethodSignature? Signature { - get => _signature.Value; - set => _signature.Value = value; + get => _signature.GetValue(this); + set => _signature.SetValue(value); } /// @@ -483,8 +483,8 @@ public bool NoInlining /// public TypeDefinition? DeclaringType { - get => _declaringType.Value; - set => _declaringType.Value = value; + get => _declaringType.GetValue(this); + set => _declaringType.SetValue(value); } ITypeDescriptor? IMemberDescriptor.DeclaringType => DeclaringType; @@ -546,8 +546,8 @@ public ParameterCollection Parameters /// public MethodBody? MethodBody { - get => _methodBody.Value; - set => _methodBody.Value = value; + get => _methodBody.GetValue(this); + set => _methodBody.SetValue(value); } /// @@ -594,15 +594,15 @@ public NativeMethodBody? NativeMethodBody /// public ImplementationMap? ImplementationMap { - get => _implementationMap.Value; + get => _implementationMap.GetValue(this); set { - if (value?.MemberForwarded is {}) + if (value?.MemberForwarded is not null) throw new ArgumentException("Cannot add an implementation map that was already added to another member."); - if (_implementationMap.Value is {}) - _implementationMap.Value.MemberForwarded = null; - _implementationMap.Value = value; - if (value is {}) + if (_implementationMap.GetValue(this) is { } map) + map.MemberForwarded = null; + _implementationMap.SetValue(value); + if (value is not null) value.MemberForwarded = this; } } @@ -645,8 +645,8 @@ public IList GenericParameters /// public MethodSemantics? Semantics { - get => _semantics.Value; - set => _semantics.Value = value; + get => _semantics.GetValue(this); + set => _semantics.SetValue(value); } /// @@ -685,8 +685,8 @@ public MethodSemantics? Semantics /// public UnmanagedExportInfo? ExportInfo { - get => _exportInfo.Value; - set => _exportInfo.Value = value; + get => _exportInfo.GetValue(this); + set => _exportInfo.SetValue(value); } MethodDefinition IMethodDescriptor.Resolve() => this; diff --git a/src/AsmResolver.DotNet/MethodSemantics.cs b/src/AsmResolver.DotNet/MethodSemantics.cs index 42409c737..4686c6b48 100644 --- a/src/AsmResolver.DotNet/MethodSemantics.cs +++ b/src/AsmResolver.DotNet/MethodSemantics.cs @@ -10,8 +10,8 @@ namespace AsmResolver.DotNet /// public class MethodSemantics : MetadataMember, IOwnedCollectionElement { - private readonly LazyVariable _method; - private readonly LazyVariable _association; + private readonly LazyVariable _method; + private readonly LazyVariable _association; /// /// Initializes an empty method semantics object. @@ -20,8 +20,8 @@ public class MethodSemantics : MetadataMember, IOwnedCollectionElement(GetMethod); - _association = new LazyVariable(GetAssociation); + _method = new LazyVariable(x => x.GetMethod()); + _association = new LazyVariable(x => x.GetAssociation()); } /// @@ -50,8 +50,8 @@ public MethodSemanticsAttributes Attributes /// public MethodDefinition? Method { - get => _method.Value; - private set => _method.Value = value; + get => _method.GetValue(this); + private set => _method.SetValue(value); } /// @@ -59,8 +59,8 @@ public MethodDefinition? Method /// public IHasSemantics? Association { - get => _association.Value; - private set => _association.Value = value; + get => _association.GetValue(this); + private set => _association.SetValue(value); } IHasSemantics? IOwnedCollectionElement.Owner diff --git a/src/AsmResolver.DotNet/MethodSpecification.cs b/src/AsmResolver.DotNet/MethodSpecification.cs index e9b9a3210..a01257405 100644 --- a/src/AsmResolver.DotNet/MethodSpecification.cs +++ b/src/AsmResolver.DotNet/MethodSpecification.cs @@ -11,8 +11,8 @@ namespace AsmResolver.DotNet /// public class MethodSpecification : MetadataMember, IMethodDescriptor, IHasCustomAttribute { - private readonly LazyVariable _method; - private readonly LazyVariable _signature; + private readonly LazyVariable _method; + private readonly LazyVariable _signature; private IList? _customAttributes; /// @@ -22,8 +22,8 @@ public class MethodSpecification : MetadataMember, IMethodDescriptor, IHasCustom protected MethodSpecification(MetadataToken token) : base(token) { - _method = new LazyVariable(GetMethod); - _signature = new LazyVariable(GetSignature); + _method = new LazyVariable(x => x.GetMethod()); + _signature = new LazyVariable(x => x.GetSignature()); } /// @@ -43,8 +43,8 @@ public MethodSpecification(IMethodDefOrRef? method, GenericInstanceMethodSignatu /// public IMethodDefOrRef? Method { - get => _method.Value; - set => _method.Value = value; + get => _method.GetValue(this); + set => _method.SetValue(value); } MethodSignature? IMethodDescriptor.Signature => Method?.Signature; @@ -54,8 +54,8 @@ public IMethodDefOrRef? Method /// public GenericInstanceMethodSignature? Signature { - get => _signature.Value; - set => _signature.Value = value; + get => _signature.GetValue(this); + set => _signature.SetValue(value); } diff --git a/src/AsmResolver.DotNet/ModuleDefinition.cs b/src/AsmResolver.DotNet/ModuleDefinition.cs index 710745aa4..a4108cfc6 100644 --- a/src/AsmResolver.DotNet/ModuleDefinition.cs +++ b/src/AsmResolver.DotNet/ModuleDefinition.cs @@ -35,24 +35,24 @@ public class ModuleDefinition : { private static MethodInfo? GetHINSTANCEMethod; - private readonly LazyVariable _name; - private readonly LazyVariable _mvid; - private readonly LazyVariable _encId; - private readonly LazyVariable _encBaseId; + private readonly LazyVariable _name; + private readonly LazyVariable _mvid; + private readonly LazyVariable _encId; + private readonly LazyVariable _encBaseId; private IList? _topLevelTypes; private IList? _assemblyReferences; private IList? _customAttributes; - private readonly LazyVariable _managedEntryPoint; + private readonly LazyVariable _managedEntryPoint; private IList? _moduleReferences; private IList? _fileReferences; private IList? _resources; private IList? _exportedTypes; private TokenAllocator? _tokenAllocator; - private readonly LazyVariable _runtimeVersion; - private readonly LazyVariable _nativeResources; + private readonly LazyVariable _runtimeVersion; + private readonly LazyVariable _nativeResources; private IList? _debugData; private ReferenceImporter? _defaultImporter; @@ -267,13 +267,13 @@ public static ModuleDefinition FromImage(IPEImage peImage, ModuleReaderParameter protected ModuleDefinition(MetadataToken token) : base(token) { - _name = new LazyVariable(GetName); - _mvid = new LazyVariable(GetMvid); - _encId = new LazyVariable(GetEncId); - _encBaseId = new LazyVariable(GetEncBaseId); - _managedEntryPoint = new LazyVariable(GetManagedEntryPoint); - _runtimeVersion = new LazyVariable(GetRuntimeVersion); - _nativeResources = new LazyVariable(GetNativeResources); + _name = new LazyVariable(x => x.GetName()); + _mvid = new LazyVariable(x => x.GetMvid()); + _encId = new LazyVariable(x => x.GetEncId()); + _encBaseId = new LazyVariable(x => x.GetEncBaseId()); + _managedEntryPoint = new LazyVariable(x => x.GetManagedEntryPoint()); + _runtimeVersion = new LazyVariable(x => x.GetRuntimeVersion()); + _nativeResources = new LazyVariable(x => x.GetNativeResources()); Attributes = DotNetDirectoryFlags.ILOnly; } @@ -384,8 +384,8 @@ public AssemblyDefinition? Assembly /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } string? INameProvider.Name => Name; @@ -416,8 +416,8 @@ public ushort Generation /// public Guid Mvid { - get => _mvid.Value; - set => _mvid.Value = value; + get => _mvid.GetValue(this); + set => _mvid.SetValue(value); } /// @@ -428,8 +428,8 @@ public Guid Mvid /// public Guid EncId { - get => _encId.Value; - set => _encId.Value = value; + get => _encId.GetValue(this); + set => _encId.SetValue(value); } /// @@ -440,8 +440,8 @@ public Guid EncId /// public Guid EncBaseId { - get => _encBaseId.Value; - set => _encBaseId.Value = value; + get => _encBaseId.GetValue(this); + set => _encBaseId.SetValue(value); } /// @@ -635,8 +635,8 @@ public IList DebugData /// public string RuntimeVersion { - get => _runtimeVersion.Value; - set => _runtimeVersion.Value = value; + get => _runtimeVersion.GetValue(this); + set => _runtimeVersion.SetValue(value); } /// @@ -645,8 +645,8 @@ public string RuntimeVersion /// public IResourceDirectory? NativeResourceDirectory { - get => _nativeResources.Value; - set => _nativeResources.Value = value; + get => _nativeResources.GetValue(this); + set => _nativeResources.SetValue(value); } /// @@ -772,8 +772,8 @@ public MethodDefinition? ManagedEntryPointMethod /// public IManagedEntryPoint? ManagedEntryPoint { - get => _managedEntryPoint.Value; - set => _managedEntryPoint.Value = value; + get => _managedEntryPoint.GetValue(this); + set => _managedEntryPoint.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/ModuleReference.cs b/src/AsmResolver.DotNet/ModuleReference.cs index 87f8a52e2..f4666024c 100644 --- a/src/AsmResolver.DotNet/ModuleReference.cs +++ b/src/AsmResolver.DotNet/ModuleReference.cs @@ -15,7 +15,7 @@ public class ModuleReference : IHasCustomAttribute, IOwnedCollectionElement { - private readonly LazyVariable _name; + private readonly LazyVariable _name; private IList? _customAttributes; /// @@ -25,7 +25,7 @@ public class ModuleReference : protected ModuleReference(MetadataToken token) : base(token) { - _name = new LazyVariable(GetName); + _name = new LazyVariable(x => x.GetName()); } /// @@ -46,8 +46,8 @@ public ModuleReference(Utf8String? name) /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } string? INameProvider.Name => Name; diff --git a/src/AsmResolver.DotNet/ParameterDefinition.cs b/src/AsmResolver.DotNet/ParameterDefinition.cs index 81e815ea9..0327a669d 100644 --- a/src/AsmResolver.DotNet/ParameterDefinition.cs +++ b/src/AsmResolver.DotNet/ParameterDefinition.cs @@ -22,10 +22,10 @@ public class ParameterDefinition : IHasFieldMarshal, IOwnedCollectionElement { - private readonly LazyVariable _name; - private readonly LazyVariable _method; - private readonly LazyVariable _constant; - private readonly LazyVariable _marshalDescriptor; + private readonly LazyVariable _name; + private readonly LazyVariable _method; + private readonly LazyVariable _constant; + private readonly LazyVariable _marshalDescriptor; private IList? _customAttributes; /// @@ -35,10 +35,10 @@ public class ParameterDefinition : protected ParameterDefinition(MetadataToken token) : base(token) { - _name = new LazyVariable(GetName); - _method = new LazyVariable(GetMethod); - _constant = new LazyVariable(GetConstant); - _marshalDescriptor = new LazyVariable(GetMarshalDescriptor); + _name = new LazyVariable(x => x.GetName()); + _method = new LazyVariable(x => x.GetMethod()); + _constant = new LazyVariable(x => x.GetConstant()); + _marshalDescriptor = new LazyVariable(x => x.GetMarshalDescriptor()); } /// @@ -73,8 +73,8 @@ public ParameterDefinition(ushort sequence, Utf8String? name, ParameterAttribute /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } string? INameProvider.Name => Name; @@ -162,8 +162,8 @@ public bool HasFieldMarshal /// public MethodDefinition? Method { - get => _method.Value; - private set => _method.Value = value; + get => _method.GetValue(this); + private set => _method.SetValue(value); } MethodDefinition? IOwnedCollectionElement.Owner @@ -194,8 +194,8 @@ public IList CustomAttributes /// public Constant? Constant { - get => _constant.Value; - set => _constant.Value = value; + get => _constant.GetValue(this); + set => _constant.SetValue(value); } /// @@ -206,8 +206,8 @@ public Constant? Constant /// public MarshalDescriptor? MarshalDescriptor { - get => _marshalDescriptor.Value; - set => _marshalDescriptor.Value = value; + get => _marshalDescriptor.GetValue(this); + set => _marshalDescriptor.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/PropertyDefinition.cs b/src/AsmResolver.DotNet/PropertyDefinition.cs index ac35369ab..db8b9cc79 100644 --- a/src/AsmResolver.DotNet/PropertyDefinition.cs +++ b/src/AsmResolver.DotNet/PropertyDefinition.cs @@ -20,10 +20,10 @@ public class PropertyDefinition : IHasConstant, IOwnedCollectionElement { - private readonly LazyVariable _name; - private readonly LazyVariable _declaringType; - private readonly LazyVariable _signature; - private readonly LazyVariable _constant; + private readonly LazyVariable _name; + private readonly LazyVariable _declaringType; + private readonly LazyVariable _signature; + private readonly LazyVariable _constant; private IList? _semantics; private IList? _customAttributes; @@ -34,10 +34,10 @@ public class PropertyDefinition : protected PropertyDefinition(MetadataToken token) : base(token) { - _name = new LazyVariable(GetName); - _signature = new LazyVariable(GetSignature); - _declaringType = new LazyVariable(GetDeclaringType); - _constant = new LazyVariable(GetConstant); + _name = new LazyVariable(x => x.GetName()); + _signature = new LazyVariable(x => x.GetSignature()); + _declaringType = new LazyVariable(x => x.GetDeclaringType()); + _constant = new LazyVariable(x => x.GetConstant()); } /// @@ -102,8 +102,8 @@ public bool HasDefault /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } string? INameProvider.Name => Name; @@ -117,8 +117,8 @@ public Utf8String? Name /// public PropertySignature? Signature { - get => _signature.Value; - set => _signature.Value = value; + get => _signature.GetValue(this); + set => _signature.SetValue(value); } /// @@ -129,8 +129,8 @@ public PropertySignature? Signature /// public TypeDefinition? DeclaringType { - get => _declaringType.Value; - private set => _declaringType.Value = value; + get => _declaringType.GetValue(this); + private set => _declaringType.SetValue(value); } ITypeDescriptor? IMemberDescriptor.DeclaringType => DeclaringType; @@ -166,8 +166,8 @@ public IList CustomAttributes /// public Constant? Constant { - get => _constant.Value; - set => _constant.Value = value; + get => _constant.GetValue(this); + set => _constant.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/SecurityDeclaration.cs b/src/AsmResolver.DotNet/SecurityDeclaration.cs index 7f3c1d572..5688f8b92 100644 --- a/src/AsmResolver.DotNet/SecurityDeclaration.cs +++ b/src/AsmResolver.DotNet/SecurityDeclaration.cs @@ -12,8 +12,8 @@ public class SecurityDeclaration : MetadataMember, IOwnedCollectionElement { - private readonly LazyVariable _parent; - private readonly LazyVariable _permissionSet; + private readonly LazyVariable _parent; + private readonly LazyVariable _permissionSet; /// /// Initializes the with a metadata token. @@ -22,8 +22,8 @@ public class SecurityDeclaration : protected SecurityDeclaration(MetadataToken token) : base(token) { - _parent = new LazyVariable(GetParent); - _permissionSet = new LazyVariable(GetPermissionSet); + _parent = new LazyVariable(x => x.GetParent()); + _permissionSet = new LazyVariable(x => x.GetPermissionSet()); } /// @@ -52,8 +52,8 @@ public SecurityAction Action /// public IHasSecurityDeclaration? Parent { - get => _parent.Value; - private set => _parent.Value = value; + get => _parent.GetValue(this); + private set => _parent.SetValue(value); } /// @@ -68,8 +68,8 @@ public IHasSecurityDeclaration? Parent /// public PermissionSetSignature? PermissionSet { - get => _permissionSet.Value; - set => _permissionSet.Value = value; + get => _permissionSet.GetValue(this); + set => _permissionSet.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/StandAloneSignature.cs b/src/AsmResolver.DotNet/StandAloneSignature.cs index c6a90ac16..3e6bed4c6 100644 --- a/src/AsmResolver.DotNet/StandAloneSignature.cs +++ b/src/AsmResolver.DotNet/StandAloneSignature.cs @@ -15,7 +15,7 @@ namespace AsmResolver.DotNet /// public class StandAloneSignature : MetadataMember, IHasCustomAttribute { - private readonly LazyVariable _signature; + private readonly LazyVariable _signature; private IList? _customAttributes; /// @@ -25,7 +25,7 @@ public class StandAloneSignature : MetadataMember, IHasCustomAttribute protected StandAloneSignature(MetadataToken token) : base(token) { - _signature = new LazyVariable(GetSignature); + _signature = new LazyVariable(x => x.GetSignature()); } /// @@ -43,8 +43,8 @@ public StandAloneSignature(BlobSignature signature) /// public BlobSignature? Signature { - get => _signature.Value; - set => _signature.Value = value; + get => _signature.GetValue(this); + set => _signature.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/TypeDefinition.cs b/src/AsmResolver.DotNet/TypeDefinition.cs index 21821ad1c..b3792ad8b 100644 --- a/src/AsmResolver.DotNet/TypeDefinition.cs +++ b/src/AsmResolver.DotNet/TypeDefinition.cs @@ -27,11 +27,11 @@ public class TypeDefinition : { internal static readonly Utf8String ModuleTypeName = ""; - private readonly LazyVariable _namespace; - private readonly LazyVariable _name; - private readonly LazyVariable _baseType; - private readonly LazyVariable _declaringType; - private readonly LazyVariable _classLayout; + private readonly LazyVariable _namespace; + private readonly LazyVariable _name; + private readonly LazyVariable _baseType; + private readonly LazyVariable _declaringType; + private readonly LazyVariable _classLayout; private IList? _nestedTypes; private ModuleDefinition? _module; private IList? _fields; @@ -51,11 +51,11 @@ public class TypeDefinition : protected TypeDefinition(MetadataToken token) : base(token) { - _namespace = new LazyVariable(GetNamespace); - _name = new LazyVariable(GetName); - _baseType = new LazyVariable(GetBaseType); - _declaringType = new LazyVariable(GetDeclaringType); - _classLayout = new LazyVariable(GetClassLayout); + _namespace = new LazyVariable(x => x.GetNamespace()); + _name = new LazyVariable(x => x.GetName()); + _baseType = new LazyVariable(x => x.GetBaseType()); + _declaringType = new LazyVariable(x => x.GetDeclaringType()); + _classLayout = new LazyVariable(x => x.GetClassLayout()); } /// @@ -93,8 +93,8 @@ public TypeDefinition(Utf8String? ns, Utf8String? name, TypeAttributes attribute /// public Utf8String? Namespace { - get => _namespace.Value; - set => _namespace.Value = value; + get => _namespace.GetValue(this); + set => _namespace.SetValue(value); } string? ITypeDescriptor.Namespace => Namespace; @@ -107,8 +107,8 @@ public Utf8String? Namespace /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } string? INameProvider.Name => Name; @@ -415,8 +415,8 @@ public bool HasSecurity /// public ITypeDefOrRef? BaseType { - get => _baseType.Value; - set => _baseType.Value = value; + get => _baseType.GetValue(this); + set => _baseType.SetValue(value); } /// @@ -435,8 +435,8 @@ public ITypeDefOrRef? BaseType /// public TypeDefinition? DeclaringType { - get => _declaringType.Value; - private set => _declaringType.Value = value; + get => _declaringType.GetValue(this); + private set => _declaringType.SetValue(value); } ITypeDefOrRef? ITypeDefOrRef.DeclaringType => DeclaringType; @@ -642,8 +642,8 @@ public IList MethodImplementations /// public ClassLayout? ClassLayout { - get => _classLayout.Value; - set => _classLayout.Value = value; + get => _classLayout.GetValue(this); + set => _classLayout.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/TypeReference.cs b/src/AsmResolver.DotNet/TypeReference.cs index 2db296a1a..5e5294d7b 100644 --- a/src/AsmResolver.DotNet/TypeReference.cs +++ b/src/AsmResolver.DotNet/TypeReference.cs @@ -14,9 +14,9 @@ public class TypeReference : ITypeDefOrRef, IResolutionScope { - private readonly LazyVariable _name; - private readonly LazyVariable _namespace; - private readonly LazyVariable _scope; + private readonly LazyVariable _name; + private readonly LazyVariable _namespace; + private readonly LazyVariable _scope; private IList? _customAttributes; /// @@ -26,9 +26,9 @@ public class TypeReference : protected TypeReference(MetadataToken token) : base(token) { - _name = new LazyVariable(GetName); - _namespace = new LazyVariable(GetNamespace); - _scope = new LazyVariable(GetScope); + _name = new LazyVariable(x => x.GetName()); + _namespace = new LazyVariable(x => x.GetNamespace()); + _scope = new LazyVariable(x => x.GetScope()); } /// @@ -40,7 +40,7 @@ protected TypeReference(MetadataToken token) public TypeReference(IResolutionScope? scope, Utf8String? ns, Utf8String? name) : this(new MetadataToken(TableIndex.TypeRef, 0)) { - _scope.Value = scope; + _scope.SetValue(scope); Namespace = ns; Name = name; } @@ -55,7 +55,7 @@ public TypeReference(IResolutionScope? scope, Utf8String? ns, Utf8String? name) public TypeReference(ModuleDefinition? module, IResolutionScope? scope, Utf8String? ns, Utf8String? name) : this(new MetadataToken(TableIndex.TypeRef, 0)) { - _scope.Value = scope; + _scope.SetValue(scope); Module = module; Namespace = ns; Name = name; @@ -69,8 +69,8 @@ public TypeReference(ModuleDefinition? module, IResolutionScope? scope, Utf8Stri /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } string? INameProvider.Name => Name; @@ -83,8 +83,8 @@ public Utf8String? Name /// public Utf8String? Namespace { - get => _namespace.Value; - set => _namespace.Value = value; + get => _namespace.GetValue(this); + set => _namespace.SetValue(value); } string? ITypeDescriptor.Namespace => Namespace; @@ -95,8 +95,8 @@ public Utf8String? Namespace /// public IResolutionScope? Scope { - get => _scope.Value; - set => _scope.Value = value; + get => _scope.GetValue(this); + set => _scope.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/TypeSpecification.cs b/src/AsmResolver.DotNet/TypeSpecification.cs index d601ec7a7..56c0388c8 100644 --- a/src/AsmResolver.DotNet/TypeSpecification.cs +++ b/src/AsmResolver.DotNet/TypeSpecification.cs @@ -14,7 +14,7 @@ public class TypeSpecification : MetadataMember, ITypeDefOrRef { - private readonly LazyVariable _signature; + private readonly LazyVariable _signature; private IList? _customAttributes; /// @@ -24,7 +24,7 @@ public class TypeSpecification : protected TypeSpecification(MetadataToken token) : base(token) { - _signature = new LazyVariable(GetSignature); + _signature = new LazyVariable(x => x.GetSignature()); } /// @@ -42,8 +42,8 @@ public TypeSpecification(TypeSignature? signature) /// public TypeSignature? Signature { - get => _signature.Value; - set => _signature.Value = value; + get => _signature.GetValue(this); + set => _signature.SetValue(value); } /// diff --git a/src/AsmResolver/LazyVariable.cs b/src/AsmResolver/LazyVariable.cs index c0f4775d7..6b4ac9814 100644 --- a/src/AsmResolver/LazyVariable.cs +++ b/src/AsmResolver/LazyVariable.cs @@ -6,21 +6,21 @@ namespace AsmResolver /// /// Represents a variable that can be lazily initialized and/or assigned a new value. /// - /// The type of the values that the variable stores. + /// The type of the values that the variable stores. /// /// For performance reasons, this class locks on itself for thread synchronization. Therefore, consumers /// should not lock instances of this class as a lock object to avoid dead-locks. /// - public class LazyVariable + public sealed class LazyVariable { - private T? _value; - private readonly Func? _getValue; + private TValue? _value; + private readonly Func? _getValue; /// /// Creates a new lazy variable and initialize it with a constant. /// /// The value to initialize the variable with. - public LazyVariable(T value) + public LazyVariable(TValue value) { _value = value; IsInitialized = true; @@ -30,7 +30,7 @@ public LazyVariable(T value) /// Creates a new lazy variable and delays the initialization of the default value. /// /// The method to execute when initializing the default value. - public LazyVariable(Func getValue) + public LazyVariable(Func getValue) { _getValue = getValue ?? throw new ArgumentNullException(nameof(getValue)); } @@ -48,7 +48,7 @@ public bool IsInitialized /// /// Gets or sets the value of the variable. /// - public T Value + public TValue Value { get { @@ -79,4 +79,69 @@ private void InitializeValue() } } + + public sealed class LazyVariable + { + private TValue? _value; + private readonly Func? _getValue; + + /// + /// Creates a new lazy variable and initialize it with a constant. + /// + /// The value to initialize the variable with. + public LazyVariable(TValue value) + { + _value = value; + IsInitialized = true; + } + + /// + /// Creates a new lazy variable and delays the initialization of the default value. + /// + /// The method to execute when initializing the default value. + public LazyVariable(Func getValue) + { + _getValue = getValue ?? throw new ArgumentNullException(nameof(getValue)); + } + + /// + /// Gets a value indicating the value has been initialized. + /// + [MemberNotNullWhen(false, nameof(_getValue))] + public bool IsInitialized + { + get; + private set; + } + + public TValue GetValue(TOwner owner) + { + if (!IsInitialized) + InitializeValue(owner); + return _value!; + } + + public void SetValue(TValue value) + { + lock (this) + { + _value = value; + IsInitialized = true; + } + } + + private void InitializeValue(TOwner owner) + { + lock (this) + { + if (!IsInitialized) + { + _value = _getValue(owner); + IsInitialized = true; + } + } + } + + } + } From 6ac13ad5cf2a11b508cec85d3297911bf4b69922 Mon Sep 17 00:00:00 2001 From: Washi Date: Thu, 20 Apr 2023 18:32:15 +0200 Subject: [PATCH 2/3] Move PE.File, PE and remainder of DotNet to new lazyvar. --- src/AsmResolver.DotNet/Bundles/BundleFile.cs | 10 ++-- .../Resources/ResourceSetEntry.cs | 14 ++--- src/AsmResolver.PE.File/PEFile.cs | 16 +++--- src/AsmResolver.PE/Debug/DebugDataEntry.cs | 10 ++-- src/AsmResolver.PE/DotNet/DotNetDirectory.cs | 56 +++++++++---------- .../DotNet/Metadata/Tables/TablesStream.cs | 12 ++-- src/AsmResolver.PE/Exports/ExportDirectory.cs | 10 ++-- src/AsmResolver.PE/PEImage.cs | 40 ++++++------- src/AsmResolver.PE/Tls/TlsDirectory.cs | 8 +-- .../Win32Resources/ResourceData.cs | 8 +-- 10 files changed, 92 insertions(+), 92 deletions(-) diff --git a/src/AsmResolver.DotNet/Bundles/BundleFile.cs b/src/AsmResolver.DotNet/Bundles/BundleFile.cs index 958eeba16..4dcffc01c 100644 --- a/src/AsmResolver.DotNet/Bundles/BundleFile.cs +++ b/src/AsmResolver.DotNet/Bundles/BundleFile.cs @@ -11,7 +11,7 @@ namespace AsmResolver.DotNet.Bundles /// public class BundleFile : IOwnedCollectionElement { - private readonly LazyVariable _contents; + private readonly LazyVariable _contents; /// /// Creates a new empty bundle file. @@ -20,7 +20,7 @@ public class BundleFile : IOwnedCollectionElement public BundleFile(string relativePath) { RelativePath = relativePath; - _contents = new LazyVariable(GetContents); + _contents = new LazyVariable(x => x.GetContents()); } /// @@ -44,7 +44,7 @@ public BundleFile(string relativePath, BundleFileType type, ISegment contents) { RelativePath = relativePath; Type = type; - _contents = new LazyVariable(contents); + _contents = new LazyVariable(contents); } /// @@ -102,8 +102,8 @@ public bool IsCompressed /// public ISegment Contents { - get => _contents.Value; - set => _contents.Value = value; + get => _contents.GetValue(this); + set => _contents.SetValue(value); } /// diff --git a/src/AsmResolver.DotNet/Resources/ResourceSetEntry.cs b/src/AsmResolver.DotNet/Resources/ResourceSetEntry.cs index 8dab0efd0..d8be45eee 100644 --- a/src/AsmResolver.DotNet/Resources/ResourceSetEntry.cs +++ b/src/AsmResolver.DotNet/Resources/ResourceSetEntry.cs @@ -8,7 +8,7 @@ namespace AsmResolver.DotNet.Resources /// public class ResourceSetEntry { - private readonly LazyVariable _data; + private readonly LazyVariable _data; /// /// Creates a new empty resource set entry. @@ -19,7 +19,7 @@ public ResourceSetEntry(string name, ResourceTypeCode typeCode) { Name = name; Type = IntrinsicResourceType.Get(typeCode); - _data = new LazyVariable(GetData); + _data = new LazyVariable(x => x.GetData()); } /// @@ -31,7 +31,7 @@ public ResourceSetEntry(string name, ResourceType type) { Name = name; Type = type; - _data = new LazyVariable(GetData); + _data = new LazyVariable(x => x.GetData()); } /// @@ -44,7 +44,7 @@ public ResourceSetEntry(string name, ResourceTypeCode typeCode, object? data) { Name = name; Type = IntrinsicResourceType.Get(typeCode); - _data = new LazyVariable(data); + _data = new LazyVariable(data); } /// @@ -57,7 +57,7 @@ public ResourceSetEntry(string name, ResourceType type, object? data) { Name = name; Type = type; - _data = new LazyVariable(data); + _data = new LazyVariable(data); } /// @@ -81,8 +81,8 @@ public ResourceType Type /// public object? Data { - get => _data.Value; - set => _data.Value = value; + get => _data.GetValue(this); + set => _data.SetValue(value); } /// diff --git a/src/AsmResolver.PE.File/PEFile.cs b/src/AsmResolver.PE.File/PEFile.cs index d1483258b..09d15695b 100644 --- a/src/AsmResolver.PE.File/PEFile.cs +++ b/src/AsmResolver.PE.File/PEFile.cs @@ -20,8 +20,8 @@ public class PEFile : IPEFile /// public const uint ValidPESignature = 0x4550; // "PE\0\0" - private readonly LazyVariable _extraSectionData; - private readonly LazyVariable _eofData; + private readonly LazyVariable _extraSectionData; + private readonly LazyVariable _eofData; private IList? _sections; /// @@ -43,8 +43,8 @@ public PEFile(DosHeader dosHeader, FileHeader fileHeader, OptionalHeader optiona DosHeader = dosHeader ?? throw new ArgumentNullException(nameof(dosHeader)); FileHeader = fileHeader ?? throw new ArgumentNullException(nameof(fileHeader)); OptionalHeader = optionalHeader ?? throw new ArgumentNullException(nameof(optionalHeader)); - _extraSectionData = new LazyVariable(GetExtraSectionData); - _eofData = new LazyVariable(GetEofData); + _extraSectionData = new LazyVariable(x =>x.GetExtraSectionData()); + _eofData = new LazyVariable(x =>x.GetEofData()); MappingMode = PEMappingMode.Unmapped; } @@ -97,15 +97,15 @@ public PEMappingMode MappingMode /// public ISegment? ExtraSectionData { - get => _extraSectionData.Value; - set => _extraSectionData.Value = value; + get => _extraSectionData.GetValue(this); + set => _extraSectionData.SetValue(value); } /// public ISegment? EofData { - get => _eofData.Value; - set => _eofData.Value = value; + get => _eofData.GetValue(this); + set => _eofData.SetValue(value); } /// diff --git a/src/AsmResolver.PE/Debug/DebugDataEntry.cs b/src/AsmResolver.PE/Debug/DebugDataEntry.cs index 44cd67726..533948854 100644 --- a/src/AsmResolver.PE/Debug/DebugDataEntry.cs +++ b/src/AsmResolver.PE/Debug/DebugDataEntry.cs @@ -21,14 +21,14 @@ public class DebugDataEntry : SegmentBase + sizeof(uint) // PointerToRawData ; - private readonly LazyVariable _contents; + private readonly LazyVariable _contents; /// /// Initializes an empty instance. /// protected DebugDataEntry() { - _contents = new LazyVariable(GetContents); + _contents = new LazyVariable(x => x.GetContents()); } /// @@ -37,7 +37,7 @@ protected DebugDataEntry() /// The contents. public DebugDataEntry(IDebugDataSegment contents) { - _contents = new LazyVariable(contents); + _contents = new LazyVariable(contents); } /// @@ -81,8 +81,8 @@ public ushort MinorVersion /// public IDebugDataSegment? Contents { - get => _contents.Value; - set => _contents.Value = value; + get => _contents.GetValue(this); + set => _contents.SetValue(value); } /// diff --git a/src/AsmResolver.PE/DotNet/DotNetDirectory.cs b/src/AsmResolver.PE/DotNet/DotNetDirectory.cs index 6f4941cc7..f41bd379c 100644 --- a/src/AsmResolver.PE/DotNet/DotNetDirectory.cs +++ b/src/AsmResolver.PE/DotNet/DotNetDirectory.cs @@ -11,26 +11,26 @@ namespace AsmResolver.PE.DotNet /// public class DotNetDirectory : SegmentBase, IDotNetDirectory { - private readonly LazyVariable _metadata; - private readonly LazyVariable _resources; - private readonly LazyVariable _strongName; - private readonly LazyVariable _codeManagerTable; - private readonly LazyVariable _exportAddressTable; - private readonly LazyVariable _vtableFixups; - private readonly LazyVariable _managedNativeHeader; + private readonly LazyVariable _metadata; + private readonly LazyVariable _resources; + private readonly LazyVariable _strongName; + private readonly LazyVariable _codeManagerTable; + private readonly LazyVariable _exportAddressTable; + private readonly LazyVariable _vtableFixups; + private readonly LazyVariable _managedNativeHeader; /// /// Creates a new .NET data directory. /// public DotNetDirectory() { - _metadata = new LazyVariable(GetMetadata); - _resources = new LazyVariable(GetResources); - _strongName = new LazyVariable(GetStrongName); - _codeManagerTable = new LazyVariable(GetCodeManagerTable); - _exportAddressTable = new LazyVariable(GetExportAddressTable); - _vtableFixups = new LazyVariable(GetVTableFixups); - _managedNativeHeader = new LazyVariable(GetManagedNativeHeader); + _metadata = new LazyVariable(x => x.GetMetadata()); + _resources = new LazyVariable(x => x.GetResources()); + _strongName = new LazyVariable(x => x.GetStrongName()); + _codeManagerTable = new LazyVariable(x => x.GetCodeManagerTable()); + _exportAddressTable = new LazyVariable(x => x.GetExportAddressTable()); + _vtableFixups = new LazyVariable(x => x.GetVTableFixups()); + _managedNativeHeader = new LazyVariable(x => x.GetManagedNativeHeader()); } /// @@ -50,8 +50,8 @@ public ushort MinorRuntimeVersion /// public IMetadata? Metadata { - get => _metadata.Value; - set => _metadata.Value = value; + get => _metadata.GetValue(this); + set => _metadata.SetValue(value); } /// @@ -71,43 +71,43 @@ public DotNetEntryPoint EntryPoint /// public DotNetResourcesDirectory? DotNetResources { - get => _resources.Value; - set => _resources.Value = value; + get => _resources.GetValue(this); + set => _resources.SetValue(value); } /// public IReadableSegment? StrongName { - get => _strongName.Value; - set => _strongName.Value = value; + get => _strongName.GetValue(this); + set => _strongName.SetValue(value); } /// public IReadableSegment? CodeManagerTable { - get => _codeManagerTable.Value; - set => _codeManagerTable.Value = value; + get => _codeManagerTable.GetValue(this); + set => _codeManagerTable.SetValue(value); } /// public VTableFixupsDirectory? VTableFixups { - get => _vtableFixups.Value; - set => _vtableFixups.Value = value; + get => _vtableFixups.GetValue(this); + set => _vtableFixups.SetValue(value); } /// public IReadableSegment? ExportAddressTable { - get => _exportAddressTable.Value; - set => _exportAddressTable.Value = value; + get => _exportAddressTable.GetValue(this); + set => _exportAddressTable.SetValue(value); } /// public IReadableSegment? ManagedNativeHeader { - get => _managedNativeHeader.Value; - set => _managedNativeHeader.Value = value; + get => _managedNativeHeader.GetValue(this); + set => _managedNativeHeader.SetValue(value); } /// diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/TablesStream.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/TablesStream.cs index 67efc4806..d12f5ed78 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/TablesStream.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/TablesStream.cs @@ -33,16 +33,16 @@ public partial class TablesStream : SegmentBase, IMetadataStream public const string UncompressedStreamName = "#Schema"; private readonly Dictionary _indexEncoders; - private readonly LazyVariable> _tables; - private readonly LazyVariable> _layouts; + private readonly LazyVariable> _tables; + private readonly LazyVariable> _layouts; /// /// Creates a new, empty tables stream. /// public TablesStream() { - _layouts = new LazyVariable>(GetTableLayouts); - _tables = new LazyVariable>(GetTables); + _layouts = new LazyVariable>(x => x.GetTableLayouts()); + _tables = new LazyVariable>(x => x.GetTables()); _indexEncoders = CreateIndexEncoders(); } @@ -223,12 +223,12 @@ public uint[]? ExternalRowCounts /// This collection always contains all tables, in the same order as defines, regardless /// of whether a table actually has elements or not. /// - protected IList Tables => _tables.Value; + protected IList Tables => _tables.GetValue(this); /// /// Gets the layout of all tables in the stream. /// - protected IList TableLayouts => _layouts.Value; + protected IList TableLayouts => _layouts.GetValue(this); /// public virtual BinaryStreamReader CreateReader() => throw new NotSupportedException(); diff --git a/src/AsmResolver.PE/Exports/ExportDirectory.cs b/src/AsmResolver.PE/Exports/ExportDirectory.cs index 5f983b233..e19649ee1 100644 --- a/src/AsmResolver.PE/Exports/ExportDirectory.cs +++ b/src/AsmResolver.PE/Exports/ExportDirectory.cs @@ -10,7 +10,7 @@ namespace AsmResolver.PE.Exports /// public class ExportDirectory : IExportDirectory { - private readonly LazyVariable _name; + private readonly LazyVariable _name; private IList? _exports; /// @@ -18,7 +18,7 @@ public class ExportDirectory : IExportDirectory /// protected ExportDirectory() { - _name = new LazyVariable(GetName); + _name = new LazyVariable(x => x.GetName()); } /// @@ -27,7 +27,7 @@ protected ExportDirectory() /// The name of the library exporting the symbols. public ExportDirectory(string name) { - _name = new LazyVariable(name ?? throw new ArgumentNullException(nameof(name))); + _name = new LazyVariable(name ?? throw new ArgumentNullException(nameof(name))); } /// @@ -61,8 +61,8 @@ public ushort MinorVersion /// public string? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// diff --git a/src/AsmResolver.PE/PEImage.cs b/src/AsmResolver.PE/PEImage.cs index f1e61fbad..7849e172f 100644 --- a/src/AsmResolver.PE/PEImage.cs +++ b/src/AsmResolver.PE/PEImage.cs @@ -21,13 +21,13 @@ namespace AsmResolver.PE public class PEImage : IPEImage { private IList? _imports; - private readonly LazyVariable _exports; - private readonly LazyVariable _resources; - private readonly LazyVariable _exceptions; + private readonly LazyVariable _exports; + private readonly LazyVariable _resources; + private readonly LazyVariable _exceptions; private IList? _relocations; - private readonly LazyVariable _dotNetDirectory; + private readonly LazyVariable _dotNetDirectory; private IList? _debugData; - private readonly LazyVariable _tlsDirectory; + private readonly LazyVariable _tlsDirectory; /// /// Opens a PE image from a specific file on the disk. @@ -169,11 +169,11 @@ public static IPEImage FromFile(IPEFile peFile, PEReaderParameters readerParamet /// public PEImage() { - _exports = new LazyVariable(GetExports); - _resources = new LazyVariable(GetResources); - _exceptions = new LazyVariable(GetExceptions); - _dotNetDirectory = new LazyVariable(GetDotNetDirectory); - _tlsDirectory = new LazyVariable(GetTlsDirectory); + _exports = new LazyVariable(x => x.GetExports()); + _resources = new LazyVariable(x => x.GetResources()); + _exceptions = new LazyVariable(x => x.GetExceptions()); + _dotNetDirectory = new LazyVariable(x => x.GetDotNetDirectory()); + _tlsDirectory = new LazyVariable(x => x.GetTlsDirectory()); } /// @@ -247,22 +247,22 @@ public IList Imports /// public IExportDirectory? Exports { - get => _exports.Value; - set => _exports.Value = value; + get => _exports.GetValue(this); + set => _exports.SetValue(value); } /// public IResourceDirectory? Resources { - get => _resources.Value; - set => _resources.Value = value; + get => _resources.GetValue(this); + set => _resources.SetValue(value); } /// public IExceptionDirectory? Exceptions { - get => _exceptions.Value; - set => _exceptions.Value = value; + get => _exceptions.GetValue(this); + set => _exceptions.SetValue(value); } /// @@ -279,8 +279,8 @@ public IList Relocations /// public IDotNetDirectory? DotNetDirectory { - get => _dotNetDirectory.Value; - set => _dotNetDirectory.Value = value; + get => _dotNetDirectory.GetValue(this); + set => _dotNetDirectory.SetValue(value); } /// @@ -297,8 +297,8 @@ public IList DebugData /// public ITlsDirectory? TlsDirectory { - get => _tlsDirectory.Value; - set => _tlsDirectory.Value = value; + get => _tlsDirectory.GetValue(this); + set => _tlsDirectory.SetValue(value); } /// diff --git a/src/AsmResolver.PE/Tls/TlsDirectory.cs b/src/AsmResolver.PE/Tls/TlsDirectory.cs index af563f6d7..6f231fd23 100644 --- a/src/AsmResolver.PE/Tls/TlsDirectory.cs +++ b/src/AsmResolver.PE/Tls/TlsDirectory.cs @@ -10,7 +10,7 @@ namespace AsmResolver.PE.Tls /// public class TlsDirectory : SegmentBase, ITlsDirectory { - private readonly LazyVariable _templateData; + private readonly LazyVariable _templateData; private TlsCallbackCollection? _callbackFunctions; private ulong _imageBase = 0x00400000; private bool _is32Bit = true; @@ -20,15 +20,15 @@ public class TlsDirectory : SegmentBase, ITlsDirectory /// public TlsDirectory() { - _templateData = new LazyVariable(GetTemplateData); + _templateData = new LazyVariable(x => x.GetTemplateData()); Index = SegmentReference.Null; } /// public IReadableSegment? TemplateData { - get => _templateData.Value; - set => _templateData.Value = value; + get => _templateData.GetValue(this); + set => _templateData.SetValue(value); } /// diff --git a/src/AsmResolver.PE/Win32Resources/ResourceData.cs b/src/AsmResolver.PE/Win32Resources/ResourceData.cs index 94a9337ca..c6659539d 100644 --- a/src/AsmResolver.PE/Win32Resources/ResourceData.cs +++ b/src/AsmResolver.PE/Win32Resources/ResourceData.cs @@ -9,14 +9,14 @@ namespace AsmResolver.PE.Win32Resources /// public class ResourceData : IResourceData { - private readonly LazyVariable _contents; + private readonly LazyVariable _contents; /// /// Initializes a new resource data entry. /// protected ResourceData() { - _contents = new LazyVariable(GetContents); + _contents = new LazyVariable(x => x.GetContents()); } /// @@ -79,8 +79,8 @@ public uint Id /// public ISegment? Contents { - get => _contents.Value; - set => _contents.Value = value; + get => _contents.GetValue(this); + set => _contents.SetValue(value); } /// From 89f934b129313fe7fd1b3f064adb8bb36eed7500 Mon Sep 17 00:00:00 2001 From: Washi Date: Thu, 20 Apr 2023 19:03:33 +0200 Subject: [PATCH 3/3] Migrate Pdb to new lazyvar. --- .../Leaves/ArrayTypeRecord.cs | 36 ++++++++--------- .../Leaves/BaseClassField.cs | 10 ++--- .../Leaves/BitFieldTypeRecord.cs | 10 ++--- .../Leaves/ClassTypeRecord.cs | 20 +++++----- .../Leaves/CodeViewCompositeTypeRecord.cs | 16 ++++---- .../Leaves/CodeViewDataField.cs | 10 ++--- .../Leaves/CodeViewDerivedTypeRecord.cs | 8 ++-- .../Leaves/CodeViewNamedField.cs | 8 ++-- .../Leaves/EnumerateField.cs | 10 ++--- .../Leaves/FunctionIdentifier.cs | 20 +++++----- .../Leaves/MemberFunctionLeaf.cs | 40 +++++++++---------- .../Leaves/MethodListEntry.cs | 12 +++--- .../Leaves/ModifierTypeRecord.cs | 10 ++--- .../Leaves/NestedTypeField.cs | 12 +++--- .../Leaves/NonOverloadedMethod.cs | 12 +++--- .../Leaves/OverloadedMethod.cs | 14 +++---- .../Leaves/PointerTypeRecord.cs | 12 +++--- .../Leaves/ProcedureTypeRecord.cs | 20 +++++----- .../Leaves/StringIdentifier.cs | 20 +++++----- .../Leaves/UnionTypeRecord.cs | 10 ++--- .../Leaves/VBaseClassField.cs | 20 +++++----- .../Leaves/VTableField.cs | 10 ++--- .../Metadata/Dbi/DbiStream.cs | 16 ++++---- .../Metadata/Modi/ModiStream.cs | 32 +++++++-------- src/AsmResolver.Symbols.Pdb/PdbModule.cs | 30 +++++++------- .../Records/BasePointerRelativeSymbol.cs | 20 +++++----- .../Records/BuildInfoSymbol.cs | 10 ++--- .../Records/CallSiteSymbol.cs | 10 ++--- .../Records/CoffGroupSymbol.cs | 10 ++--- .../Records/CompileSymbol.cs | 8 ++-- .../Records/ConstantSymbol.cs | 20 +++++----- .../Records/DataSymbol.cs | 20 +++++----- .../Records/FileStaticSymbol.cs | 20 +++++----- .../Records/InlineSiteSymbol.cs | 10 ++--- .../Records/LabelSymbol.cs | 10 ++--- .../Records/LocalSymbol.cs | 20 +++++----- .../Records/ObjectNameSymbol.cs | 10 ++--- .../Records/ProcedureReferenceSymbol.cs | 20 ++++------ .../Records/ProcedureSymbol.cs | 24 +++++------ .../Records/PublicSymbol.cs | 10 ++--- .../Records/RegisterRelativeSymbol.cs | 20 +++++----- .../Records/RegisterSymbol.cs | 20 +++++----- .../Records/SectionSymbol.cs | 10 ++--- .../Records/ThunkSymbol.cs | 10 ++--- .../Records/UserDefinedTypeSymbol.cs | 20 +++++----- .../Records/UsingNamespaceSymbol.cs | 10 ++--- src/AsmResolver/LazyVariable.cs | 21 ++++++++-- 47 files changed, 381 insertions(+), 370 deletions(-) diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/ArrayTypeRecord.cs b/src/AsmResolver.Symbols.Pdb/Leaves/ArrayTypeRecord.cs index 1f53f2071..61ec5bff5 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/ArrayTypeRecord.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/ArrayTypeRecord.cs @@ -5,9 +5,9 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class ArrayTypeRecord : CodeViewTypeRecord { - private readonly LazyVariable _elementType; - private readonly LazyVariable _indexType; - private readonly LazyVariable _name; + private readonly LazyVariable _elementType; + private readonly LazyVariable _indexType; + private readonly LazyVariable _name; /// /// Initializes a new empty array type. @@ -16,9 +16,9 @@ public class ArrayTypeRecord : CodeViewTypeRecord protected ArrayTypeRecord(uint typeIndex) : base(typeIndex) { - _elementType = new LazyVariable(GetElementType); - _indexType = new LazyVariable(GetIndexType); - _name = new LazyVariable(GetName); + _elementType = new LazyVariable(x => x.GetElementType()); + _indexType = new LazyVariable(x => x.GetIndexType()); + _name = new LazyVariable(x => x.GetName()); } /// @@ -30,10 +30,10 @@ protected ArrayTypeRecord(uint typeIndex) public ArrayTypeRecord(CodeViewTypeRecord elementType, CodeViewTypeRecord indexType, ulong length) : base(0) { - _elementType = new LazyVariable(elementType); - _indexType = new LazyVariable(indexType); + _elementType = new LazyVariable(elementType); + _indexType = new LazyVariable(indexType); + _name = new LazyVariable(Utf8String.Empty); Length = length; - _name = new LazyVariable(Utf8String.Empty); } /// @@ -46,10 +46,10 @@ public ArrayTypeRecord(CodeViewTypeRecord elementType, CodeViewTypeRecord indexT public ArrayTypeRecord(CodeViewTypeRecord elementType, CodeViewTypeRecord indexType, ulong length, Utf8String name) : base(0) { - _elementType = new LazyVariable(elementType); - _indexType = new LazyVariable(indexType); + _elementType = new LazyVariable(elementType); + _indexType = new LazyVariable(indexType); + _name = new LazyVariable(name); Length = length; - _name = new LazyVariable(Name); } /// @@ -60,8 +60,8 @@ public ArrayTypeRecord(CodeViewTypeRecord elementType, CodeViewTypeRecord indexT /// public CodeViewTypeRecord? ElementType { - get => _elementType.Value; - set => _elementType.Value = value; + get => _elementType.GetValue(this); + set => _elementType.SetValue(value); } /// @@ -69,8 +69,8 @@ public CodeViewTypeRecord? ElementType /// public CodeViewTypeRecord? IndexType { - get => _indexType.Value; - set => _indexType.Value = value; + get => _indexType.GetValue(this); + set => _indexType.SetValue(value); } /// @@ -87,8 +87,8 @@ public ulong Length /// public Utf8String Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/BaseClassField.cs b/src/AsmResolver.Symbols.Pdb/Leaves/BaseClassField.cs index 3a3823945..c47a47fce 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/BaseClassField.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/BaseClassField.cs @@ -5,7 +5,7 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class BaseClassField : CodeViewField { - private readonly LazyVariable _type; + private readonly LazyVariable _type; /// /// Initializes an empty base class. @@ -14,7 +14,7 @@ public class BaseClassField : CodeViewField protected BaseClassField(uint typeIndex) : base(typeIndex) { - _type = new LazyVariable(GetBaseType); + _type = new LazyVariable(x => x.GetBaseType()); } /// @@ -24,7 +24,7 @@ protected BaseClassField(uint typeIndex) public BaseClassField(CodeViewTypeRecord type) : base(0) { - _type = new LazyVariable(type); + _type = new LazyVariable(type); } /// @@ -35,8 +35,8 @@ public BaseClassField(CodeViewTypeRecord type) /// public CodeViewTypeRecord? Type { - get => _type.Value; - set => _type.Value = value; + get => _type.GetValue(this); + set => _type.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/BitFieldTypeRecord.cs b/src/AsmResolver.Symbols.Pdb/Leaves/BitFieldTypeRecord.cs index 40a01fbb5..9c93991a2 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/BitFieldTypeRecord.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/BitFieldTypeRecord.cs @@ -5,7 +5,7 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class BitFieldTypeRecord : CodeViewTypeRecord { - private readonly LazyVariable _type; + private readonly LazyVariable _type; /// /// Initializes an empty bit field record. @@ -14,7 +14,7 @@ public class BitFieldTypeRecord : CodeViewTypeRecord protected BitFieldTypeRecord(uint typeIndex) : base(typeIndex) { - _type = new LazyVariable(GetBaseType); + _type = new LazyVariable(x => x.GetBaseType()); } /// @@ -26,7 +26,7 @@ protected BitFieldTypeRecord(uint typeIndex) public BitFieldTypeRecord(CodeViewTypeRecord type, byte position, byte length) : base(0) { - _type = new LazyVariable(type); + _type = new LazyVariable(type); Position = position; Length = length; } @@ -39,8 +39,8 @@ public BitFieldTypeRecord(CodeViewTypeRecord type, byte position, byte length) /// public CodeViewTypeRecord? Type { - get => _type.Value; - set => _type.Value = value; + get => _type.GetValue(this); + set => _type.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/ClassTypeRecord.cs b/src/AsmResolver.Symbols.Pdb/Leaves/ClassTypeRecord.cs index 3f222effc..faf4aecf7 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/ClassTypeRecord.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/ClassTypeRecord.cs @@ -7,8 +7,8 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class ClassTypeRecord : CodeViewDerivedTypeRecord { - private readonly LazyVariable _uniqueName; - private readonly LazyVariable _vtableShape; + private readonly LazyVariable _uniqueName; + private readonly LazyVariable _vtableShape; /// /// Initializes an empty class type. @@ -25,8 +25,8 @@ protected ClassTypeRecord(CodeViewLeafKind kind, uint typeIndex) throw new ArgumentOutOfRangeException(nameof(kind)); LeafKind = kind; - _uniqueName = new LazyVariable(GetUniqueName); - _vtableShape = new LazyVariable(GetVTableShape); + _uniqueName = new LazyVariable(x => x.GetUniqueName()); + _vtableShape = new LazyVariable(x => x.GetVTableShape()); } /// @@ -50,8 +50,8 @@ public ClassTypeRecord(CodeViewLeafKind kind, Utf8String name, Utf8String unique LeafKind = kind; Name = name; - _uniqueName = new LazyVariable(uniqueName); - _vtableShape = new LazyVariable(default(VTableShapeLeaf)); + _uniqueName = new LazyVariable(uniqueName); + _vtableShape = new LazyVariable(default(VTableShapeLeaf)); Size = size; StructureAttributes = attributes; BaseType = baseType; @@ -77,8 +77,8 @@ public ulong Size /// public Utf8String UniqueName { - get => _uniqueName.Value; - set => _uniqueName.Value = value; + get => _uniqueName.GetValue(this); + set => _uniqueName.SetValue(value); } /// @@ -86,8 +86,8 @@ public Utf8String UniqueName /// public VTableShapeLeaf? VTableShape { - get => _vtableShape.Value; - set => _vtableShape.Value = value; + get => _vtableShape.GetValue(this); + set => _vtableShape.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/CodeViewCompositeTypeRecord.cs b/src/AsmResolver.Symbols.Pdb/Leaves/CodeViewCompositeTypeRecord.cs index 9abc46710..b71238178 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/CodeViewCompositeTypeRecord.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/CodeViewCompositeTypeRecord.cs @@ -5,8 +5,8 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public abstract class CodeViewCompositeTypeRecord : CodeViewTypeRecord { - private readonly LazyVariable _name; - private readonly LazyVariable _fields; + private readonly LazyVariable _name; + private readonly LazyVariable _fields; /// /// Initializes a new empty composite type. @@ -15,8 +15,8 @@ public abstract class CodeViewCompositeTypeRecord : CodeViewTypeRecord protected CodeViewCompositeTypeRecord(uint typeIndex) : base(typeIndex) { - _name = new LazyVariable(GetName); - _fields = new LazyVariable(GetFields); + _name = new LazyVariable(x => x.GetName()); + _fields = new LazyVariable(x => x.GetFields()); } /// @@ -33,8 +33,8 @@ public StructureAttributes StructureAttributes /// public Utf8String Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// @@ -42,8 +42,8 @@ public Utf8String Name /// public FieldListLeaf? Fields { - get => _fields.Value; - set => _fields.Value = value; + get => _fields.GetValue(this); + set => _fields.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/CodeViewDataField.cs b/src/AsmResolver.Symbols.Pdb/Leaves/CodeViewDataField.cs index 3821a14fe..64a0edeb9 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/CodeViewDataField.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/CodeViewDataField.cs @@ -5,7 +5,7 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public abstract class CodeViewDataField : CodeViewNamedField { - private readonly LazyVariable _dataType; + private readonly LazyVariable _dataType; /// /// Initializes an empty instance data member. @@ -14,7 +14,7 @@ public abstract class CodeViewDataField : CodeViewNamedField protected CodeViewDataField(uint typeIndex) : base(typeIndex) { - _dataType = new LazyVariable(GetDataType); + _dataType = new LazyVariable(x => x.GetDataType()); } /// @@ -25,7 +25,7 @@ protected CodeViewDataField(uint typeIndex) protected CodeViewDataField(CodeViewTypeRecord dataType, Utf8String name) : base(0) { - _dataType = new LazyVariable(dataType); + _dataType = new LazyVariable(dataType); Name = name; } @@ -34,8 +34,8 @@ protected CodeViewDataField(CodeViewTypeRecord dataType, Utf8String name) /// public CodeViewTypeRecord DataType { - get => _dataType.Value; - set => _dataType.Value = value; + get => _dataType.GetValue(this); + set => _dataType.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/CodeViewDerivedTypeRecord.cs b/src/AsmResolver.Symbols.Pdb/Leaves/CodeViewDerivedTypeRecord.cs index 3cd51d0f8..fd4b7f068 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/CodeViewDerivedTypeRecord.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/CodeViewDerivedTypeRecord.cs @@ -5,13 +5,13 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public abstract class CodeViewDerivedTypeRecord : CodeViewCompositeTypeRecord { - private readonly LazyVariable _baseType; + private readonly LazyVariable _baseType; /// protected CodeViewDerivedTypeRecord(uint typeIndex) : base(typeIndex) { - _baseType = new LazyVariable(GetBaseType); + _baseType = new LazyVariable(x => x.GetBaseType()); } /// @@ -19,8 +19,8 @@ protected CodeViewDerivedTypeRecord(uint typeIndex) /// public CodeViewTypeRecord? BaseType { - get => _baseType.Value; - set => _baseType.Value = value; + get => _baseType.GetValue(this); + set => _baseType.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/CodeViewNamedField.cs b/src/AsmResolver.Symbols.Pdb/Leaves/CodeViewNamedField.cs index 3137dabde..1b8e72fe2 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/CodeViewNamedField.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/CodeViewNamedField.cs @@ -5,7 +5,7 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public abstract class CodeViewNamedField : CodeViewField { - private readonly LazyVariable _name; + private readonly LazyVariable _name; /// /// Initializes an empty CodeView field leaf. @@ -14,7 +14,7 @@ public abstract class CodeViewNamedField : CodeViewField protected CodeViewNamedField(uint typeIndex) : base(typeIndex) { - _name = new LazyVariable(GetName); + _name = new LazyVariable(x => x.GetName()); } /// @@ -22,8 +22,8 @@ protected CodeViewNamedField(uint typeIndex) /// public Utf8String Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/EnumerateField.cs b/src/AsmResolver.Symbols.Pdb/Leaves/EnumerateField.cs index 4fe1a97c9..27538f17b 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/EnumerateField.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/EnumerateField.cs @@ -5,7 +5,7 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class EnumerateField : CodeViewNamedField { - private readonly LazyVariable _value; + private readonly LazyVariable _value; /// /// Initializes an empty enumerate field leaf. @@ -14,7 +14,7 @@ public class EnumerateField : CodeViewNamedField protected EnumerateField(uint typeIndex) : base(typeIndex) { - _value = new LazyVariable(GetValue); + _value = new LazyVariable(x => x.GetValue()); } /// @@ -27,7 +27,7 @@ public EnumerateField(Utf8String name, object value, CodeViewFieldAttributes att : base(0) { Name = name; - _value = new LazyVariable(value); + _value = new LazyVariable(value); Attributes = attributes; } @@ -39,8 +39,8 @@ public EnumerateField(Utf8String name, object value, CodeViewFieldAttributes att /// public object Value { - get => _value.Value; - set => _value.Value = value; + get => _value.GetValue(this); + set => _value.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/FunctionIdentifier.cs b/src/AsmResolver.Symbols.Pdb/Leaves/FunctionIdentifier.cs index 326194b14..3c3dc7ae4 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/FunctionIdentifier.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/FunctionIdentifier.cs @@ -5,8 +5,8 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class FunctionIdentifier : CodeViewLeaf, IIpiLeaf { - private readonly LazyVariable _name; - private readonly LazyVariable _functionType; + private readonly LazyVariable _name; + private readonly LazyVariable _functionType; /// /// Initializes an empty function identifier leaf. @@ -15,8 +15,8 @@ public class FunctionIdentifier : CodeViewLeaf, IIpiLeaf protected FunctionIdentifier(uint typeIndex) : base(typeIndex) { - _name = new LazyVariable(GetName); - _functionType = new LazyVariable(GetFunctionType); + _name = new LazyVariable(x => x.GetName()); + _functionType = new LazyVariable(x => x.GetFunctionType()); } /// @@ -29,8 +29,8 @@ public FunctionIdentifier(uint scopeId, Utf8String name, CodeViewTypeRecord func : base(0) { ScopeId = scopeId; - _name = new LazyVariable(name); - _functionType = new LazyVariable(functionType); + _name = new LazyVariable(name); + _functionType = new LazyVariable(functionType); } /// @@ -50,8 +50,8 @@ public uint ScopeId /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// @@ -59,8 +59,8 @@ public Utf8String? Name /// public CodeViewTypeRecord? FunctionType { - get => _functionType.Value; - set => _functionType.Value = value; + get => _functionType.GetValue(this); + set => _functionType.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/MemberFunctionLeaf.cs b/src/AsmResolver.Symbols.Pdb/Leaves/MemberFunctionLeaf.cs index 08fc5adcd..7618d3aaa 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/MemberFunctionLeaf.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/MemberFunctionLeaf.cs @@ -7,10 +7,10 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class MemberFunctionLeaf : CodeViewLeaf, ITpiLeaf { - private readonly LazyVariable _returnType; - private readonly LazyVariable _declaringType; - private readonly LazyVariable _thisType; - private readonly LazyVariable _argumentList; + private readonly LazyVariable _returnType; + private readonly LazyVariable _declaringType; + private readonly LazyVariable _thisType; + private readonly LazyVariable _argumentList; /// /// Initializes an empty member function. @@ -19,10 +19,10 @@ public class MemberFunctionLeaf : CodeViewLeaf, ITpiLeaf protected MemberFunctionLeaf(uint typeIndex) : base(typeIndex) { - _returnType = new LazyVariable(GetReturnType); - _declaringType = new LazyVariable(GetDeclaringType); - _thisType = new LazyVariable(GetThisType); - _argumentList = new LazyVariable(GetArguments); + _returnType = new LazyVariable(x => x.GetReturnType()); + _declaringType = new LazyVariable(x => x.GetDeclaringType()); + _thisType = new LazyVariable(x => x.GetThisType()); + _argumentList = new LazyVariable(x => x.GetArguments()); } /// @@ -34,10 +34,10 @@ protected MemberFunctionLeaf(uint typeIndex) public MemberFunctionLeaf(CodeViewTypeRecord returnType, CodeViewTypeRecord declaringType, ArgumentListLeaf arguments) : base(0) { - _returnType = new LazyVariable(returnType); - _declaringType = new LazyVariable(declaringType); - _thisType = new LazyVariable(default(CodeViewTypeRecord)); - _argumentList = new LazyVariable(arguments); + _returnType = new LazyVariable(returnType); + _declaringType = new LazyVariable(declaringType); + _thisType = new LazyVariable(default(CodeViewTypeRecord)); + _argumentList = new LazyVariable(arguments); CallingConvention = CodeViewCallingConvention.NearC; Attributes = 0; ThisAdjuster = 0; @@ -51,8 +51,8 @@ public MemberFunctionLeaf(CodeViewTypeRecord returnType, CodeViewTypeRecord decl /// public CodeViewTypeRecord? ReturnType { - get => _returnType.Value; - set => _returnType.Value = value; + get => _returnType.GetValue(this); + set => _returnType.SetValue(value); } /// @@ -60,8 +60,8 @@ public CodeViewTypeRecord? ReturnType /// public CodeViewTypeRecord? DeclaringType { - get => _declaringType.Value; - set => _declaringType.Value = value; + get => _declaringType.GetValue(this); + set => _declaringType.SetValue(value); } /// @@ -69,8 +69,8 @@ public CodeViewTypeRecord? DeclaringType /// public CodeViewTypeRecord? ThisType { - get => _thisType.Value; - set => _thisType.Value = value; + get => _thisType.GetValue(this); + set => _thisType.SetValue(value); } /// @@ -96,8 +96,8 @@ public MemberFunctionAttributes Attributes /// public ArgumentListLeaf? Arguments { - get => _argumentList.Value; - set => _argumentList.Value = value; + get => _argumentList.GetValue(this); + set => _argumentList.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/MethodListEntry.cs b/src/AsmResolver.Symbols.Pdb/Leaves/MethodListEntry.cs index 447296798..83b4aa210 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/MethodListEntry.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/MethodListEntry.cs @@ -5,14 +5,14 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class MethodListEntry { - private readonly LazyVariable _function; + private readonly LazyVariable _function; /// /// Initializes an empty method list entry. /// protected MethodListEntry() { - _function = new LazyVariable(GetFunction); + _function = new LazyVariable(x => x.GetFunction()); } /// @@ -23,7 +23,7 @@ protected MethodListEntry() public MethodListEntry(CodeViewFieldAttributes attributes, MemberFunctionLeaf function) { Attributes = attributes; - _function = new LazyVariable(function); + _function = new LazyVariable(function); VTableOffset = 0; } @@ -36,7 +36,7 @@ public MethodListEntry(CodeViewFieldAttributes attributes, MemberFunctionLeaf fu public MethodListEntry(CodeViewFieldAttributes attributes, MemberFunctionLeaf function, uint vTableOffset) { Attributes = attributes; - _function = new LazyVariable(function); + _function = new LazyVariable(function); VTableOffset = vTableOffset; } @@ -54,8 +54,8 @@ public CodeViewFieldAttributes Attributes /// public MemberFunctionLeaf? Function { - get => _function.Value; - set => _function.Value = value; + get => _function.GetValue(this); + set => _function.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/ModifierTypeRecord.cs b/src/AsmResolver.Symbols.Pdb/Leaves/ModifierTypeRecord.cs index c70e50ed1..cb121c474 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/ModifierTypeRecord.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/ModifierTypeRecord.cs @@ -5,7 +5,7 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class ModifierTypeRecord : CodeViewTypeRecord { - private readonly LazyVariable _baseType; + private readonly LazyVariable _baseType; /// /// Initializes a new empty modifier type. @@ -14,7 +14,7 @@ public class ModifierTypeRecord : CodeViewTypeRecord protected ModifierTypeRecord(uint typeIndex) : base(typeIndex) { - _baseType = new LazyVariable(GetBaseType); + _baseType = new LazyVariable(x => x.GetBaseType()); } /// @@ -25,7 +25,7 @@ protected ModifierTypeRecord(uint typeIndex) public ModifierTypeRecord(CodeViewTypeRecord type, ModifierAttributes attributes) : base(0) { - _baseType = new LazyVariable(type); + _baseType = new LazyVariable(type); Attributes = attributes; } @@ -37,8 +37,8 @@ public ModifierTypeRecord(CodeViewTypeRecord type, ModifierAttributes attributes /// public CodeViewTypeRecord BaseType { - get => _baseType.Value; - set => _baseType.Value = value; + get => _baseType.GetValue(this); + set => _baseType.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/NestedTypeField.cs b/src/AsmResolver.Symbols.Pdb/Leaves/NestedTypeField.cs index 91bca6ee3..e240cada7 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/NestedTypeField.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/NestedTypeField.cs @@ -5,7 +5,7 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class NestedTypeField : CodeViewNamedField { - private readonly LazyVariable _type; + private readonly LazyVariable _type; /// /// Initializes an empty nested type. @@ -14,7 +14,7 @@ public class NestedTypeField : CodeViewNamedField protected NestedTypeField(uint typeIndex) : base(typeIndex) { - _type = new LazyVariable(GetNestedType); + _type = new LazyVariable(x => x.GetNestedType()); } /// @@ -25,7 +25,7 @@ protected NestedTypeField(uint typeIndex) public NestedTypeField(CodeViewTypeRecord type, Utf8String name) : base(0) { - _type = new LazyVariable(type); + _type = new LazyVariable(type); Name = name; Attributes = 0; } @@ -39,7 +39,7 @@ public NestedTypeField(CodeViewTypeRecord type, Utf8String name) public NestedTypeField(CodeViewTypeRecord type, Utf8String name, CodeViewFieldAttributes attributes) : base(0) { - _type = new LazyVariable(type); + _type = new LazyVariable(type); Name = name; Attributes = attributes; } @@ -54,8 +54,8 @@ public NestedTypeField(CodeViewTypeRecord type, Utf8String name, CodeViewFieldAt /// public CodeViewTypeRecord? Type { - get => _type.Value; - set => _type.Value = value; + get => _type.GetValue(this); + set => _type.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/NonOverloadedMethod.cs b/src/AsmResolver.Symbols.Pdb/Leaves/NonOverloadedMethod.cs index 08bdb113f..65afaa7c4 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/NonOverloadedMethod.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/NonOverloadedMethod.cs @@ -5,7 +5,7 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class NonOverloadedMethod : CodeViewNamedField { - private readonly LazyVariable _function; + private readonly LazyVariable _function; /// /// Initializes an empty non-overloaded method. @@ -14,7 +14,7 @@ public class NonOverloadedMethod : CodeViewNamedField protected NonOverloadedMethod(uint typeIndex) : base(typeIndex) { - _function = new LazyVariable(GetFunction); + _function = new LazyVariable(x => x.GetFunction()); } /// @@ -26,7 +26,7 @@ protected NonOverloadedMethod(uint typeIndex) public NonOverloadedMethod(Utf8String name, CodeViewFieldAttributes attributes, MemberFunctionLeaf function) : base(0) { - _function = new LazyVariable(function); + _function = new LazyVariable(function); Attributes = attributes; Name = name; } @@ -41,7 +41,7 @@ public NonOverloadedMethod(Utf8String name, CodeViewFieldAttributes attributes, public NonOverloadedMethod(Utf8String name, CodeViewFieldAttributes attributes, uint vTableOffset, MemberFunctionLeaf function) : base(0) { - _function = new LazyVariable(function); + _function = new LazyVariable(function); Attributes = attributes; Name = name; VTableOffset = vTableOffset; @@ -55,8 +55,8 @@ public NonOverloadedMethod(Utf8String name, CodeViewFieldAttributes attributes, /// public MemberFunctionLeaf? Function { - get => _function.Value; - set => _function.Value = value; + get => _function.GetValue(this); + set => _function.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/OverloadedMethod.cs b/src/AsmResolver.Symbols.Pdb/Leaves/OverloadedMethod.cs index a6c17cea0..ed5e4e50e 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/OverloadedMethod.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/OverloadedMethod.cs @@ -5,7 +5,7 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class OverloadedMethod : CodeViewNamedField { - private readonly LazyVariable _methods; + private readonly LazyVariable _methods; /// /// Initializes an empty overloaded method. @@ -14,7 +14,7 @@ public class OverloadedMethod : CodeViewNamedField protected OverloadedMethod(uint typeIndex) : base(typeIndex) { - _methods = new LazyVariable(GetMethods); + _methods = new LazyVariable(x => x.GetMethods()); } /// @@ -23,7 +23,7 @@ protected OverloadedMethod(uint typeIndex) public OverloadedMethod() : base(0) { - _methods = new LazyVariable(new MethodListLeaf()); + _methods = new LazyVariable(new MethodListLeaf()); } /// @@ -32,7 +32,7 @@ public OverloadedMethod() public OverloadedMethod(MethodListLeaf methods) : base(0) { - _methods = new LazyVariable(methods); + _methods = new LazyVariable(methods); } /// @@ -41,7 +41,7 @@ public OverloadedMethod(MethodListLeaf methods) public OverloadedMethod(params MethodListEntry[] methods) : base(0) { - _methods = new LazyVariable(new MethodListLeaf(methods)); + _methods = new LazyVariable(new MethodListLeaf(methods)); } /// @@ -52,8 +52,8 @@ public OverloadedMethod(params MethodListEntry[] methods) /// public MethodListLeaf? Methods { - get => _methods.Value; - set => _methods.Value = value; + get => _methods.GetValue(this); + set => _methods.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/PointerTypeRecord.cs b/src/AsmResolver.Symbols.Pdb/Leaves/PointerTypeRecord.cs index 740e792cd..dc77efcb9 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/PointerTypeRecord.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/PointerTypeRecord.cs @@ -5,7 +5,7 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class PointerTypeRecord : CodeViewTypeRecord { - private readonly LazyVariable _baseType; + private readonly LazyVariable _baseType; /// /// Initializes a new empty pointer type. @@ -14,7 +14,7 @@ public class PointerTypeRecord : CodeViewTypeRecord protected PointerTypeRecord(uint typeIndex) : base(typeIndex) { - _baseType = new LazyVariable(GetBaseType); + _baseType = new LazyVariable(x => x.GetBaseType()); } /// @@ -25,7 +25,7 @@ protected PointerTypeRecord(uint typeIndex) public PointerTypeRecord(CodeViewTypeRecord type, PointerAttributes attributes) : base(0) { - _baseType = new LazyVariable(type); + _baseType = new LazyVariable(type); Attributes = attributes; } @@ -38,7 +38,7 @@ public PointerTypeRecord(CodeViewTypeRecord type, PointerAttributes attributes) public PointerTypeRecord(CodeViewTypeRecord type, PointerAttributes attributes, byte size) : base(0) { - _baseType = new LazyVariable(type); + _baseType = new LazyVariable(type); Attributes = attributes; Size = size; } @@ -51,8 +51,8 @@ public PointerTypeRecord(CodeViewTypeRecord type, PointerAttributes attributes, /// public CodeViewTypeRecord BaseType { - get => _baseType.Value; - set => _baseType.Value = value; + get => _baseType.GetValue(this); + set => _baseType.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/ProcedureTypeRecord.cs b/src/AsmResolver.Symbols.Pdb/Leaves/ProcedureTypeRecord.cs index b973fcccb..82e81dd84 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/ProcedureTypeRecord.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/ProcedureTypeRecord.cs @@ -7,8 +7,8 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class ProcedureTypeRecord : CodeViewTypeRecord { - private readonly LazyVariable _returnType; - private readonly LazyVariable _argumentList; + private readonly LazyVariable _returnType; + private readonly LazyVariable _argumentList; /// /// Initializes an empty procedure type. @@ -17,8 +17,8 @@ public class ProcedureTypeRecord : CodeViewTypeRecord protected ProcedureTypeRecord(uint typeIndex) : base(typeIndex) { - _returnType = new LazyVariable(GetReturnType); - _argumentList = new LazyVariable(GetArguments); + _returnType = new LazyVariable(x => x.GetReturnType()); + _argumentList = new LazyVariable(x => x.GetArguments()); } /// @@ -31,8 +31,8 @@ public ProcedureTypeRecord(CodeViewCallingConvention callingConvention, CodeView : base(0) { CallingConvention = callingConvention; - _returnType = new LazyVariable(returnType); - _argumentList = new LazyVariable(arguments); + _returnType = new LazyVariable(returnType); + _argumentList = new LazyVariable(arguments); } /// @@ -43,8 +43,8 @@ public ProcedureTypeRecord(CodeViewCallingConvention callingConvention, CodeView /// public CodeViewTypeRecord? ReturnType { - get => _returnType.Value; - set => _returnType.Value = value; + get => _returnType.GetValue(this); + set => _returnType.SetValue(value); } /// @@ -70,8 +70,8 @@ public MemberFunctionAttributes Attributes /// public ArgumentListLeaf? Arguments { - get => _argumentList.Value; - set => _argumentList.Value = value; + get => _argumentList.GetValue(this); + set => _argumentList.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/StringIdentifier.cs b/src/AsmResolver.Symbols.Pdb/Leaves/StringIdentifier.cs index 2de1b1bf2..112a9932b 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/StringIdentifier.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/StringIdentifier.cs @@ -5,8 +5,8 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class StringIdentifier : CodeViewLeaf, IIpiLeaf { - private readonly LazyVariable _value; - private readonly LazyVariable _subStrings; + private readonly LazyVariable _value; + private readonly LazyVariable _subStrings; /// /// Initializes an empty String ID entry. @@ -15,8 +15,8 @@ public class StringIdentifier : CodeViewLeaf, IIpiLeaf protected StringIdentifier(uint typeIndex) : base(typeIndex) { - _value = new LazyVariable(GetValue); - _subStrings = new LazyVariable(GetSubStrings); + _value = new LazyVariable(x =>x .GetValue()); + _subStrings = new LazyVariable(x =>x .GetSubStrings()); } /// @@ -36,8 +36,8 @@ public StringIdentifier(Utf8String value) public StringIdentifier(Utf8String value, SubStringListLeaf? subStrings) : base(0) { - _value = new LazyVariable(value); - _subStrings = new LazyVariable(subStrings); + _value = new LazyVariable(value); + _subStrings = new LazyVariable(subStrings); } /// @@ -48,8 +48,8 @@ public StringIdentifier(Utf8String value, SubStringListLeaf? subStrings) /// public Utf8String Value { - get => _value.Value; - set => _value.Value = value; + get => _value.GetValue(this); + set => _value.SetValue(value); } /// @@ -57,8 +57,8 @@ public Utf8String Value /// public SubStringListLeaf? SubStrings { - get => _subStrings.Value; - set => _subStrings.Value = value; + get => _subStrings.GetValue(this); + set => _subStrings.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/UnionTypeRecord.cs b/src/AsmResolver.Symbols.Pdb/Leaves/UnionTypeRecord.cs index a28d73ceb..b51fa686b 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/UnionTypeRecord.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/UnionTypeRecord.cs @@ -5,7 +5,7 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class UnionTypeRecord : CodeViewCompositeTypeRecord { - private readonly LazyVariable _uniqueName; + private readonly LazyVariable _uniqueName; /// /// Initializes an empty union type. @@ -14,7 +14,7 @@ public class UnionTypeRecord : CodeViewCompositeTypeRecord protected UnionTypeRecord(uint typeIndex) : base(typeIndex) { - _uniqueName = new LazyVariable(GetUniqueName); + _uniqueName = new LazyVariable(x => x.GetUniqueName()); } /// @@ -24,7 +24,7 @@ protected UnionTypeRecord(uint typeIndex) public UnionTypeRecord(ulong size) : base(0) { - _uniqueName = new LazyVariable(Utf8String.Empty); + _uniqueName = new LazyVariable(Utf8String.Empty); Size = size; } @@ -45,8 +45,8 @@ public ulong Size /// public Utf8String UniqueName { - get => _uniqueName.Value; - set => _uniqueName.Value = value; + get => _uniqueName.GetValue(this); + set => _uniqueName.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/VBaseClassField.cs b/src/AsmResolver.Symbols.Pdb/Leaves/VBaseClassField.cs index 99d5edf0e..58be950e6 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/VBaseClassField.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/VBaseClassField.cs @@ -5,8 +5,8 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class VBaseClassField : CodeViewField { - private readonly LazyVariable _baseType; - private readonly LazyVariable _basePointerType; + private readonly LazyVariable _baseType; + private readonly LazyVariable _basePointerType; /// /// Initializes a new empty virtual base class field. @@ -15,8 +15,8 @@ public class VBaseClassField : CodeViewField protected VBaseClassField(uint typeIndex) : base(typeIndex) { - _baseType = new LazyVariable(GetBaseType); - _basePointerType = new LazyVariable(GetBasePointerType); + _baseType = new LazyVariable(x => x.GetBaseType()); + _basePointerType = new LazyVariable(x => x.GetBasePointerType()); } /// @@ -35,8 +35,8 @@ public VBaseClassField( bool isIndirect) : base(0) { - _baseType = new LazyVariable(baseType); - _basePointerType = new LazyVariable(pointerType); + _baseType = new LazyVariable(baseType); + _basePointerType = new LazyVariable(pointerType); PointerOffset = pointerOffset; TableOffset = tableOffset; IsIndirect = isIndirect; @@ -61,8 +61,8 @@ public bool IsIndirect /// public CodeViewTypeRecord? Type { - get => _baseType.Value; - set => _baseType.Value = value; + get => _baseType.GetValue(this); + set => _baseType.SetValue(value); } /// @@ -70,8 +70,8 @@ public CodeViewTypeRecord? Type /// public CodeViewTypeRecord? PointerType { - get => _basePointerType.Value; - set => _basePointerType.Value = value; + get => _basePointerType.GetValue(this); + set => _basePointerType.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Leaves/VTableField.cs b/src/AsmResolver.Symbols.Pdb/Leaves/VTableField.cs index 11355cad4..5d30879a6 100644 --- a/src/AsmResolver.Symbols.Pdb/Leaves/VTableField.cs +++ b/src/AsmResolver.Symbols.Pdb/Leaves/VTableField.cs @@ -5,7 +5,7 @@ namespace AsmResolver.Symbols.Pdb.Leaves; /// public class VTableField : CodeViewField { - private readonly LazyVariable _type; + private readonly LazyVariable _type; /// /// Initializes an empty virtual function table field. @@ -14,7 +14,7 @@ public class VTableField : CodeViewField protected VTableField(uint typeIndex) : base(typeIndex) { - _type = new LazyVariable(GetPointerType); + _type = new LazyVariable(x => x.GetPointerType()); } /// @@ -24,7 +24,7 @@ protected VTableField(uint typeIndex) public VTableField(CodeViewTypeRecord pointerType) : base(0) { - _type = new LazyVariable(pointerType); + _type = new LazyVariable(pointerType); } /// @@ -35,8 +35,8 @@ public VTableField(CodeViewTypeRecord pointerType) /// public CodeViewTypeRecord? PointerType { - get => _type.Value; - set => _type.Value = value; + get => _type.GetValue(this); + set => _type.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/DbiStream.cs b/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/DbiStream.cs index 247bd21ac..581e3932f 100644 --- a/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/DbiStream.cs +++ b/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/DbiStream.cs @@ -20,8 +20,8 @@ public class DbiStream : SegmentBase private IList? _modules; private IList? _sectionContributions; private IList? _sectionMaps; - private readonly LazyVariable _typeServerMapStream; - private readonly LazyVariable _ecStream; + private readonly LazyVariable _typeServerMapStream; + private readonly LazyVariable _ecStream; private IList? _sourceFiles; private IList? _extraStreamIndices; @@ -30,8 +30,8 @@ public class DbiStream : SegmentBase /// public DbiStream() { - _typeServerMapStream = new LazyVariable(GetTypeServerMapStream); - _ecStream = new LazyVariable(GetECStream); + _typeServerMapStream = new LazyVariable(x => x.GetTypeServerMapStream()); + _ecStream = new LazyVariable(x => x.GetECStream()); IsNewVersionFormat = true; } @@ -228,8 +228,8 @@ public IList SectionMaps /// public ISegment? TypeServerMapStream { - get => _typeServerMapStream.Value; - set => _typeServerMapStream.Value = value; + get => _typeServerMapStream.GetValue(this); + set => _typeServerMapStream.SetValue(value); } /// @@ -241,8 +241,8 @@ public ISegment? TypeServerMapStream /// public ISegment? ECStream { - get => _ecStream.Value; - set => _ecStream.Value = value; + get => _ecStream.GetValue(this); + set => _ecStream.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Metadata/Modi/ModiStream.cs b/src/AsmResolver.Symbols.Pdb/Metadata/Modi/ModiStream.cs index 5f788fa54..c4d6bde40 100644 --- a/src/AsmResolver.Symbols.Pdb/Metadata/Modi/ModiStream.cs +++ b/src/AsmResolver.Symbols.Pdb/Metadata/Modi/ModiStream.cs @@ -8,20 +8,20 @@ namespace AsmResolver.Symbols.Pdb.Metadata.Modi; /// public class ModiStream : SegmentBase { - private readonly LazyVariable _symbols; - private readonly LazyVariable _c11LineInfo; - private readonly LazyVariable _c13LineInfo; - private readonly LazyVariable _globalReferences; + private readonly LazyVariable _symbols; + private readonly LazyVariable _c11LineInfo; + private readonly LazyVariable _c13LineInfo; + private readonly LazyVariable _globalReferences; /// /// Creates a new empty module info stream. /// public ModiStream() { - _symbols = new LazyVariable(GetSymbols); - _c11LineInfo = new LazyVariable(GetC11LineInfo); - _c13LineInfo = new LazyVariable(GetC13LineInfo); - _globalReferences = new LazyVariable(GetGlobalReferences); + _symbols = new LazyVariable(x => x.GetSymbols()); + _c11LineInfo = new LazyVariable(x => x.GetC11LineInfo()); + _c13LineInfo = new LazyVariable(x => x.GetC13LineInfo()); + _globalReferences = new LazyVariable(x => x.GetGlobalReferences()); } /// @@ -41,8 +41,8 @@ public uint Signature /// public IReadableSegment? Symbols { - get => _symbols.Value; - set => _symbols.Value = value; + get => _symbols.GetValue(this); + set => _symbols.SetValue(value); } /// @@ -50,8 +50,8 @@ public IReadableSegment? Symbols /// public IReadableSegment? C11LineInfo { - get => _c11LineInfo.Value; - set => _c11LineInfo.Value = value; + get => _c11LineInfo.GetValue(this); + set => _c11LineInfo.SetValue(value); } /// @@ -59,8 +59,8 @@ public IReadableSegment? C11LineInfo /// public IReadableSegment? C13LineInfo { - get => _c13LineInfo.Value; - set => _c13LineInfo.Value = value; + get => _c13LineInfo.GetValue(this); + set => _c13LineInfo.SetValue(value); } /// @@ -71,8 +71,8 @@ public IReadableSegment? C13LineInfo /// public IReadableSegment? GlobalReferences { - get => _globalReferences.Value; - set => _globalReferences.Value = value; + get => _globalReferences.GetValue(this); + set => _globalReferences.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/PdbModule.cs b/src/AsmResolver.Symbols.Pdb/PdbModule.cs index bd76dae1c..0ed64d247 100644 --- a/src/AsmResolver.Symbols.Pdb/PdbModule.cs +++ b/src/AsmResolver.Symbols.Pdb/PdbModule.cs @@ -10,10 +10,10 @@ namespace AsmResolver.Symbols.Pdb; /// public class PdbModule : ICodeViewSymbolProvider { - private readonly LazyVariable _name; - private readonly LazyVariable _objectFileName; + private readonly LazyVariable _name; + private readonly LazyVariable _objectFileName; private IList? _sourceFiles; - private readonly LazyVariable _sectionContribution; + private readonly LazyVariable _sectionContribution; private IList? _symbols; @@ -22,9 +22,9 @@ public class PdbModule : ICodeViewSymbolProvider /// protected PdbModule() { - _name = new LazyVariable(GetName); - _objectFileName = new LazyVariable(GetObjectFileName); - _sectionContribution = new LazyVariable(GetSectionContribution); + _name = new LazyVariable(x => x.GetName()); + _objectFileName = new LazyVariable(x => x.GetObjectFileName()); + _sectionContribution = new LazyVariable(x => x.GetSectionContribution()); } /// @@ -43,9 +43,9 @@ public PdbModule(Utf8String name) /// The path to the object file. public PdbModule(Utf8String name, Utf8String objectFileName) { - _name = new LazyVariable(name); - _objectFileName = new LazyVariable(objectFileName); - _sectionContribution = new LazyVariable(new SectionContribution()); + _name = new LazyVariable(name); + _objectFileName = new LazyVariable(objectFileName); + _sectionContribution = new LazyVariable(new SectionContribution()); } /// @@ -57,8 +57,8 @@ public PdbModule(Utf8String name, Utf8String objectFileName) /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// @@ -70,8 +70,8 @@ public Utf8String? Name /// public Utf8String? ObjectFileName { - get => _objectFileName.Value; - set => _objectFileName.Value = value; + get => _objectFileName.GetValue(this); + set => _objectFileName.SetValue(value); } /// @@ -93,8 +93,8 @@ public IList SourceFiles /// public SectionContribution SectionContribution { - get => _sectionContribution.Value; - set => _sectionContribution.Value = value; + get => _sectionContribution.GetValue(this); + set => _sectionContribution.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/BasePointerRelativeSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/BasePointerRelativeSymbol.cs index 83bb21064..c17fed782 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/BasePointerRelativeSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/BasePointerRelativeSymbol.cs @@ -7,16 +7,16 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class BasePointerRelativeSymbol : CodeViewSymbol, IRegisterRelativeSymbol { - private readonly LazyVariable _variableType; - private readonly LazyVariable _name; + private readonly LazyVariable _variableType; + private readonly LazyVariable _name; /// /// Initializes an empty base-pointer relative symbol. /// protected BasePointerRelativeSymbol() { - _name = new LazyVariable(GetName); - _variableType = new LazyVariable(GetVariableType); + _name = new LazyVariable(x => x.GetName()); + _variableType = new LazyVariable(x => x.GetVariableType()); } /// @@ -27,8 +27,8 @@ protected BasePointerRelativeSymbol() /// The type of variable the symbol stores. public BasePointerRelativeSymbol(Utf8String name, CodeViewTypeRecord variableType, int offset) { - _name = new LazyVariable(name); - _variableType = new LazyVariable(variableType); + _name = new LazyVariable(name); + _variableType = new LazyVariable(variableType); Offset = offset; } @@ -49,8 +49,8 @@ public int Offset /// public CodeViewTypeRecord? VariableType { - get => _variableType.Value; - set => _variableType.Value = value; + get => _variableType.GetValue(this); + set => _variableType.SetValue(value); } /// @@ -58,8 +58,8 @@ public CodeViewTypeRecord? VariableType /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/BuildInfoSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/BuildInfoSymbol.cs index 60ed99b80..a9852eb25 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/BuildInfoSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/BuildInfoSymbol.cs @@ -7,14 +7,14 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class BuildInfoSymbol : CodeViewSymbol { - private readonly LazyVariable _info; + private readonly LazyVariable _info; /// /// Initializes an empty build information symbol. /// protected BuildInfoSymbol() { - _info = new LazyVariable(GetInfo); + _info = new LazyVariable(x => x.GetInfo()); } /// @@ -23,7 +23,7 @@ protected BuildInfoSymbol() /// The information to wrap. public BuildInfoSymbol(BuildInfoLeaf info) { - _info = new LazyVariable(info); + _info = new LazyVariable(info); } /// @@ -34,8 +34,8 @@ public BuildInfoSymbol(BuildInfoLeaf info) /// public BuildInfoLeaf? Info { - get => _info.Value; - set => _info.Value = value; + get => _info.GetValue(this); + set => _info.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/CallSiteSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/CallSiteSymbol.cs index a2eb2e41e..ff88e22c6 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/CallSiteSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/CallSiteSymbol.cs @@ -7,14 +7,14 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class CallSiteSymbol : CodeViewSymbol { - private readonly LazyVariable _functionType; + private readonly LazyVariable _functionType; /// /// Initializes an empty call site symbol. /// protected CallSiteSymbol() { - _functionType = new LazyVariable(GetFunctionType); + _functionType = new LazyVariable(x => x.GetFunctionType()); } /// @@ -27,7 +27,7 @@ public CallSiteSymbol(ushort sectionIndex, int offset, CodeViewTypeRecord functi { SectionIndex = sectionIndex; Offset = offset; - _functionType = new LazyVariable(functionType); + _functionType = new LazyVariable(functionType); } /// @@ -56,8 +56,8 @@ public int Offset /// public CodeViewTypeRecord? FunctionType { - get => _functionType.Value; - set => _functionType.Value = value; + get => _functionType.GetValue(this); + set => _functionType.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/CoffGroupSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/CoffGroupSymbol.cs index 6f04d1c82..be69bda15 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/CoffGroupSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/CoffGroupSymbol.cs @@ -7,14 +7,14 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class CoffGroupSymbol : CodeViewSymbol { - private readonly LazyVariable _name; + private readonly LazyVariable _name; /// /// Initializes an empty COFF group symbol. /// protected CoffGroupSymbol() { - _name = new LazyVariable(GetName); + _name = new LazyVariable(x => x.GetName()); } /// @@ -27,7 +27,7 @@ protected CoffGroupSymbol() /// The characteristics describing the group. public CoffGroupSymbol(Utf8String name, ushort segmentIndex, uint offset, uint size, SectionFlags characteristics) { - _name = new LazyVariable(name); + _name = new LazyVariable(name); SegmentIndex = segmentIndex; Offset = offset; Size = size; @@ -78,8 +78,8 @@ public uint Offset /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/CompileSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/CompileSymbol.cs index cb95e2b29..38993eaef 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/CompileSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/CompileSymbol.cs @@ -5,14 +5,14 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public abstract class CompileSymbol : CodeViewSymbol { - private readonly LazyVariable _compilerVersion; + private readonly LazyVariable _compilerVersion; /// /// Initializes an empty compile symbol. /// protected CompileSymbol() { - _compilerVersion = new LazyVariable(GetCompilerVersion); + _compilerVersion = new LazyVariable(x => x.GetCompilerVersion()); } /// @@ -101,8 +101,8 @@ public ushort BackEndBuildVersion /// public Utf8String CompilerVersion { - get => _compilerVersion.Value; - set => _compilerVersion.Value = value; + get => _compilerVersion.GetValue(this); + set => _compilerVersion.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/ConstantSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/ConstantSymbol.cs index dffc6183a..261f64295 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/ConstantSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/ConstantSymbol.cs @@ -7,16 +7,16 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class ConstantSymbol : CodeViewSymbol { - private readonly LazyVariable _name; - private readonly LazyVariable _type; + private readonly LazyVariable _name; + private readonly LazyVariable _type; /// /// Initializes a named constant /// protected ConstantSymbol() { - _name = new LazyVariable(GetName); - _type = new LazyVariable(GetConstantType); + _name = new LazyVariable(x => x.GetName()); + _type = new LazyVariable(x => x.GetConstantType()); } /// @@ -27,8 +27,8 @@ protected ConstantSymbol() /// The value to assign to the constant. public ConstantSymbol(Utf8String name, CodeViewTypeRecord type, ushort value) { - _name = new LazyVariable(name); - _type = new LazyVariable(type); + _name = new LazyVariable(name); + _type = new LazyVariable(type); Value = value; } @@ -40,8 +40,8 @@ public ConstantSymbol(Utf8String name, CodeViewTypeRecord type, ushort value) /// public CodeViewTypeRecord Type { - get => _type.Value; - set => _type.Value = value; + get => _type.GetValue(this); + set => _type.SetValue(value); } /// @@ -58,8 +58,8 @@ public ushort Value /// public Utf8String Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/DataSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/DataSymbol.cs index e2c29c5cb..4f34d49f6 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/DataSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/DataSymbol.cs @@ -7,16 +7,16 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class DataSymbol : CodeViewSymbol, IVariableSymbol { - private readonly LazyVariable _name; - private readonly LazyVariable _variableType; + private readonly LazyVariable _name; + private readonly LazyVariable _variableType; /// /// Initializes an empty data symbol. /// protected DataSymbol() { - _name = new LazyVariable(GetName); - _variableType = new LazyVariable(GetVariableType); + _name = new LazyVariable(x => x.GetName()); + _variableType = new LazyVariable(x => x.GetVariableType()); } /// @@ -26,8 +26,8 @@ protected DataSymbol() /// The data type of the symbol. public DataSymbol(Utf8String name, CodeViewTypeRecord variableType) { - _name = new LazyVariable(name); - _variableType = new LazyVariable(variableType); + _name = new LazyVariable(name); + _variableType = new LazyVariable(variableType); } /// @@ -74,15 +74,15 @@ public uint Offset /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// public CodeViewTypeRecord? VariableType { - get => _variableType.Value; - set => _variableType.Value = value; + get => _variableType.GetValue(this); + set => _variableType.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/FileStaticSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/FileStaticSymbol.cs index a0a408b52..5a2f3525c 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/FileStaticSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/FileStaticSymbol.cs @@ -7,16 +7,16 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class FileStaticSymbol : CodeViewSymbol, IVariableSymbol { - private readonly LazyVariable _name; - private readonly LazyVariable _variableType; + private readonly LazyVariable _name; + private readonly LazyVariable _variableType; /// /// Initializes an empty file static symbol. /// protected FileStaticSymbol() { - _name = new LazyVariable(GetName); - _variableType = new LazyVariable(GetVariableType); + _name = new LazyVariable(x => x.GetName()); + _variableType = new LazyVariable(x => x.GetVariableType()); } /// @@ -28,8 +28,8 @@ protected FileStaticSymbol() public FileStaticSymbol(Utf8String name, CodeViewTypeRecord variableType, LocalAttributes attributes) { Attributes = attributes; - _name = new LazyVariable(name); - _variableType = new LazyVariable(variableType); + _name = new LazyVariable(name); + _variableType = new LazyVariable(variableType); } /// @@ -56,15 +56,15 @@ public LocalAttributes Attributes /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// public CodeViewTypeRecord? VariableType { - get => _variableType.Value; - set => _variableType.Value = value; + get => _variableType.GetValue(this); + set => _variableType.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/InlineSiteSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/InlineSiteSymbol.cs index d4fb13867..dd052121f 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/InlineSiteSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/InlineSiteSymbol.cs @@ -9,7 +9,7 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class InlineSiteSymbol : CodeViewSymbol, IScopeCodeViewSymbol { - private readonly LazyVariable _inlinee; + private readonly LazyVariable _inlinee; private IList? _symbols; private IList? _annotations; @@ -19,7 +19,7 @@ public class InlineSiteSymbol : CodeViewSymbol, IScopeCodeViewSymbol /// protected InlineSiteSymbol() { - _inlinee = new LazyVariable(GetInlinee); + _inlinee = new LazyVariable(x => x.GetInlinee()); } /// @@ -28,7 +28,7 @@ protected InlineSiteSymbol() /// The function that is being inlined. public InlineSiteSymbol(FunctionIdentifier inlinee) { - _inlinee = new LazyVariable(inlinee); + _inlinee = new LazyVariable(inlinee); } /// @@ -50,8 +50,8 @@ public IList Symbols /// public FunctionIdentifier? Inlinee { - get => _inlinee.Value; - set => _inlinee.Value = value; + get => _inlinee.GetValue(this); + set => _inlinee.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/LabelSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/LabelSymbol.cs index ca42dca92..11f509d88 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/LabelSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/LabelSymbol.cs @@ -5,14 +5,14 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class LabelSymbol : CodeViewSymbol { - private readonly LazyVariable _name; + private readonly LazyVariable _name; /// /// Initializes an empty label symbol. /// protected LabelSymbol() { - _name = new LazyVariable(GetName); + _name = new LazyVariable(x => x.GetName()); } /// @@ -24,7 +24,7 @@ protected LabelSymbol() /// The attributes describing the label. public LabelSymbol(Utf8String name, ushort segmentIndex, uint offset, ProcedureAttributes attributes) { - _name = new LazyVariable(name); + _name = new LazyVariable(name); SegmentIndex = segmentIndex; Offset = offset; Attributes = attributes; @@ -65,8 +65,8 @@ public ProcedureAttributes Attributes /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/LocalSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/LocalSymbol.cs index 2c9cdae46..d53c0f786 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/LocalSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/LocalSymbol.cs @@ -7,16 +7,16 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class LocalSymbol : CodeViewSymbol, IVariableSymbol { - private readonly LazyVariable _variableType; - private readonly LazyVariable _name; + private readonly LazyVariable _variableType; + private readonly LazyVariable _name; /// /// Initializes an empty local variable symbol. /// protected LocalSymbol() { - _variableType = new LazyVariable(GetVariableType); - _name = new LazyVariable(GetName); + _variableType = new LazyVariable(x => x.GetVariableType()); + _name = new LazyVariable(x => x.GetName()); } /// @@ -27,8 +27,8 @@ protected LocalSymbol() /// The attributes describing the variable. public LocalSymbol(Utf8String? name, CodeViewTypeRecord? variableType, LocalAttributes attributes) { - _variableType = new LazyVariable(variableType); - _name = new LazyVariable(name); + _variableType = new LazyVariable(variableType); + _name = new LazyVariable(name); Attributes = attributes; } @@ -38,8 +38,8 @@ public LocalSymbol(Utf8String? name, CodeViewTypeRecord? variableType, LocalAttr /// public CodeViewTypeRecord? VariableType { - get => _variableType.Value; - set => _variableType.Value = value; + get => _variableType.GetValue(this); + set => _variableType.SetValue(value); } /// @@ -54,8 +54,8 @@ public LocalAttributes Attributes /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/ObjectNameSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/ObjectNameSymbol.cs index d40a629dd..cfe0df8be 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/ObjectNameSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/ObjectNameSymbol.cs @@ -5,14 +5,14 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class ObjectNameSymbol : CodeViewSymbol { - private readonly LazyVariable _name; + private readonly LazyVariable _name; /// /// Initializes an empty object name symbol. /// protected ObjectNameSymbol() { - _name = new LazyVariable(GetName); + _name = new LazyVariable(x => x.GetName()); } /// @@ -23,7 +23,7 @@ protected ObjectNameSymbol() public ObjectNameSymbol(uint signature, Utf8String name) { Signature = signature; - _name = new LazyVariable(name); + _name = new LazyVariable(name); } /// @@ -43,8 +43,8 @@ public uint Signature /// public Utf8String Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/ProcedureReferenceSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/ProcedureReferenceSymbol.cs index 0ee3f5782..d1964af4e 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/ProcedureReferenceSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/ProcedureReferenceSymbol.cs @@ -5,7 +5,7 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class ProcedureReferenceSymbol : CodeViewSymbol { - private readonly LazyVariable _name; + private readonly LazyVariable _name; private readonly bool _local; /// @@ -14,7 +14,7 @@ public class ProcedureReferenceSymbol : CodeViewSymbol /// If true, this represents a local procedure reference. protected ProcedureReferenceSymbol(bool local) { - _name = new LazyVariable(GetName); + _name = new LazyVariable(x => x.GetName()); _local = local; } @@ -31,18 +31,14 @@ public ProcedureReferenceSymbol(uint checksum, uint offset, ushort module, Utf8S Checksum = checksum; Offset = offset; Module = module; - _name = new LazyVariable(name); + _name = new LazyVariable(name); _local = local; } /// - public override CodeViewSymbolType CodeViewSymbolType - { - get - { - return _local ? CodeViewSymbolType.LProcRef : CodeViewSymbolType.ProcRef; - } - } + public override CodeViewSymbolType CodeViewSymbolType => _local + ? CodeViewSymbolType.LProcRef + : CodeViewSymbolType.ProcRef; /// /// Is the symbol a Local Procedure Reference? @@ -83,8 +79,8 @@ public ushort Module /// public Utf8String Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/ProcedureSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/ProcedureSymbol.cs index 8786de18b..699a39729 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/ProcedureSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/ProcedureSymbol.cs @@ -9,8 +9,8 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class ProcedureSymbol : CodeViewSymbol, IScopeCodeViewSymbol { - private readonly LazyVariable _name; - private readonly LazyVariable _type; + private readonly LazyVariable _name; + private readonly LazyVariable _type; private IList? _symbols; @@ -19,8 +19,8 @@ public class ProcedureSymbol : CodeViewSymbol, IScopeCodeViewSymbol /// protected ProcedureSymbol() { - _name = new LazyVariable(GetName); - _type = new LazyVariable(GetFunctionType); + _name = new LazyVariable(x => x.GetName()); + _type = new LazyVariable(x => x.GetFunctionType()); } /// @@ -30,8 +30,8 @@ protected ProcedureSymbol() /// The function identifier of the procedure. public ProcedureSymbol(Utf8String name, FunctionIdentifier id) { - _name = new LazyVariable(name); - _type = new LazyVariable(id); + _name = new LazyVariable(name); + _type = new LazyVariable(id); } /// @@ -41,8 +41,8 @@ public ProcedureSymbol(Utf8String name, FunctionIdentifier id) /// The type describing the shape of the procedure. public ProcedureSymbol(Utf8String name, ProcedureTypeRecord type) { - _name = new LazyVariable(name); - _type = new LazyVariable(type); + _name = new LazyVariable(name); + _type = new LazyVariable(type); } /// @@ -124,8 +124,8 @@ public uint DebugEndOffset /// public CodeViewLeaf? Type { - get => _type.Value; - set => _type.Value = value; + get => _type.GetValue(this); + set => _type.SetValue(value); } /// @@ -178,8 +178,8 @@ public ProcedureAttributes Attributes /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/PublicSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/PublicSymbol.cs index 8d89e4212..c70aa1ec5 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/PublicSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/PublicSymbol.cs @@ -5,14 +5,14 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class PublicSymbol : CodeViewSymbol { - private readonly LazyVariable _name; + private readonly LazyVariable _name; /// /// Initializes a new empty public symbol. /// protected PublicSymbol() { - _name = new LazyVariable(GetName); + _name = new LazyVariable(x => x.GetName()); } /// @@ -26,7 +26,7 @@ public PublicSymbol(ushort segmentIndex, uint offset, Utf8String name, PublicSym { SegmentIndex = segmentIndex; Offset = offset; - _name = new LazyVariable(name); + _name = new LazyVariable(name); Attributes = attributes; } @@ -105,8 +105,8 @@ public bool IsMsil /// public Utf8String Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/RegisterRelativeSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/RegisterRelativeSymbol.cs index 4871ea858..1a868d5bd 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/RegisterRelativeSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/RegisterRelativeSymbol.cs @@ -7,16 +7,16 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class RegisterRelativeSymbol : CodeViewSymbol, IRegisterRelativeSymbol { - private readonly LazyVariable _variableType; - private readonly LazyVariable _name; + private readonly LazyVariable _variableType; + private readonly LazyVariable _name; /// /// Initializes an empty relative register symbol. /// protected RegisterRelativeSymbol() { - _variableType = new LazyVariable(GetVariableType); - _name = new LazyVariable(GetName); + _variableType = new LazyVariable(x => x.GetVariableType()); + _name = new LazyVariable(x => x.GetName()); } /// @@ -28,10 +28,10 @@ protected RegisterRelativeSymbol() /// The type of variable the register+offset pair stores. public RegisterRelativeSymbol(Utf8String name, ushort baseRegister, int offset, CodeViewTypeRecord variableType) { - _name = new LazyVariable(name); + _name = new LazyVariable(name); BaseRegister = baseRegister; Offset = offset; - _variableType = new LazyVariable(variableType); + _variableType = new LazyVariable(variableType); } /// @@ -58,15 +58,15 @@ public int Offset /// public CodeViewTypeRecord? VariableType { - get => _variableType.Value; - set => _variableType.Value = value; + get => _variableType.GetValue(this); + set => _variableType.SetValue(value); } /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/RegisterSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/RegisterSymbol.cs index 9cf7bde0b..06cc40470 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/RegisterSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/RegisterSymbol.cs @@ -7,16 +7,16 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class RegisterSymbol : CodeViewSymbol, IVariableSymbol { - private readonly LazyVariable _variableType; - private readonly LazyVariable _name; + private readonly LazyVariable _variableType; + private readonly LazyVariable _name; /// /// Initializes an empty register variable symbol. /// protected RegisterSymbol() { - _variableType = new LazyVariable(GetVariableType); - _name = new LazyVariable(GetName); + _variableType = new LazyVariable(x => x.GetVariableType()); + _name = new LazyVariable(x => x.GetName()); } /// @@ -28,8 +28,8 @@ protected RegisterSymbol() public RegisterSymbol(Utf8String? name, CodeViewTypeRecord? variableType, ushort register) { Register = register; - _variableType = new LazyVariable(variableType); - _name = new LazyVariable(name); + _variableType = new LazyVariable(variableType); + _name = new LazyVariable(name); } /// @@ -47,15 +47,15 @@ public ushort Register /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// public CodeViewTypeRecord? VariableType { - get => _variableType.Value; - set => _variableType.Value = value; + get => _variableType.GetValue(this); + set => _variableType.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/SectionSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/SectionSymbol.cs index a6885e204..5103a6ca1 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/SectionSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/SectionSymbol.cs @@ -7,14 +7,14 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class SectionSymbol : CodeViewSymbol { - private readonly LazyVariable _name; + private readonly LazyVariable _name; /// /// Initializes an empty section symbol. /// protected SectionSymbol() { - _name = new LazyVariable(GetName); + _name = new LazyVariable(x => x.GetName()); } /// @@ -23,7 +23,7 @@ protected SectionSymbol() /// The name of the section. public SectionSymbol(Utf8String name) { - _name = new LazyVariable(name); + _name = new LazyVariable(name); } /// @@ -82,8 +82,8 @@ public SectionFlags Attributes /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/ThunkSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/ThunkSymbol.cs index e765b660e..a13549893 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/ThunkSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/ThunkSymbol.cs @@ -8,7 +8,7 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class ThunkSymbol : CodeViewSymbol, IScopeCodeViewSymbol { - private readonly LazyVariable _name; + private readonly LazyVariable _name; private IList? _symbols; @@ -17,7 +17,7 @@ public class ThunkSymbol : CodeViewSymbol, IScopeCodeViewSymbol /// protected ThunkSymbol() { - _name = new LazyVariable(GetName); + _name = new LazyVariable(x => x.GetName()); } /// @@ -27,7 +27,7 @@ protected ThunkSymbol() /// The size of the thunk in bytes. public ThunkSymbol(Utf8String name, ushort size) { - _name = new LazyVariable(name); + _name = new LazyVariable(name); Size = size; } @@ -86,8 +86,8 @@ public ThunkOrdinal Ordinal /// public Utf8String? Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/UserDefinedTypeSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/UserDefinedTypeSymbol.cs index d7f4e8e10..f7873ce90 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/UserDefinedTypeSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/UserDefinedTypeSymbol.cs @@ -7,16 +7,16 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class UserDefinedTypeSymbol : CodeViewSymbol { - private readonly LazyVariable _name; - private readonly LazyVariable _type; + private readonly LazyVariable _name; + private readonly LazyVariable _type; /// /// Initializes a new empty user-defined type symbol. /// protected UserDefinedTypeSymbol() { - _name = new LazyVariable(GetName); - _type = new LazyVariable(GetSymbolType); + _name = new LazyVariable(x => x.GetName()); + _type = new LazyVariable(x => x.GetSymbolType()); } /// @@ -26,8 +26,8 @@ protected UserDefinedTypeSymbol() /// The type. public UserDefinedTypeSymbol(Utf8String name, CodeViewTypeRecord type) { - _name = new LazyVariable(name); - _type = new LazyVariable(type); + _name = new LazyVariable(name); + _type = new LazyVariable(type); } /// @@ -38,8 +38,8 @@ public UserDefinedTypeSymbol(Utf8String name, CodeViewTypeRecord type) /// public Utf8String Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// @@ -47,8 +47,8 @@ public Utf8String Name /// public CodeViewTypeRecord Type { - get => _type.Value; - set => _type.Value = value; + get => _type.GetValue(this); + set => _type.SetValue(value); } /// diff --git a/src/AsmResolver.Symbols.Pdb/Records/UsingNamespaceSymbol.cs b/src/AsmResolver.Symbols.Pdb/Records/UsingNamespaceSymbol.cs index 05badd80c..66b0e68f0 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/UsingNamespaceSymbol.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/UsingNamespaceSymbol.cs @@ -5,14 +5,14 @@ namespace AsmResolver.Symbols.Pdb.Records; /// public class UsingNamespaceSymbol : CodeViewSymbol { - private readonly LazyVariable _name; + private readonly LazyVariable _name; /// /// Initializes a new empty using namespace. /// protected UsingNamespaceSymbol() { - _name = new LazyVariable(GetName); + _name = new LazyVariable(x => x.GetName()); } /// @@ -21,7 +21,7 @@ protected UsingNamespaceSymbol() /// The namespace to use. public UsingNamespaceSymbol(Utf8String name) { - _name = new LazyVariable(name); + _name = new LazyVariable(name); } /// @@ -32,8 +32,8 @@ public UsingNamespaceSymbol(Utf8String name) /// public Utf8String Name { - get => _name.Value; - set => _name.Value = value; + get => _name.GetValue(this); + set => _name.SetValue(value); } /// diff --git a/src/AsmResolver/LazyVariable.cs b/src/AsmResolver/LazyVariable.cs index 6b4ac9814..a3fe78dd8 100644 --- a/src/AsmResolver/LazyVariable.cs +++ b/src/AsmResolver/LazyVariable.cs @@ -77,9 +77,17 @@ private void InitializeValue() } } } - } + /// + /// Represents a variable that can be lazily initialized and/or assigned a new value. + /// + /// The type of the owner of the variable. + /// The type of the values that the variable stores. + /// + /// For performance reasons, this class locks on itself for thread synchronization. Therefore, consumers + /// should not lock instances of this class as a lock object to avoid dead-locks. + /// public sealed class LazyVariable { private TValue? _value; @@ -114,6 +122,11 @@ public bool IsInitialized private set; } + /// + /// Obtains the value stored in the variable, initializing the variable if necessary. + /// + /// The owner of the variable. + /// The value. public TValue GetValue(TOwner owner) { if (!IsInitialized) @@ -121,6 +134,10 @@ public TValue GetValue(TOwner owner) return _value!; } + /// + /// Assigns a new value to the variable. + /// + /// The new value. public void SetValue(TValue value) { lock (this) @@ -141,7 +158,5 @@ private void InitializeValue(TOwner owner) } } } - } - }