Skip to content

Simplify code for reading/writing settings#81516

Merged
CyrusNajmabadi merged 3 commits intodotnet:mainfrom
CyrusNajmabadi:settingsSimplification3
Dec 2, 2025
Merged

Simplify code for reading/writing settings#81516
CyrusNajmabadi merged 3 commits intodotnet:mainfrom
CyrusNajmabadi:settingsSimplification3

Conversation

@CyrusNajmabadi
Copy link
Contributor

Followup to #81515


protected bool TryFetchWorker(OptionKey2 optionKey, string storageKey, Type optionType, out object? value)
{
var result = TryReadAndMonitorOptionValue(optionKey, storageKey, storageKey, optionType, optionKey.Option.DefaultValue);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we passed this value along just to do a type check and call into a helper method. but we can determine that from the optionType passed in.

return default;
}

if (defaultValue is ICodeStyleOption2 codeStyle)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the only actual use of defaultValue. Note: i very VERY much want this value gone because it's very tempting to return that value in the case of failure. But that's not the behavior we want. we want to actually return nothing as the final high level caller needs to know if needs to go to the next persister.

so this makes sure that mistake can't happen (which i s something i did, but fortunately had a test catch).

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review December 2, 2025 21:48
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner December 2, 2025 21:48
@CyrusNajmabadi
Copy link
Contributor Author

@JoeRobich this is ready for review. tnx.

try
{
return new Optional<object?>(codeStyle.FromXElement(XElement.Parse(value)));
var fromXElementMember = storageType.GetMethod(nameof(CodeStyleOption2<>.FromXElement), BindingFlags.Public | BindingFlags.Static);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been taught to be wary of reflection. Is this something that runs frequently or only on start up and when an option's value changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. these values, once read, are cached in the higher level construct. then we only clear that cached value when we get a notification that the value changed, and we only refetch it at that point.

@CyrusNajmabadi CyrusNajmabadi merged commit 77dcf20 into dotnet:main Dec 2, 2025
25 of 26 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the settingsSimplification3 branch December 2, 2025 23:20
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Dec 2, 2025
@davidwengier davidwengier modified the milestones: Next, 18.3 Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants