Skip to content

Modernize DynamoModel.cs to C# 12 idioms#16880

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/clean-up-dynamomodel-cs
Draft

Modernize DynamoModel.cs to C# 12 idioms#16880
Copilot wants to merge 4 commits intomasterfrom
copilot/clean-up-dynamomodel-cs

Conversation

Copy link
Contributor

Copilot AI commented Feb 7, 2026

Janitorial cleanup applying modern C# 12 language features to DynamoModel.cs for improved readability and maintainability. No functional changes.

Changes Applied

  • Collection expressions: new List<T>()[], new Dictionary<K,V>()[] or new() for field initializers (21 instances)
  • Pattern matching: var x = obj as Type; if (x != null)if (obj is Type x) (5 instances)
  • String interpolation: Replaced concatenation and string.Format with $"" syntax (9 instances)

Example

- var extensions = new List<IExtension>();
+ List<IExtension> extensions = [];

- var logSource = ext as ILogSource;
- if (logSource != null)
+ if (ext is ILogSource logSource)
    logSource.MessageLogged -= LogMessage;

- Logger.Log(Resources.BackupSavedMsg + ": " + savePath);
+ Logger.Log($"{Resources.BackupSavedMsg}: {savePath}");

Impact: 110 lines modified (53 insertions, 55 deletions), net -2 lines. All changes preserve existing semantics and maintain backward compatibility.

Original prompt

Clean up DynamoModel.cs in this repo

Custom agent used: C#/.NET Janitor
Perform janitorial tasks on C#/.NET code including cleanup, modernization, and tech debt remediation.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 7, 2026 14:36
Co-authored-by: QilongTang <3942418+QilongTang@users.noreply.github.com>
…DynamoModel.cs

Co-authored-by: QilongTang <3942418+QilongTang@users.noreply.github.com>
Co-authored-by: QilongTang <3942418+QilongTang@users.noreply.github.com>
Copilot AI changed the title [WIP] Clean up DynamoModel.cs in the repository Modernize DynamoModel.cs to C# 12 idioms Feb 7, 2026
Copilot AI requested a review from QilongTang February 7, 2026 14:42
@QilongTang QilongTang added the WIP label Feb 7, 2026
private WorkspaceModel currentWorkspace;
private Timer backupFilesTimer;
private Dictionary<Guid, string> backupFilesDict = new Dictionary<Guid, string>();
private Dictionary<Guid, string> backupFilesDict = new();
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 7, 2026

if (trustedLoc.StartsWith(programDataPath))
{
Logger.Log(("An unsafe path has been detected in Trusted Locations: " + trustedLoc));
Logger.Log($"An unsafe path has been detected in Trusted Locations: {trustedLoc}");

Check failure

Code scanning / CodeQL

Clear text storage of sensitive information High

This stores sensitive data returned by
call to method SelectSingleNode : XmlNode
as clear text.
This stores sensitive data returned by
call to method DeserializeTrustedLocations : List
as clear text.
This stores sensitive data returned by
access to local variable trustedLoc : String
as clear text.
This stores sensitive data returned by
access to local variable trustedLoc : String
as clear text.

Copilot Autofix

AI about 1 month ago

In general, to fix clear-text storage issues in logs, you either (a) avoid logging the sensitive value at all, or (b) log only a redacted/derived form (such as a hash, prefix, or generic tag) that is sufficient for diagnostics without exposing the original value. For filesystem paths coming from user-controlled configuration, you typically only need to indicate that a problematic path exists and maybe show a minimally identifying portion, not the entire absolute path.

For this specific case, the best fix that preserves existing functionality is to avoid logging the full trusted location path and instead log only a safe, truncated representation. We can transform trustedLoc before passing it to Logger.Log, e.g. by logging only the last directory segment or a redacted form such as "...\folder" or "[redacted]". This keeps the information that an unsafe path exists and roughly which entry it is, while no longer storing the full user path in clear text. We only need to change the logging line in DynamoModel.cs; the rest of the flow (loading and storing trusted locations in memory and XML) is outside the identified sink and should remain unchanged.

Concretely, in src/DynamoCore/Models/DynamoModel.cs, within the constructor (or initialization method) near lines 1038–1045, replace

Logger.Log($"An unsafe path has been detected in Trusted Locations: {trustedLoc}");

with a version that uses a safe representation of trustedLoc. A simple approach that requires no new imports is to derive a short identifier, such as the last path component using Path.GetFileName(trustedLoc.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)), and log that instead. However, we must not add new imports other than standard ones, and System.IO is already imported at the top of the file, so we can safely use Path. We will compute a safeLocationDescription inline and use that in the log message. This change affects only DynamoModel.cs; no changes are required in PreferenceSettings.cs for this particular sink.


Suggested changeset 1
src/DynamoCore/Models/DynamoModel.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/DynamoCore/Models/DynamoModel.cs b/src/DynamoCore/Models/DynamoModel.cs
--- a/src/DynamoCore/Models/DynamoModel.cs
+++ b/src/DynamoCore/Models/DynamoModel.cs
@@ -1040,7 +1040,8 @@
             {
                 if (trustedLoc.StartsWith(programDataPath))
                 {
-                    Logger.Log($"An unsafe path has been detected in Trusted Locations: {trustedLoc}");
+                    var safeLocationDescription = Path.GetFileName(trustedLoc.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar));
+                    Logger.Log($"An unsafe path has been detected in Trusted Locations. Entry: {safeLocationDescription}");
                 }
             }        
         }
EOF
@@ -1040,7 +1040,8 @@
{
if (trustedLoc.StartsWith(programDataPath))
{
Logger.Log($"An unsafe path has been detected in Trusted Locations: {trustedLoc}");
var safeLocationDescription = Path.GetFileName(trustedLoc.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar));
Logger.Log($"An unsafe path has been detected in Trusted Locations. Entry: {safeLocationDescription}");
}
}
}
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants