From 5d8cb885873d58c9af1a9f62a42e45068e4ce704 Mon Sep 17 00:00:00 2001 From: Washi Date: Sun, 27 Nov 2022 14:41:43 +0100 Subject: [PATCH] Replace string parameters in constructors with Utf8String parameters. --- src/AsmResolver.DotNet/AssemblyDefinition.cs | 10 ++++------ src/AsmResolver.DotNet/AssemblyReference.cs | 4 ++-- src/AsmResolver.DotNet/DefaultMetadataResolver.cs | 2 +- src/AsmResolver.DotNet/EventDefinition.cs | 2 +- src/AsmResolver.DotNet/FieldDefinition.cs | 4 ++-- src/AsmResolver.DotNet/FileReference.cs | 2 +- src/AsmResolver.DotNet/GenericParameter.cs | 4 ++-- src/AsmResolver.DotNet/IFieldDescriptor.cs | 2 +- src/AsmResolver.DotNet/IMethodDescriptor.cs | 2 +- src/AsmResolver.DotNet/ImplementationMap.cs | 2 +- src/AsmResolver.DotNet/ManifestResource.cs | 4 ++-- src/AsmResolver.DotNet/MemberReference.cs | 2 +- src/AsmResolver.DotNet/MethodDefinition.cs | 2 +- src/AsmResolver.DotNet/ModuleDefinition.cs | 2 +- src/AsmResolver.DotNet/ModuleReference.cs | 2 +- src/AsmResolver.DotNet/ParameterDefinition.cs | 4 ++-- src/AsmResolver.DotNet/PropertyDefinition.cs | 2 +- src/AsmResolver.DotNet/TypeDefinition.cs | 4 ++-- src/AsmResolver.DotNet/TypeReference.cs | 4 ++-- 19 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/AsmResolver.DotNet/AssemblyDefinition.cs b/src/AsmResolver.DotNet/AssemblyDefinition.cs index fabe500a6..e379cf590 100644 --- a/src/AsmResolver.DotNet/AssemblyDefinition.cs +++ b/src/AsmResolver.DotNet/AssemblyDefinition.cs @@ -106,7 +106,7 @@ protected AssemblyDefinition(MetadataToken token) /// /// The name of the assembly. /// The version of the assembly. - public AssemblyDefinition(string? name, Version version) + public AssemblyDefinition(Utf8String? name, Version version) : this(new MetadataToken(TableIndex.Assembly, 0)) { Name = name; @@ -290,11 +290,9 @@ public void Write(string filePath, IPEImageBuilder imageBuilder, IPEFileBuilder for (int i = 0; i < Modules.Count; i++) { var module = Modules[i]; - string modulePath; - if (module == ManifestModule) - modulePath = filePath; - else - modulePath = Path.Combine(directory, module.Name ?? $"module{i}.bin"); + string modulePath = module == ManifestModule + ? filePath + : Path.Combine(directory, module.Name?.Value ?? $"module{i}.bin"); module.Write(modulePath, imageBuilder, fileBuilder); } diff --git a/src/AsmResolver.DotNet/AssemblyReference.cs b/src/AsmResolver.DotNet/AssemblyReference.cs index c255427de..d4432896c 100644 --- a/src/AsmResolver.DotNet/AssemblyReference.cs +++ b/src/AsmResolver.DotNet/AssemblyReference.cs @@ -35,7 +35,7 @@ protected AssemblyReference(MetadataToken token) /// /// The name of the assembly. /// The version of the assembly. - public AssemblyReference(string? name, Version version) + public AssemblyReference(Utf8String? name, Version version) : this(new MetadataToken(TableIndex.AssemblyRef, 0)) { Name = name; @@ -51,7 +51,7 @@ public AssemblyReference(string? name, Version version) /// unhashed public key used to verify the authenticity of the assembly. /// Indicates the public key or token (depending on ), /// used to verify the authenticity of the assembly. - public AssemblyReference(string? name, Version version, bool publicKey, byte[]? publicKeyOrToken) + public AssemblyReference(Utf8String? name, Version version, bool publicKey, byte[]? publicKeyOrToken) : this(new MetadataToken(TableIndex.AssemblyRef, 0)) { Name = name; diff --git a/src/AsmResolver.DotNet/DefaultMetadataResolver.cs b/src/AsmResolver.DotNet/DefaultMetadataResolver.cs index bd3030090..0d625ed02 100644 --- a/src/AsmResolver.DotNet/DefaultMetadataResolver.cs +++ b/src/AsmResolver.DotNet/DefaultMetadataResolver.cs @@ -226,7 +226,7 @@ public TypeResolution(IAssemblyResolver resolver) } } - private TypeDefinition? FindTypeInAssembly(AssemblyDefinition assembly, string? ns, string name) + private TypeDefinition? FindTypeInAssembly(AssemblyDefinition assembly, Utf8String? ns, Utf8String name) { for (int i = 0; i < assembly.Modules.Count; i++) { diff --git a/src/AsmResolver.DotNet/EventDefinition.cs b/src/AsmResolver.DotNet/EventDefinition.cs index d21d1036b..02b84bc36 100644 --- a/src/AsmResolver.DotNet/EventDefinition.cs +++ b/src/AsmResolver.DotNet/EventDefinition.cs @@ -42,7 +42,7 @@ protected EventDefinition(MetadataToken token) /// The name of the property. /// The attributes. /// The delegate type of the event. - public EventDefinition(string? name, EventAttributes attributes, ITypeDefOrRef? eventType) + public EventDefinition(Utf8String? name, EventAttributes attributes, ITypeDefOrRef? eventType) : this(new MetadataToken(TableIndex.Event,0)) { Name = name; diff --git a/src/AsmResolver.DotNet/FieldDefinition.cs b/src/AsmResolver.DotNet/FieldDefinition.cs index 39b7e5c3e..5f1f8d345 100644 --- a/src/AsmResolver.DotNet/FieldDefinition.cs +++ b/src/AsmResolver.DotNet/FieldDefinition.cs @@ -57,7 +57,7 @@ protected FieldDefinition(MetadataToken token) /// The name of the field. /// The attributes. /// The signature of the field. - public FieldDefinition(string? name, FieldAttributes attributes, FieldSignature? signature) + public FieldDefinition(Utf8String? name, FieldAttributes attributes, FieldSignature? signature) : this(new MetadataToken(TableIndex.Field, 0)) { Name = name; @@ -71,7 +71,7 @@ public FieldDefinition(string? name, FieldAttributes attributes, FieldSignature? /// The name of the field. /// The attributes. /// The type of values the field contains. - public FieldDefinition(string? name, FieldAttributes attributes, TypeSignature? fieldType) + public FieldDefinition(Utf8String name, FieldAttributes attributes, TypeSignature? fieldType) : this(new MetadataToken(TableIndex.Field, 0)) { Name = name; diff --git a/src/AsmResolver.DotNet/FileReference.cs b/src/AsmResolver.DotNet/FileReference.cs index 8f6078e0e..48401e611 100644 --- a/src/AsmResolver.DotNet/FileReference.cs +++ b/src/AsmResolver.DotNet/FileReference.cs @@ -35,7 +35,7 @@ protected FileReference(MetadataToken token) /// /// The name of the file. /// The attributes associated to the reference. - public FileReference(string? name, FileAttributes attributes) + public FileReference(Utf8String? name, FileAttributes attributes) : this(new MetadataToken(TableIndex.File, 0)) { Name = name; diff --git a/src/AsmResolver.DotNet/GenericParameter.cs b/src/AsmResolver.DotNet/GenericParameter.cs index cb4d1390a..a4021ca53 100644 --- a/src/AsmResolver.DotNet/GenericParameter.cs +++ b/src/AsmResolver.DotNet/GenericParameter.cs @@ -36,7 +36,7 @@ protected GenericParameter(MetadataToken token) /// Creates a new generic parameter. /// /// The name of the parameter. - public GenericParameter(string? name) + public GenericParameter(Utf8String? name) : this(new MetadataToken(TableIndex.GenericParam, 0)) { Name = name; @@ -47,7 +47,7 @@ public GenericParameter(string? name) /// /// The name of the parameter. /// Additional attributes to assign to the parameter. - public GenericParameter(string? name, GenericParameterAttributes attributes) + public GenericParameter(Utf8String? name, GenericParameterAttributes attributes) : this(new MetadataToken(TableIndex.GenericParam, 0)) { Name = name; diff --git a/src/AsmResolver.DotNet/IFieldDescriptor.cs b/src/AsmResolver.DotNet/IFieldDescriptor.cs index 8ed9a5ebf..233b45d02 100644 --- a/src/AsmResolver.DotNet/IFieldDescriptor.cs +++ b/src/AsmResolver.DotNet/IFieldDescriptor.cs @@ -10,7 +10,7 @@ public interface IFieldDescriptor : IMemberDescriptor, IMetadataMember /// /// Gets the name of the field. /// - new Utf8String Name + new Utf8String? Name { get; } diff --git a/src/AsmResolver.DotNet/IMethodDescriptor.cs b/src/AsmResolver.DotNet/IMethodDescriptor.cs index d9cf2085c..80b4485d0 100644 --- a/src/AsmResolver.DotNet/IMethodDescriptor.cs +++ b/src/AsmResolver.DotNet/IMethodDescriptor.cs @@ -10,7 +10,7 @@ public interface IMethodDescriptor : IMemberDescriptor, IMetadataMember /// /// Gets the name of the method. /// - new Utf8String Name + new Utf8String? Name { get; } diff --git a/src/AsmResolver.DotNet/ImplementationMap.cs b/src/AsmResolver.DotNet/ImplementationMap.cs index 2c9a9877f..b846d8f42 100644 --- a/src/AsmResolver.DotNet/ImplementationMap.cs +++ b/src/AsmResolver.DotNet/ImplementationMap.cs @@ -31,7 +31,7 @@ protected ImplementationMap(MetadataToken token) /// The scope that declares the imported member. /// The name of the imported member. /// The attributes associated to the implementation mapping. - public ImplementationMap(ModuleReference? scope, string? name, ImplementationMapAttributes attributes) + public ImplementationMap(ModuleReference? scope, Utf8String? name, ImplementationMapAttributes attributes) : this(new MetadataToken(TableIndex.ImplMap, 0)) { Scope = scope; diff --git a/src/AsmResolver.DotNet/ManifestResource.cs b/src/AsmResolver.DotNet/ManifestResource.cs index a0b07fbde..4034e9142 100644 --- a/src/AsmResolver.DotNet/ManifestResource.cs +++ b/src/AsmResolver.DotNet/ManifestResource.cs @@ -42,7 +42,7 @@ protected ManifestResource(MetadataToken token) /// The attributes of the resource. /// The location of the resource data. /// The offset within the file referenced by where the data starts. - public ManifestResource(string? name, ManifestResourceAttributes attributes, IImplementation? implementation, uint offset) + public ManifestResource(Utf8String? name, ManifestResourceAttributes attributes, IImplementation? implementation, uint offset) : this(new MetadataToken(TableIndex.ManifestResource, 0)) { Name = name; @@ -57,7 +57,7 @@ public ManifestResource(string? name, ManifestResourceAttributes attributes, IIm /// The name of the repository. /// The attributes of the resource. /// The embedded resource data. - public ManifestResource(string? name, ManifestResourceAttributes attributes, ISegment? data) + public ManifestResource(Utf8String? name, ManifestResourceAttributes attributes, ISegment? data) : this(new MetadataToken(TableIndex.ManifestResource, 0)) { Name = name; diff --git a/src/AsmResolver.DotNet/MemberReference.cs b/src/AsmResolver.DotNet/MemberReference.cs index 69a274884..bbc335a99 100644 --- a/src/AsmResolver.DotNet/MemberReference.cs +++ b/src/AsmResolver.DotNet/MemberReference.cs @@ -37,7 +37,7 @@ protected MemberReference(MetadataToken token) /// The name of the referenced member. /// The signature of the referenced member. This dictates whether the /// referenced member is a field or a method. - public MemberReference(IMemberRefParent? parent, string? name, MemberSignature? signature) + public MemberReference(IMemberRefParent? parent, Utf8String? name, MemberSignature? signature) : this(new MetadataToken(TableIndex.MemberRef, 0)) { Parent = parent; diff --git a/src/AsmResolver.DotNet/MethodDefinition.cs b/src/AsmResolver.DotNet/MethodDefinition.cs index a65658523..7d81b58af 100644 --- a/src/AsmResolver.DotNet/MethodDefinition.cs +++ b/src/AsmResolver.DotNet/MethodDefinition.cs @@ -68,7 +68,7 @@ protected MethodDefinition(MetadataToken token) /// is set, the bit should be unset in /// and vice versa. /// - public MethodDefinition(string? name, MethodAttributes attributes, MethodSignature? signature) + public MethodDefinition(Utf8String? name, MethodAttributes attributes, MethodSignature? signature) : this(new MetadataToken(TableIndex.Method, 0)) { Name = name; diff --git a/src/AsmResolver.DotNet/ModuleDefinition.cs b/src/AsmResolver.DotNet/ModuleDefinition.cs index c463b7e2a..ecf5895ce 100644 --- a/src/AsmResolver.DotNet/ModuleDefinition.cs +++ b/src/AsmResolver.DotNet/ModuleDefinition.cs @@ -283,7 +283,7 @@ protected ModuleDefinition(MetadataToken token) /// Defines a new .NET module that references mscorlib version 4.0.0.0. /// /// The name of the module. - public ModuleDefinition(string? name) + public ModuleDefinition(Utf8String? name) : this(new MetadataToken(TableIndex.Module, 0)) { Name = name; diff --git a/src/AsmResolver.DotNet/ModuleReference.cs b/src/AsmResolver.DotNet/ModuleReference.cs index 1c4cef6d4..87f8a52e2 100644 --- a/src/AsmResolver.DotNet/ModuleReference.cs +++ b/src/AsmResolver.DotNet/ModuleReference.cs @@ -32,7 +32,7 @@ protected ModuleReference(MetadataToken token) /// Creates a new reference to an external module. /// /// The file name of the module. - public ModuleReference(string? name) + public ModuleReference(Utf8String? name) : this(new MetadataToken(TableIndex.ModuleRef, 0)) { Name = name; diff --git a/src/AsmResolver.DotNet/ParameterDefinition.cs b/src/AsmResolver.DotNet/ParameterDefinition.cs index 33331e50a..81e815ea9 100644 --- a/src/AsmResolver.DotNet/ParameterDefinition.cs +++ b/src/AsmResolver.DotNet/ParameterDefinition.cs @@ -45,7 +45,7 @@ protected ParameterDefinition(MetadataToken token) /// Creates a new parameter definition using the provided name. /// /// The name of the new parameter. - public ParameterDefinition(string? name) + public ParameterDefinition(Utf8String? name) : this(new MetadataToken(TableIndex.Param, 0)) { Name = name; @@ -57,7 +57,7 @@ public ParameterDefinition(string? name) /// The sequence number of the new parameter. /// The name of the new parameter. /// The attributes to assign to the parameter. - public ParameterDefinition(ushort sequence, string? name, ParameterAttributes attributes) + public ParameterDefinition(ushort sequence, Utf8String? name, ParameterAttributes attributes) : this(new MetadataToken(TableIndex.Param, 0)) { Sequence = sequence; diff --git a/src/AsmResolver.DotNet/PropertyDefinition.cs b/src/AsmResolver.DotNet/PropertyDefinition.cs index 325bacd11..8a795d0e3 100644 --- a/src/AsmResolver.DotNet/PropertyDefinition.cs +++ b/src/AsmResolver.DotNet/PropertyDefinition.cs @@ -46,7 +46,7 @@ protected PropertyDefinition(MetadataToken token) /// The name of the property. /// The attributes. /// The signature of the property. - public PropertyDefinition(string? name, PropertyAttributes attributes, PropertySignature? signature) + public PropertyDefinition(Utf8String? name, PropertyAttributes attributes, PropertySignature? signature) : this(new MetadataToken(TableIndex.Property,0)) { Name = name; diff --git a/src/AsmResolver.DotNet/TypeDefinition.cs b/src/AsmResolver.DotNet/TypeDefinition.cs index b9f658544..c1e8fd6aa 100644 --- a/src/AsmResolver.DotNet/TypeDefinition.cs +++ b/src/AsmResolver.DotNet/TypeDefinition.cs @@ -63,7 +63,7 @@ protected TypeDefinition(MetadataToken token) /// The namespace the type resides in. /// The name of the type. /// The attributes associated to the type. - public TypeDefinition(string? ns, string? name, TypeAttributes attributes) + public TypeDefinition(Utf8String? ns, Utf8String? name, TypeAttributes attributes) : this(ns, name, attributes, null) { } @@ -75,7 +75,7 @@ public TypeDefinition(string? ns, string? name, TypeAttributes attributes) /// The name of the type. /// The attributes associated to the type. /// The super class that this type extends. - public TypeDefinition(string? ns, string? name, TypeAttributes attributes, ITypeDefOrRef? baseType) + public TypeDefinition(Utf8String? ns, Utf8String? name, TypeAttributes attributes, ITypeDefOrRef? baseType) : this(new MetadataToken(TableIndex.TypeDef, 0)) { Namespace = ns; diff --git a/src/AsmResolver.DotNet/TypeReference.cs b/src/AsmResolver.DotNet/TypeReference.cs index fef21335e..637de2a95 100644 --- a/src/AsmResolver.DotNet/TypeReference.cs +++ b/src/AsmResolver.DotNet/TypeReference.cs @@ -37,7 +37,7 @@ protected TypeReference(MetadataToken token) /// The scope that defines the type. /// The namespace the type resides in. /// The name of the type. - public TypeReference(IResolutionScope? scope, string? ns, string? name) + public TypeReference(IResolutionScope? scope, Utf8String? ns, Utf8String? name) : this(new MetadataToken(TableIndex.TypeRef, 0)) { _scope.Value = scope; @@ -52,7 +52,7 @@ public TypeReference(IResolutionScope? scope, string? ns, string? name) /// The scope that defines the type. /// The namespace the type resides in. /// The name of the type. - public TypeReference(ModuleDefinition? module, IResolutionScope? scope, string? ns, string? name) + public TypeReference(ModuleDefinition? module, IResolutionScope? scope, Utf8String? ns, Utf8String? name) : this(new MetadataToken(TableIndex.TypeRef, 0)) { _scope.Value = scope;