-
-
Notifications
You must be signed in to change notification settings - Fork 1k
chore: Enable nullable for job/characteristics relating code #2900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |
| using System.Reflection; | ||
| using JetBrains.Annotations; | ||
|
|
||
| #nullable enable | ||
|
|
||
| namespace BenchmarkDotNet.Characteristics | ||
| { | ||
| // TODO: better naming. | ||
|
|
@@ -17,15 +19,15 @@ public abstract class CharacteristicObject | |
| DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | ||
| | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields; | ||
|
|
||
| protected static string ResolveId(CharacteristicObject obj, string actual) | ||
| protected static string ResolveId(CharacteristicObject obj, string? actual) | ||
| { | ||
| if (!string.IsNullOrEmpty(actual) && actual != IdCharacteristic.FallbackValue) | ||
| return actual; | ||
| return actual!; | ||
|
|
||
| string result = CharacteristicSetPresenter.Display.ToPresentation(obj); | ||
|
|
||
| if (result.Length == 0) | ||
| result = IdCharacteristic.FallbackValue; | ||
| result = IdCharacteristic.FallbackValue!; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| return result; | ||
| } | ||
|
|
@@ -44,7 +46,7 @@ protected CharacteristicObject() | |
| sharedValues = new Dictionary<Characteristic, object>(); | ||
| } | ||
|
|
||
| protected CharacteristicObject(string? id) : this() | ||
| protected CharacteristicObject(string id) : this() | ||
| { | ||
| if (!string.IsNullOrEmpty(id)) | ||
| { | ||
|
|
@@ -79,7 +81,7 @@ private void AssertIsNonFrozenRoot() | |
| AssertIsRoot(); | ||
| } | ||
|
|
||
| private static void AssertIsAssignable(Characteristic characteristic, object value) | ||
| private static void AssertIsAssignable(Characteristic characteristic, object? value) | ||
| { | ||
| if (ReferenceEquals(value, Characteristic.EmptyValue) || ReferenceEquals(value, null)) | ||
| { | ||
|
|
@@ -140,53 +142,53 @@ public bool HasValue(Characteristic characteristic) | |
| return false; | ||
| } | ||
|
|
||
| internal T GetValue<[DynamicallyAccessedMembers(CharacteristicMemberTypes)] T>(Characteristic<T> characteristic) | ||
| internal T? GetValue<[DynamicallyAccessedMembers(CharacteristicMemberTypes)] T>(Characteristic<T> characteristic) | ||
| { | ||
| return (T)GetValue((Characteristic)characteristic); | ||
| return (T?)GetValue((Characteristic)characteristic); | ||
| } | ||
|
|
||
| internal object GetValue(Characteristic characteristic) | ||
| internal object? GetValue(Characteristic characteristic) | ||
| { | ||
| if (!sharedValues.TryGetValue(characteristic, out var result)) | ||
| result = Characteristic.EmptyValue; | ||
|
|
||
| return ResolveCore(characteristic, result); | ||
| } | ||
|
|
||
| private object ResolveCore(Characteristic characteristic, object result) | ||
| private object? ResolveCore(Characteristic characteristic, object result) | ||
| { | ||
| return characteristic.ResolveValueCore(this, result); | ||
| } | ||
| #endregion | ||
|
|
||
| #region Resolve | ||
| public T ResolveValue<[DynamicallyAccessedMembers(CharacteristicMemberTypes)] T>(Characteristic<T> characteristic, IResolver resolver) | ||
| public T? ResolveValue<[DynamicallyAccessedMembers(CharacteristicMemberTypes)] T>(Characteristic<T> characteristic, IResolver resolver) | ||
| { | ||
| return resolver.Resolve(this, characteristic); | ||
| } | ||
|
|
||
| public T ResolveValue<[DynamicallyAccessedMembers(CharacteristicMemberTypes)] T>(Characteristic<T> characteristic, IResolver resolver, T defaultValue) | ||
| public T? ResolveValue<[DynamicallyAccessedMembers(CharacteristicMemberTypes)] T>(Characteristic<T> characteristic, IResolver resolver, T defaultValue) | ||
| { | ||
| return resolver.Resolve(this, characteristic, defaultValue); | ||
| } | ||
|
|
||
| public object ResolveValue(Characteristic characteristic, IResolver resolver) | ||
| public object? ResolveValue(Characteristic characteristic, IResolver resolver) | ||
| { | ||
| return resolver.Resolve(this, characteristic); | ||
| } | ||
|
|
||
| public object ResolveValue(Characteristic characteristic, IResolver resolver, object defaultValue) | ||
| public object? ResolveValue(Characteristic characteristic, IResolver resolver, object defaultValue) | ||
| { | ||
| return resolver.Resolve(this, characteristic, defaultValue); | ||
| } | ||
|
|
||
| public T ResolveValue<[DynamicallyAccessedMembers(CharacteristicObject.CharacteristicMemberTypes)] T>(Characteristic<T> characteristic, T defaultValue) | ||
| public T? ResolveValue<[DynamicallyAccessedMembers(CharacteristicObject.CharacteristicMemberTypes)] T>(Characteristic<T> characteristic, T defaultValue) | ||
| { | ||
| return HasValue(characteristic) ? GetValue(characteristic) : (T)characteristic.ResolveValueCore(this, defaultValue); | ||
| return HasValue(characteristic) ? GetValue(characteristic) : (T?)characteristic.ResolveValueCore(this, defaultValue!); | ||
| } | ||
|
|
||
| [PublicAPI] | ||
| public object ResolveValue(Characteristic characteristic, object defaultValue) | ||
| public object? ResolveValue(Characteristic characteristic, object defaultValue) | ||
| { | ||
| return HasValue(characteristic) ? GetValue(characteristic) : characteristic.ResolveValueCore(this, defaultValue); | ||
| } | ||
|
|
@@ -203,16 +205,16 @@ public object ResolveValue(Characteristic characteristic, object defaultValue) | |
| SetValue((Characteristic)characteristic, value); | ||
| } | ||
|
|
||
| internal void SetValue(Characteristic characteristic, object value) | ||
| internal void SetValue(Characteristic characteristic, object? value) | ||
| { | ||
| AssertNotFrozen(); | ||
|
|
||
| if (characteristic.HasChildCharacteristics) | ||
| { | ||
| AssertIsAssignable(characteristic, value); | ||
|
|
||
| var oldObjectValue = (CharacteristicObject)GetValue(characteristic); | ||
| var newObjectValue = (CharacteristicObject)ResolveCore(characteristic, value); | ||
| var oldObjectValue = (CharacteristicObject?)GetValue(characteristic); | ||
| var newObjectValue = (CharacteristicObject?)ResolveCore(characteristic, value!); | ||
|
|
||
| if (!ReferenceEquals(oldObjectValue, newObjectValue)) | ||
| { | ||
|
|
@@ -226,7 +228,7 @@ internal void SetValue(Characteristic characteristic, object value) | |
| } | ||
| } | ||
|
|
||
| private void SetValueCore(Characteristic characteristic, object value) | ||
| private void SetValueCore(Characteristic characteristic, object? value) | ||
| { | ||
| AssertIsAssignable(characteristic, value); | ||
|
|
||
|
|
@@ -243,7 +245,7 @@ private void SetValueCore(Characteristic characteristic, object value) | |
| $"The current node {this} has value for {characteristic} already.", | ||
| nameof(characteristic)); | ||
|
|
||
| var characteristicObject = (CharacteristicObject)ResolveCore(characteristic, value); | ||
| var characteristicObject = (CharacteristicObject)ResolveCore(characteristic, value!)!; | ||
| characteristicObject.SetOwnerCore(OwnerOrSelf); | ||
|
|
||
| sharedValues[characteristic] = characteristicObject; | ||
|
|
@@ -321,7 +323,7 @@ private void SetValueOnAttach(Characteristic characteristic, object value) | |
| if (characteristic.HasChildCharacteristics) | ||
| { | ||
| // DONTTOUCH: workaround on case there were no parent characteristic. | ||
| var characteristicObject = (CharacteristicObject)GetValue(characteristic); | ||
| var characteristicObject = (CharacteristicObject?)GetValue(characteristic); | ||
| characteristicObject?.DetachFromOwner(characteristic); | ||
| } | ||
|
|
||
|
|
@@ -358,13 +360,13 @@ private CharacteristicObject ApplyCore( | |
| { | ||
| if (!HasValue(characteristic)) | ||
| { | ||
| var characteristicObject = (CharacteristicObject)ResolveCore(characteristic, value); | ||
| var characteristicObject = (CharacteristicObject?)ResolveCore(characteristic, value); | ||
| if (characteristicObject != null) | ||
| { | ||
| value = Activator.CreateInstance(characteristicObject.GetType()); | ||
| } | ||
|
|
||
| SetValueCore(characteristic, value); | ||
| SetValueCore(characteristic, value!); | ||
| } | ||
| } | ||
| else | ||
|
|
@@ -399,20 +401,20 @@ protected CharacteristicObject UnfreezeCopyCore() | |
| { | ||
| AssertIsRoot(); | ||
|
|
||
| var newRoot = (CharacteristicObject)Activator.CreateInstance(GetType()); | ||
| var newRoot = (CharacteristicObject)Activator.CreateInstance(GetType())!; | ||
| newRoot.ApplyCore(this); | ||
|
|
||
| // Preserve the IdCharacteristic of the original object | ||
| if (this.HasValue(IdCharacteristic)) | ||
| { | ||
| newRoot.SetValue(IdCharacteristic, this.GetValue(IdCharacteristic)); | ||
| newRoot.SetValue(IdCharacteristic, this.GetValue(IdCharacteristic)!); | ||
| } | ||
|
|
||
| return newRoot; | ||
| } | ||
| #endregion | ||
|
|
||
| public string Id => IdCharacteristic[this]; | ||
| public string Id => IdCharacteristic[this]!; | ||
|
|
||
| public override string ToString() => Id; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It need to allow
nullbecause some characteristics expected to returnnull(e.g. RuntimeCharacteristic/EnvironmentVariablesCharacteristic)