Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/PocketBaseClient.CodeGenerator/Generation/ItemInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ public override void UpdateWith(ItemBase itemBase)
: base(id, created, updated)
{{");
foreach (var field in Fields)
sb.AppendLine($@" {field.PropertyName} = {GetParameterNameForConstructor(field)};");
sb.AppendLine($@" this.{field.PropertyName} = {GetParameterNameForConstructor(field)};");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

field.PropertyName and GetParameterNameForConstructor(field) are mostly the same.
So I added this in front of property name.

sb.AppendLine($@"
AddInternal(this);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

AddInternal must be called at the end of JSON constructor because AddInternal isn't updating the reference of a item in the cache, but updating the each values of the item.

}}
#endregion");

Expand Down
2 changes: 1 addition & 1 deletion src/PocketBaseClient/Extensions/PocketBaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static void Send(this PocketBase pocketBase, string path, HttpMethod met
response.EnsureSuccessStatusCode();

using (var stream = response.Content.ReadAsStream())
return JsonSerializer.Deserialize<T>(stream);
return JsonSerializer.Deserialize<T>(stream, new JsonSerializerOptions(JsonSerializerDefaults.Web));
}
catch (Exception ex)
{
Expand Down
5 changes: 3 additions & 2 deletions src/PocketBaseClient/Orm/ItemBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,13 @@ public ItemBase()
[JsonConstructor]
public ItemBase(string? id, DateTime? created, DateTime? updated)
{
Id = id;
_Id = id;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Use _Id rather than Id to avoid AddInternal being called at this point.
AddInternal must be called at the end of JSON constructor.

Created = created;
Updated = updated;
Metadata_.SetLoaded();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This line is also required to avoid redundant update of the item.

}

//protected object? AddInternal(object? element) => Collection.AddInternal(element);
protected object? AddInternal(object? element) => Collection.AddInternal(element);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Collection.AddInternal is internal method. Exposing it for derived classes.


/// <inheritdoc />
public override string ToString()
Expand Down