diff --git a/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs index 2f5ea6fdc..050924c9e 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + using System; using System.Collections.Generic; using System.Diagnostics; @@ -94,7 +96,7 @@ namespace ICSharpCode.Decompiler.IL /// public bool IsDescendantOf(ILInstruction possibleAncestor) { - for (ILInstruction ancestor = this; ancestor != null; ancestor = ancestor.Parent) + for (ILInstruction? ancestor = this; ancestor != null; ancestor = ancestor.Parent) { if (ancestor == possibleAncestor) return true; @@ -102,33 +104,33 @@ namespace ICSharpCode.Decompiler.IL return false; } - public ILInstruction GetCommonParent(ILInstruction other) + public ILInstruction? GetCommonParent(ILInstruction other) { if (other == null) throw new ArgumentNullException(nameof(other)); - ILInstruction a = this; - ILInstruction b = other; + ILInstruction? a = this; + ILInstruction? b = other; int levelA = a.CountAncestors(); int levelB = b.CountAncestors(); while (levelA > levelB) { - a = a.Parent; + a = a!.Parent; levelA--; } while (levelB > levelA) { - b = b.Parent; + b = b!.Parent; levelB--; } while (a != b) { - a = a.Parent; - b = b.Parent; + a = a!.Parent; + b = b!.Parent; } return a; @@ -153,13 +155,13 @@ namespace ICSharpCode.Decompiler.IL while (levelA > levelB) { - a = a.Parent; + a = a.Parent!; levelA--; } while (levelB > levelA) { - b = b.Parent; + b = b.Parent!; levelB--; } @@ -172,8 +174,8 @@ namespace ICSharpCode.Decompiler.IL while (a.Parent != b.Parent) { - a = a.Parent; - b = b.Parent; + a = a.Parent!; + b = b.Parent!; } // now a and b have the same parent or are both root nodes @@ -183,7 +185,7 @@ namespace ICSharpCode.Decompiler.IL private int CountAncestors() { int level = 0; - for (ILInstruction ancestor = this; ancestor != null; ancestor = ancestor.Parent) + for (ILInstruction? ancestor = this; ancestor != null; ancestor = ancestor.Parent) { level++; } @@ -240,7 +242,7 @@ namespace ICSharpCode.Decompiler.IL protected private void MakeDirty() { #if DEBUG - for (ILInstruction inst = this; inst != null && !inst.IsDirty; inst = inst.parent) + for (ILInstruction? inst = this; inst != null && !inst.IsDirty; inst = inst.parent) { inst.IsDirty = true; } @@ -289,7 +291,7 @@ namespace ICSharpCode.Decompiler.IL protected void InvalidateFlags() { - for (ILInstruction inst = this; inst != null && inst.flags != invalidFlags; inst = inst.parent) + for (ILInstruction? inst = this; inst != null && inst.flags != invalidFlags; inst = inst.parent) inst.flags = invalidFlags; } @@ -425,7 +427,7 @@ namespace ICSharpCode.Decompiler.IL internal ChildrenCollection(ILInstruction inst) { Debug.Assert(inst != null); - this.inst = inst; + this.inst = inst!; } public int Count { @@ -485,7 +487,7 @@ namespace ICSharpCode.Decompiler.IL /// public struct ChildrenEnumerator : IEnumerator { - ILInstruction inst; + ILInstruction? inst; readonly int end; int pos; @@ -494,7 +496,7 @@ namespace ICSharpCode.Decompiler.IL Debug.Assert(inst != null); this.inst = inst; this.pos = -1; - this.end = inst.GetChildCount(); + this.end = inst!.GetChildCount(); #if DEBUG inst.StartEnumerator(); #endif @@ -502,7 +504,7 @@ namespace ICSharpCode.Decompiler.IL public ILInstruction Current { get { - return inst.GetChild(pos); + return inst!.GetChild(pos); } } @@ -556,7 +558,7 @@ namespace ICSharpCode.Decompiler.IL /// public void ReplaceWith(ILInstruction replacement) { - Debug.Assert(parent.GetChild(ChildIndex) == this); + Debug.Assert(parent!.GetChild(ChildIndex) == this); if (replacement == this) return; parent.SetChild(ChildIndex, replacement); @@ -621,7 +623,7 @@ namespace ICSharpCode.Decompiler.IL /// public IEnumerable Ancestors { get { - for (ILInstruction node = this; node != null; node = node.Parent) + for (ILInstruction? node = this; node != null; node = node.Parent) { yield return node; } @@ -683,7 +685,7 @@ namespace ICSharpCode.Decompiler.IL child.ReleaseRef(); } - ILInstruction parent; + ILInstruction? parent; /// /// Gets the parent of this ILInstruction. @@ -709,7 +711,7 @@ namespace ICSharpCode.Decompiler.IL /// /// Note that is it is possible (though unusual) for a stale position to reference an orphaned node. /// - public ILInstruction Parent { + public ILInstruction? Parent { get { return parent; } } @@ -732,7 +734,7 @@ namespace ICSharpCode.Decompiler.IL /// /// Precondition: this node must not be orphaned. /// - public SlotInfo SlotInfo { + public SlotInfo? SlotInfo { get { if (parent == null) return null; @@ -748,7 +750,7 @@ namespace ICSharpCode.Decompiler.IL /// New child /// Index of the field in the Children collection protected internal void SetChildInstruction(ref T childPointer, T newValue, int index) - where T : ILInstruction + where T : ILInstruction? { T oldValue = childPointer; Debug.Assert(oldValue == GetChild(index)); @@ -861,7 +863,7 @@ namespace ICSharpCode.Decompiler.IL /// If the method returns true, it adds the capture groups (if any) to the match. /// If the method returns false, the match object may remain in a partially-updated state and /// needs to be restored before it can be reused. - protected internal abstract bool PerformMatch(ILInstruction other, ref Match match); + protected internal abstract bool PerformMatch(ILInstruction? other, ref Match match); /// /// Attempts matching this instruction against a list of other instructions (or a part of said list). diff --git a/ICSharpCode.Decompiler/IL/Transforms/IILTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/IILTransform.cs index e813ebaed..35c5fd7fb 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/IILTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/IILTransform.cs @@ -16,16 +16,15 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + using System; -using System.Collections.Generic; -using System.Collections.Immutable; using System.Diagnostics; using System.Threading; using ICSharpCode.Decompiler.CSharp.TypeSystem; using ICSharpCode.Decompiler.DebugInfo; using ICSharpCode.Decompiler.TypeSystem; -using ICSharpCode.Decompiler.Util; namespace ICSharpCode.Decompiler.IL.Transforms { @@ -44,16 +43,16 @@ namespace ICSharpCode.Decompiler.IL.Transforms { public ILFunction Function { get; } public IDecompilerTypeSystem TypeSystem { get; } - public IDebugInfoProvider DebugInfo { get; } + public IDebugInfoProvider? DebugInfo { get; } public DecompilerSettings Settings { get; } public CancellationToken CancellationToken { get; set; } public Stepper Stepper { get; set; } public Metadata.PEFile PEFile => TypeSystem.MainModule.PEFile; - internal DecompileRun DecompileRun { get; set; } - internal ResolvedUsingScope UsingScope => DecompileRun?.UsingScope.Resolve(TypeSystem); + internal DecompileRun? DecompileRun { get; set; } + internal ResolvedUsingScope? UsingScope => DecompileRun?.UsingScope.Resolve(TypeSystem); - public ILTransformContext(ILFunction function, IDecompilerTypeSystem typeSystem, IDebugInfoProvider debugInfo, DecompilerSettings settings = null) + public ILTransformContext(ILFunction function, IDecompilerTypeSystem typeSystem, IDebugInfoProvider? debugInfo, DecompilerSettings? settings = null) { this.Function = function ?? throw new ArgumentNullException(nameof(function)); this.TypeSystem = typeSystem ?? throw new ArgumentNullException(nameof(typeSystem)); @@ -62,7 +61,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms Stepper = new Stepper(); } - public ILTransformContext(ILTransformContext context, ILFunction function = null) + public ILTransformContext(ILTransformContext context, ILFunction? function = null) { this.Function = function ?? context.Function; this.TypeSystem = context.TypeSystem; @@ -89,13 +88,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms /// Unlike context.Stepper.Step(), calls to this method are only compiled in debug builds. /// [Conditional("STEP")] - internal void Step(string description, ILInstruction near) + internal void Step(string description, ILInstruction? near) { Stepper.Step(description, near); } [Conditional("STEP")] - internal void StepStartGroup(string description, ILInstruction near = null) + internal void StepStartGroup(string description, ILInstruction? near = null) { Stepper.StartGroup(description, near); } diff --git a/ICSharpCode.Decompiler/IL/Transforms/Stepper.cs b/ICSharpCode.Decompiler/IL/Transforms/Stepper.cs index 76aa63ff0..f3f85386a 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/Stepper.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/Stepper.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + using System; using System.Collections.Generic; using System.Diagnostics; @@ -58,8 +60,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms public class Node { - public string Description { get; set; } - public ILInstruction Position { get; set; } + public string Description { get; } + public ILInstruction? Position { get; set; } /// /// BeginStep is inclusive. /// @@ -70,6 +72,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms public int EndStep { get; set; } public IList Children { get; } = new List(); + + public Node(string description) + { + Description = description; + } } readonly Stack groups; @@ -88,12 +95,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms /// /// May throw in debug mode. /// - public void Step(string description, ILInstruction near = null) + public void Step(string description, ILInstruction? near = null) { StepInternal(description, near); } - private Node StepInternal(string description, ILInstruction near) + private Node StepInternal(string description, ILInstruction? near) { if (step == StepLimit) { @@ -102,8 +109,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms else throw new StepLimitReachedException(); } - var stepNode = new Node { - Description = $"{step}: {description}", + var stepNode = new Node($"{step}: {description}") { Position = near, BeginStep = step, EndStep = step + 1 @@ -117,7 +123,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return stepNode; } - public void StartGroup(string description, ILInstruction near = null) + public void StartGroup(string description, ILInstruction? near = null) { groups.Push(StepInternal(description, near)); } diff --git a/ICSharpCode.Decompiler/TypeSystem/IAssembly.cs b/ICSharpCode.Decompiler/TypeSystem/IAssembly.cs index d2191da74..da8148f90 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IAssembly.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IAssembly.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + using System.Collections.Generic; using ICSharpCode.Decompiler.Metadata; @@ -40,7 +42,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// /// Resolves this metadata module. /// - IModule Resolve(ITypeResolveContext context); + IModule? Resolve(ITypeResolveContext context); } /// @@ -51,7 +53,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// /// Gets the underlying metadata file. May return null, if the IAssembly was not created from a PE file. /// - PEFile PEFile { get; } + PEFile? PEFile { get; } /// /// Gets whether this assembly is the main assembly of the compilation. @@ -97,7 +99,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// Gets the type definition for a top-level type. /// /// This method uses ordinal name comparison, not the compilation's name comparer. - ITypeDefinition GetTypeDefinition(TopLevelTypeName topLevelTypeName); + ITypeDefinition? GetTypeDefinition(TopLevelTypeName topLevelTypeName); /// /// Gets all non-nested types in the assembly. diff --git a/ICSharpCode.Decompiler/TypeSystem/IAttribute.cs b/ICSharpCode.Decompiler/TypeSystem/IAttribute.cs index 53b61b0c8..45d07b092 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IAttribute.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IAttribute.cs @@ -16,12 +16,11 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using System.Collections.Generic; +#nullable enable + using System.Collections.Immutable; using System.Reflection.Metadata; -using ICSharpCode.Decompiler.Semantics; - namespace ICSharpCode.Decompiler.TypeSystem { /// @@ -39,7 +38,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// Gets the constructor being used. /// This property may return null if no matching constructor was found. /// - IMethod Constructor { get; } + IMethod? Constructor { get; } /// /// Gets whether there were errors decoding the attribute. diff --git a/ICSharpCode.Decompiler/TypeSystem/ICodeContext.cs b/ICSharpCode.Decompiler/TypeSystem/ICodeContext.cs index 6d9525c08..09152382b 100644 --- a/ICSharpCode.Decompiler/TypeSystem/ICodeContext.cs +++ b/ICSharpCode.Decompiler/TypeSystem/ICodeContext.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + using System.Collections.Generic; namespace ICSharpCode.Decompiler.TypeSystem @@ -34,4 +36,3 @@ namespace ICSharpCode.Decompiler.TypeSystem bool IsWithinLambdaExpression { get; } } } - diff --git a/ICSharpCode.Decompiler/TypeSystem/ICompilation.cs b/ICSharpCode.Decompiler/TypeSystem/ICompilation.cs index d41f350f4..abbbe5e2d 100644 --- a/ICSharpCode.Decompiler/TypeSystem/ICompilation.cs +++ b/ICSharpCode.Decompiler/TypeSystem/ICompilation.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + using System; using System.Collections.Generic; @@ -63,7 +65,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// returns the global root namespace. /// If no alias with the specified name exists, this method returns null. /// - INamespace GetNamespaceForExternAlias(string alias); + INamespace? GetNamespaceForExternAlias(string? alias); IType FindType(KnownTypeCode typeCode); diff --git a/ICSharpCode.Decompiler/TypeSystem/IDecompilerTypeSystem.cs b/ICSharpCode.Decompiler/TypeSystem/IDecompilerTypeSystem.cs index f45bdd2c1..44991cd95 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IDecompilerTypeSystem.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IDecompilerTypeSystem.cs @@ -16,10 +16,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using System.Collections.Immutable; -using System.Reflection.Metadata; - -using ICSharpCode.Decompiler.Metadata; +#nullable enable namespace ICSharpCode.Decompiler.TypeSystem { diff --git a/ICSharpCode.Decompiler/TypeSystem/IEntity.cs b/ICSharpCode.Decompiler/TypeSystem/IEntity.cs index 4bd680a75..92452c64a 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IEntity.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IEntity.cs @@ -16,7 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using System; +#nullable enable + using System.Collections.Generic; namespace ICSharpCode.Decompiler.TypeSystem @@ -46,14 +47,14 @@ namespace ICSharpCode.Decompiler.TypeSystem /// For members, this is the class that contains the member. /// For nested classes, this is the outer class. For top-level entities, this property returns null. /// - ITypeDefinition DeclaringTypeDefinition { get; } + ITypeDefinition? DeclaringTypeDefinition { get; } /// /// Gets/Sets the declaring type (incl. type arguments, if any). /// This property will return null for top-level entities. /// If this is not a specialized member, the value returned is equal to . /// - IType DeclaringType { get; } + IType? DeclaringType { get; } /// /// The module in which this entity is defined. diff --git a/ICSharpCode.Decompiler/TypeSystem/IEvent.cs b/ICSharpCode.Decompiler/TypeSystem/IEvent.cs index ee9aa2b80..732840c62 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IEvent.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IEvent.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + namespace ICSharpCode.Decompiler.TypeSystem { public interface IEvent : IMember @@ -24,8 +26,8 @@ namespace ICSharpCode.Decompiler.TypeSystem bool CanRemove { get; } bool CanInvoke { get; } - IMethod AddAccessor { get; } - IMethod RemoveAccessor { get; } - IMethod InvokeAccessor { get; } + IMethod? AddAccessor { get; } + IMethod? RemoveAccessor { get; } + IMethod? InvokeAccessor { get; } } } diff --git a/ICSharpCode.Decompiler/TypeSystem/IField.cs b/ICSharpCode.Decompiler/TypeSystem/IField.cs index 18f5a00b7..49a92fd26 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IField.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IField.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + namespace ICSharpCode.Decompiler.TypeSystem { /// diff --git a/ICSharpCode.Decompiler/TypeSystem/IFreezable.cs b/ICSharpCode.Decompiler/TypeSystem/IFreezable.cs index b6dae14f0..2623eb1c2 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IFreezable.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IFreezable.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + namespace ICSharpCode.Decompiler.TypeSystem { public interface IFreezable diff --git a/ICSharpCode.Decompiler/TypeSystem/IInterningProvider.cs b/ICSharpCode.Decompiler/TypeSystem/IInterningProvider.cs index 0c670f214..7ef6a58fc 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IInterningProvider.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IInterningProvider.cs @@ -16,7 +16,10 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace ICSharpCode.Decompiler.TypeSystem { @@ -47,52 +50,57 @@ namespace ICSharpCode.Decompiler.TypeSystem /// /// If the object is freezable, it will be frozen. /// - public abstract ISupportsInterning Intern(ISupportsInterning obj); + [return: NotNullIfNotNull("obj")] + public abstract ISupportsInterning? Intern(ISupportsInterning? obj); /// /// Interns the specified object. /// /// If the object is freezable, it will be frozen. /// - public T Intern(T obj) where T : class, ISupportsInterning + [return: NotNullIfNotNull("obj")] + public T? Intern(T? obj) where T : class, ISupportsInterning { - ISupportsInterning input = obj; - return (T)Intern(input); + ISupportsInterning? input = obj; + return (T?)Intern(input); } /// /// Interns the specified string. /// - public abstract string Intern(string text); + [return: NotNullIfNotNull("text")] + public abstract string? Intern(string? text); /// /// Inters a boxed value type. /// - public abstract object InternValue(object obj); + [return: NotNullIfNotNull("obj")] + public abstract object? InternValue(object? obj); /// /// Interns the given list. Uses reference equality to compare the list elements. /// - public abstract IList InternList(IList list) where T : class; + [return: NotNullIfNotNull("list")] + public abstract IList? InternList(IList? list) where T : class; sealed class DummyInterningProvider : InterningProvider { - public override ISupportsInterning Intern(ISupportsInterning obj) + public override ISupportsInterning? Intern(ISupportsInterning? obj) { return obj; } - public override string Intern(string text) + public override string? Intern(string? text) { return text; } - public override object InternValue(object obj) + public override object? InternValue(object? obj) { return obj; } - public override IList InternList(IList list) + public override IList? InternList(IList? list) { return list; } diff --git a/ICSharpCode.Decompiler/TypeSystem/IMember.cs b/ICSharpCode.Decompiler/TypeSystem/IMember.cs index 47718c4d1..d5f359072 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IMember.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IMember.cs @@ -16,7 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using System; +#nullable enable + using System.Collections.Generic; namespace ICSharpCode.Decompiler.TypeSystem @@ -40,7 +41,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// /// Returns the resolved member, or null if the member could not be found. /// - IMember Resolve(ITypeResolveContext context); + IMember? Resolve(ITypeResolveContext context); } /// @@ -119,6 +120,6 @@ namespace ICSharpCode.Decompiler.TypeSystem /// /// Gets whether the members are considered equal when applying the specified type normalization. /// - bool Equals(IMember obj, TypeVisitor typeNormalization); + bool Equals(IMember? obj, TypeVisitor typeNormalization); } } diff --git a/ICSharpCode.Decompiler/TypeSystem/IMethod.cs b/ICSharpCode.Decompiler/TypeSystem/IMethod.cs index d82dc5491..26e4626c8 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IMethod.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IMethod.cs @@ -16,7 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using System; +#nullable enable + using System.Collections.Generic; using System.Reflection; @@ -86,7 +87,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// If this method is an accessor, returns the corresponding property/event. /// Otherwise, returns null. /// - IMember AccessorOwner { get; } + IMember? AccessorOwner { get; } /// /// Gets the kind of accessor this is. @@ -98,7 +99,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// A reduced method doesn't contain the extension method parameter. That means that it has one parameter less than its definition. /// A local function doesn't contain compiler-generated method parameters at the end. /// - IMethod ReducedFrom { get; } + IMethod? ReducedFrom { get; } /// /// Specializes this method with the given substitution. diff --git a/ICSharpCode.Decompiler/TypeSystem/INamespace.cs b/ICSharpCode.Decompiler/TypeSystem/INamespace.cs index 353fd633b..81c6fe967 100644 --- a/ICSharpCode.Decompiler/TypeSystem/INamespace.cs +++ b/ICSharpCode.Decompiler/TypeSystem/INamespace.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + using System.Collections.Generic; namespace ICSharpCode.Decompiler.TypeSystem @@ -49,7 +51,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// Gets the parent namespace. /// Returns null if this is the root namespace. /// - INamespace ParentNamespace { get; } + INamespace? ParentNamespace { get; } /// /// Gets the child namespaces in this namespace. @@ -73,7 +75,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// /// This method uses the compilation's current string comparer. /// - INamespace GetChildNamespace(string name); + INamespace? GetChildNamespace(string name); /// /// Gets the type with the specified short name and type parameter count. @@ -82,6 +84,6 @@ namespace ICSharpCode.Decompiler.TypeSystem /// /// This method uses the compilation's current string comparer. /// - ITypeDefinition GetTypeDefinition(string name, int typeParameterCount); + ITypeDefinition? GetTypeDefinition(string name, int typeParameterCount); } } diff --git a/ICSharpCode.Decompiler/TypeSystem/IParameter.cs b/ICSharpCode.Decompiler/TypeSystem/IParameter.cs index ff7fdea3b..b28b4db09 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IParameter.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IParameter.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -90,6 +92,6 @@ namespace ICSharpCode.Decompiler.TypeSystem /// Gets the owner of this parameter. /// May return null; for example when parameters belong to lambdas or anonymous methods. /// - IParameterizedMember Owner { get; } + IParameterizedMember? Owner { get; } } } diff --git a/ICSharpCode.Decompiler/TypeSystem/IParameterizedMember.cs b/ICSharpCode.Decompiler/TypeSystem/IParameterizedMember.cs index 7f7e055ed..aba9a8f1f 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IParameterizedMember.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IParameterizedMember.cs @@ -15,6 +15,7 @@ // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable using System.Collections.Generic; diff --git a/ICSharpCode.Decompiler/TypeSystem/IProperty.cs b/ICSharpCode.Decompiler/TypeSystem/IProperty.cs index 56673e52b..f8b6203d1 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IProperty.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IProperty.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + namespace ICSharpCode.Decompiler.TypeSystem { /// @@ -26,8 +28,8 @@ namespace ICSharpCode.Decompiler.TypeSystem bool CanGet { get; } bool CanSet { get; } - IMethod Getter { get; } - IMethod Setter { get; } + IMethod? Getter { get; } + IMethod? Setter { get; } bool IsIndexer { get; } diff --git a/ICSharpCode.Decompiler/TypeSystem/ISupportsInterning.cs b/ICSharpCode.Decompiler/TypeSystem/ISupportsInterning.cs index dfab4ea57..e3517fce7 100644 --- a/ICSharpCode.Decompiler/TypeSystem/ISupportsInterning.cs +++ b/ICSharpCode.Decompiler/TypeSystem/ISupportsInterning.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + namespace ICSharpCode.Decompiler.TypeSystem { /// diff --git a/ICSharpCode.Decompiler/TypeSystem/ISymbol.cs b/ICSharpCode.Decompiler/TypeSystem/ISymbol.cs index 6bfcd5b71..430479efb 100644 --- a/ICSharpCode.Decompiler/TypeSystem/ISymbol.cs +++ b/ICSharpCode.Decompiler/TypeSystem/ISymbol.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + namespace ICSharpCode.Decompiler.TypeSystem { public enum SymbolKind : byte diff --git a/ICSharpCode.Decompiler/TypeSystem/IType.cs b/ICSharpCode.Decompiler/TypeSystem/IType.cs index c9725d04e..a5e38fc6a 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IType.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IType.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + using System; using System.Collections.Generic; @@ -83,13 +85,13 @@ namespace ICSharpCode.Decompiler.TypeSystem /// Gets the underlying type definition. /// Can return null for types which do not have a type definition (for example arrays, pointers, type parameters). /// - ITypeDefinition GetDefinition(); + ITypeDefinition? GetDefinition(); /// /// Gets the parent type, if this is a nested type. /// Returns null for top-level types. /// - IType DeclaringType { get; } + IType? DeclaringType { get; } /// /// Gets the number of type parameters. @@ -168,7 +170,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// Base.GetNestedTypes() = { Base`1+Nested`1[`0, unbound] } /// /// - IEnumerable GetNestedTypes(Predicate filter = null, GetMemberOptions options = GetMemberOptions.None); + IEnumerable GetNestedTypes(Predicate? filter = null, GetMemberOptions options = GetMemberOptions.None); // Note that we cannot 'leak' the additional type parameter as we leak the normal type parameters, because // the index might collide. For example, @@ -193,7 +195,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// and thus 'leaked' to the caller in the same way the GetMembers() method does not specialize members /// from an and 'leaks' type parameters in member signatures. /// - IEnumerable GetNestedTypes(IReadOnlyList typeArguments, Predicate filter = null, GetMemberOptions options = GetMemberOptions.None); + IEnumerable GetNestedTypes(IReadOnlyList typeArguments, Predicate? filter = null, GetMemberOptions options = GetMemberOptions.None); /// /// Gets all instance constructors for this type. @@ -209,7 +211,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// and the appropriate will be returned. /// /// - IEnumerable GetConstructors(Predicate filter = null, GetMemberOptions options = GetMemberOptions.IgnoreInheritedMembers); + IEnumerable GetConstructors(Predicate? filter = null, GetMemberOptions options = GetMemberOptions.IgnoreInheritedMembers); /// /// Gets all methods that can be called on this type. @@ -236,7 +238,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// the ambiguity can be avoided. /// /// - IEnumerable GetMethods(Predicate filter = null, GetMemberOptions options = GetMemberOptions.None); + IEnumerable GetMethods(Predicate? filter = null, GetMemberOptions options = GetMemberOptions.None); /// /// Gets all generic methods that can be called on this type with the specified type arguments. @@ -257,7 +259,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// and the other overload's remarks about ambiguous signatures apply here as well. /// /// - IEnumerable GetMethods(IReadOnlyList typeArguments, Predicate filter = null, GetMemberOptions options = GetMemberOptions.None); + IEnumerable GetMethods(IReadOnlyList typeArguments, Predicate? filter = null, GetMemberOptions options = GetMemberOptions.None); /// /// Gets all properties that can be called on this type. @@ -269,7 +271,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// For properties on parameterized types, type substitution will be performed on the property signature, /// and the appropriate will be returned. /// - IEnumerable GetProperties(Predicate filter = null, GetMemberOptions options = GetMemberOptions.None); + IEnumerable GetProperties(Predicate? filter = null, GetMemberOptions options = GetMemberOptions.None); /// /// Gets all fields that can be accessed on this type. @@ -281,7 +283,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// For fields on parameterized types, type substitution will be performed on the field's return type, /// and the appropriate will be returned. /// - IEnumerable GetFields(Predicate filter = null, GetMemberOptions options = GetMemberOptions.None); + IEnumerable GetFields(Predicate? filter = null, GetMemberOptions options = GetMemberOptions.None); /// /// Gets all events that can be accessed on this type. @@ -293,7 +295,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// For fields on parameterized types, type substitution will be performed on the event's return type, /// and the appropriate will be returned. /// - IEnumerable GetEvents(Predicate filter = null, GetMemberOptions options = GetMemberOptions.None); + IEnumerable GetEvents(Predicate? filter = null, GetMemberOptions options = GetMemberOptions.None); /// /// Gets all members that can be called on this type. @@ -312,7 +314,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// method apply here as well. /// /// - IEnumerable GetMembers(Predicate filter = null, GetMemberOptions options = GetMemberOptions.None); + IEnumerable GetMembers(Predicate? filter = null, GetMemberOptions options = GetMemberOptions.None); /// /// Gets all accessors belonging to properties or events on this type. @@ -323,7 +325,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// /// Accessors are not returned by GetMembers() or GetMethods(). /// - IEnumerable GetAccessors(Predicate filter = null, GetMemberOptions options = GetMemberOptions.None); + IEnumerable GetAccessors(Predicate? filter = null, GetMemberOptions options = GetMemberOptions.None); } [Flags] diff --git a/ICSharpCode.Decompiler/TypeSystem/ITypeDefinition.cs b/ICSharpCode.Decompiler/TypeSystem/ITypeDefinition.cs index 4eb6b922c..bd7bb1b3c 100644 --- a/ICSharpCode.Decompiler/TypeSystem/ITypeDefinition.cs +++ b/ICSharpCode.Decompiler/TypeSystem/ITypeDefinition.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + using System.Collections.Generic; namespace ICSharpCode.Decompiler.TypeSystem @@ -60,7 +62,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// Gets/Sets the declaring type (incl. type arguments, if any). /// This property will return null for top-level types. /// - new IType DeclaringType { get; } // solves ambiguity between IType.DeclaringType and IEntity.DeclaringType + new IType? DeclaringType { get; } // solves ambiguity between IType.DeclaringType and IEntity.DeclaringType /// /// Gets whether this type contains extension methods. diff --git a/ICSharpCode.Decompiler/TypeSystem/ITypeParameter.cs b/ICSharpCode.Decompiler/TypeSystem/ITypeParameter.cs index 4079d274a..09bed7da3 100644 --- a/ICSharpCode.Decompiler/TypeSystem/ITypeParameter.cs +++ b/ICSharpCode.Decompiler/TypeSystem/ITypeParameter.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + using System; using System.Collections.Generic; @@ -43,7 +45,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// inner.TypeParameters[0].Owner will be the outer class, because the same /// ITypeParameter instance is used both on Outer`1 and Outer`1+Inner. /// - IEntity Owner { get; } + IEntity? Owner { get; } /// /// Gets the index of the type parameter in the type parameter list of the owning method/class. @@ -112,7 +114,7 @@ namespace ICSharpCode.Decompiler.TypeSystem public IType Type { get; } public IReadOnlyList Attributes { get; } - public TypeConstraint(IType type, IReadOnlyList attributes = null) + public TypeConstraint(IType type, IReadOnlyList? attributes = null) { this.Type = type ?? throw new ArgumentNullException(nameof(type)); this.Attributes = attributes ?? EmptyList.Instance; diff --git a/ICSharpCode.Decompiler/TypeSystem/ITypeReference.cs b/ICSharpCode.Decompiler/TypeSystem/ITypeReference.cs index 92ef08450..0716a4807 100644 --- a/ICSharpCode.Decompiler/TypeSystem/ITypeReference.cs +++ b/ICSharpCode.Decompiler/TypeSystem/ITypeReference.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable + namespace ICSharpCode.Decompiler.TypeSystem { /// @@ -53,19 +55,19 @@ namespace ICSharpCode.Decompiler.TypeSystem /// Gets the current module. /// This property may return null if this context does not specify any module. /// - IModule CurrentModule { get; } + IModule? CurrentModule { get; } /// /// Gets the current type definition. /// - ITypeDefinition CurrentTypeDefinition { get; } + ITypeDefinition? CurrentTypeDefinition { get; } /// /// Gets the current member. /// - IMember CurrentMember { get; } + IMember? CurrentMember { get; } - ITypeResolveContext WithCurrentTypeDefinition(ITypeDefinition typeDefinition); - ITypeResolveContext WithCurrentMember(IMember member); + ITypeResolveContext WithCurrentTypeDefinition(ITypeDefinition? typeDefinition); + ITypeResolveContext WithCurrentMember(IMember? member); } -} \ No newline at end of file +} diff --git a/ICSharpCode.Decompiler/TypeSystem/IVariable.cs b/ICSharpCode.Decompiler/TypeSystem/IVariable.cs index 13e1c270e..1e537cb88 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IVariable.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IVariable.cs @@ -15,6 +15,7 @@ // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable namespace ICSharpCode.Decompiler.TypeSystem { @@ -42,6 +43,6 @@ namespace ICSharpCode.Decompiler.TypeSystem /// If this field is a constant, retrieves the value. /// For parameters, this is the default value. /// - object GetConstantValue(bool throwOnInvalidMetadata = false); + object? GetConstantValue(bool throwOnInvalidMetadata = false); } } diff --git a/ICSharpCode.Decompiler/TypeSystem/KnownTypeReference.cs b/ICSharpCode.Decompiler/TypeSystem/KnownTypeReference.cs index 03b2b1267..06ba9d6cd 100644 --- a/ICSharpCode.Decompiler/TypeSystem/KnownTypeReference.cs +++ b/ICSharpCode.Decompiler/TypeSystem/KnownTypeReference.cs @@ -15,6 +15,7 @@ // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#nullable enable using System; using System.Collections.Generic; @@ -162,7 +163,7 @@ namespace ICSharpCode.Decompiler.TypeSystem { internal const int KnownTypeCodeCount = (int)KnownTypeCode.Range + 1; - static readonly KnownTypeReference[] knownTypeReferences = new KnownTypeReference[KnownTypeCodeCount] { + static readonly KnownTypeReference?[] knownTypeReferences = new KnownTypeReference?[KnownTypeCodeCount] { null, // None new KnownTypeReference(KnownTypeCode.Object, TypeKind.Class, "System", "Object", baseType: KnownTypeCode.None), new KnownTypeReference(KnownTypeCode.DBNull, TypeKind.Class, "System", "DBNull"), @@ -231,7 +232,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// Gets the known type reference for the specified type code. /// Returns null for KnownTypeCode.None. /// - public static KnownTypeReference Get(KnownTypeCode typeCode) + public static KnownTypeReference? Get(KnownTypeCode typeCode) { return knownTypeReferences[(int)typeCode]; } @@ -299,7 +300,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// Gets the C# primitive type name from the known type code. /// Returns null if there is no primitive name for the specified type. /// - public static string GetCSharpNameByTypeCode(KnownTypeCode knownTypeCode) + public static string? GetCSharpNameByTypeCode(KnownTypeCode knownTypeCode) { switch (knownTypeCode) {