Skip to content

Commit

Permalink
fix arg extraction logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev committed Jun 17, 2024
1 parent 67cc7ab commit 220f0e2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Tools/DeployApps/BaasClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,8 @@ public static HttpContent GetJsonContent(object obj)
return content;
}

// Extract arguments and populate a type T with the extracted values. Only string readwrite properties
// will be considered.
public static (T Extracted, string[] RemainingArgs) ExtractArguments<T>(string[] args)
where T : new()
{
Expand All @@ -831,12 +833,10 @@ public static (T Extracted, string[] RemainingArgs) ExtractArguments<T>(string[]
throw new ArgumentNullException(nameof(args));
}

var argsToExtract = typeof(T).GetProperties().Select(p => (ArgName: GetArgName(p.Name), PropertyInfo: p)).ToArray();
var invalidProps = argsToExtract.Where(p => p.PropertyInfo != typeof(string) || !p.PropertyInfo.CanRead || !p.PropertyInfo.CanWrite).ToArray();
if (invalidProps.Length != 0)
{
throw new ArgumentException($"Invalid properties: {string.Join(", ", invalidProps.Select(p => p.PropertyInfo.Name))}");
}
var argsToExtract = typeof(T).GetProperties()
.Where(p => p.PropertyType == typeof(string) && p is { CanRead: true, CanWrite: true })
.Select(p => (ArgName: GetArgName(p.Name), PropertyInfo: p))
.ToArray();

var extracted = new T();
return (extracted, args.Where(a => !argsToExtract.Any(kvp => ExtractArg(a, kvp))).ToArray());
Expand Down

0 comments on commit 220f0e2

Please sign in to comment.