Refactored plugin settings handling for maintainability (#515)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2025-06-27 22:52:34 +02:00
1 parent 1b8ed286e7
commit 7df0b3e6e0
3 files changed
+20 -1

No files matched your search

@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
using System.Text.Json;
using AIStudio.Provider;
@@ -347,4 +348,21 @@ public sealed class SettingsManager
return ConfidenceLevel.UNKNOWN;
}
}
public static string ToSettingName<T>(Expression<Func<T, object>> propertyExpression)
{
MemberExpression? memberExpr;
// Handle the case where the expression is a unary expression (e.g., when using Convert):
if (propertyExpression.Body is UnaryExpression { NodeType: ExpressionType.Convert } unaryExpr)
memberExpr = unaryExpr.Operand as MemberExpression;
else
memberExpr = propertyExpression.Body as MemberExpression;
if (memberExpr is null)
throw new ArgumentException("Expression must be a property access", nameof(propertyExpression));
// Return the full name of the property, including the class name:
return $"{typeof(T).Name}.{memberExpr.Member.Name}";
}
}