@@ -7,28 +7,32 @@ namespace CommandLine.Helpers;
77
88public  static class  SupabasePatchHelper 
99{ 
10+     // Applies a "SET" operation to the table, setting the value of a specific property. 
1011    public  static IPostgrestTable < T >  ApplySet < T > ( 
11-         IPostgrestTable < T >  table , 
12-         string  jsonPropertyName , 
13-         object  value 
14-     )  where  T  :  BaseModel ,  new ( ) 
12+         IPostgrestTable < T >  table ,   // The table to apply the operation to 
13+         string  jsonPropertyName ,    // The name of the JSON property to update 
14+         object  value                // The new value to set for the property 
15+     )  where  T  :  BaseModel ,  new ( )   // Ensures T is a subclass of BaseModel with a parameterless constructor 
1516    { 
16-         // Find the property that matches the JsonProperty  name 
17+         // Find the property on the model  that matches the JSON property  name 
1718        var  property  =  typeof ( T ) 
18-             . GetProperties ( ) 
19+             . GetProperties ( )    // Get all properties of the model type 
1920            . FirstOrDefault ( p => 
21+                 // Check if the property has a JsonPropertyAttribute 
2022                p . GetCustomAttributes ( typeof ( JsonPropertyAttribute ) ,  true ) 
2123                . FirstOrDefault ( )  is  JsonPropertyAttribute  attr  && 
22-                 attr . PropertyName  ==  jsonPropertyName ) ; 
24+                 attr . PropertyName  ==  jsonPropertyName ) ;    // Check if the JSON property name matches 
2325
2426        if  ( property  ==  null ) 
2527            throw  new  ArgumentException ( $ "'{ jsonPropertyName } ' is not a valid property on type '{ typeof ( T ) . Name } '") ; 
2628
27-         var  parameter  =  Expression . Parameter ( typeof ( T ) ,  "x" ) ; 
28-         var  propertyAccess  =  Expression . Property ( parameter ,  property . Name ) ; 
29-         var  converted  =  Expression . Convert ( propertyAccess ,  typeof ( object ) ) ; 
30-         var  lambda  =  Expression . Lambda < Func < T ,  object > > ( converted ,  parameter ) ; 
29+         // Create an expression to access the specified property on the model 
30+         var  parameter  =  Expression . Parameter ( typeof ( T ) ,  "x" ) ;  // Define a parameter for the expression 
31+         var  propertyAccess  =  Expression . Property ( parameter ,  property . Name ) ;  // Access the property 
32+         var  converted  =  Expression . Convert ( propertyAccess ,  typeof ( object ) ) ;  // Convert the value to object type 
33+         var  lambda  =  Expression . Lambda < Func < T ,  object > > ( converted ,  parameter ) ;  // Create a lambda expression for the property 
3134
35+         // Apply the "SET" operation to the table using the lambda expression 
3236        return  table . Set ( lambda ,  value ) ; 
3337    } 
34- } 
38+ } 
0 commit comments