Comments (5)
My suggestion would probably be to change it inline as follows:
public static User From(Dictionary<string, object> map)
{
return new User(
id: map["$id"].ToString(),
createdAt: map["$createdAt"].ToString(),
updatedAt: map["$updatedAt"].ToString(),
name: map["name"].ToString(),
password: map.TryGetValue("password", out var password) ? password.ToString() : null,
hash: map.TryGetValue("hash", out var hash) ? hash.ToString() : null,
hashOptions: map.TryGetValue("hashOptions", out var hashOptions) ? hashOptions.ToString() : null,
registration: map["registration"].ToString(),
status: (bool)map["status"],
labels: ((JArray)map["labels"]).ToObject<List<object>>(),
passwordUpdate: map["passwordUpdate"].ToString(),
email: map["email"].ToString(),
phone: map["phone"].ToString(),
emailVerification: (bool)map["emailVerification"],
phoneVerification: (bool)map["phoneVerification"],
prefs: Preferences.From(((JObject)map["prefs"]).ToObject<Dictionary<string, object>>()),
accessedAt: map["accessedAt"].ToString());
}
So we would not need to add an extra function. And I would use named parameters when creating the User
-object. Having positional arguments is confusing if the list is so long and not readable. ;)
from sdk-for-dotnet.
Discussion on Discord: https://discord.com/channels/564160730845151244/564160731327758347/1192519235017113600
from sdk-for-dotnet.
My quick fix was this on User.cs. Open to better solution. I only identified as potential "nulls" password, hash and hashOptions. I don't know whether all other fields are always populated for every user account.
private static object? getFromMap(Dictionary<string, object> map, string key)
{
object? val;
map.TryGetValue("password",out val);
return val;
}
public static User From(Dictionary<string, object> map) {
return new User(
id: map["$id"].ToString(),
createdAt: map["$createdAt"].ToString(),
updatedAt: map["$updatedAt"].ToString(),
name: map["name"].ToString(),
password: getFromMap(map,"password")?.ToString(),
hash: getFromMap(map,"hash")?.ToString(),
hashOptions: getFromMap(map,"hashOptions")?.ToString(),
registration: map["registration"].ToString(),
status: (bool)map["status"],
labels: ((JArray)map["labels"]).ToObject<List>(),
passwordUpdate: map["passwordUpdate"].ToString(),
email: map["email"].ToString(),
phone: map["phone"].ToString(),
emailVerification: (bool)map["emailVerification"],
phoneVerification: (bool)map["phoneVerification"],
prefs: Preferences.From(map: ((JObject)map["prefs"]).ToObject<Dictionary<string, object>>()!),
accessedAt: map["accessedAt"].ToString()
);
}
from sdk-for-dotnet.
Thanks for your quick fix, but I think your getFromMap
is not implemented as desired.
You implemented a hardcoded value "password"
in TryGetValue
. I guess instead it should be:
map.TryGetValue(key,out val);
A more compact version would be:
private static object? getFromMap(Dictionary<string, object> map, string key)
{
return map.TryGetValue(key, out var val) ? val.toString() : null;
}
from sdk-for-dotnet.
Thanks for your quick fix, but I think your
getFromMap
is not implemented as desired. You implemented a hardcoded value"password"
inTryGetValue
. I guess instead it should be:map.TryGetValue(key,out val);A more compact version would be:
private static object? getFromMap(Dictionary<string, object> map, string key) { return map.TryGetValue(key, out var val) ? val.toString() : null; }
yep, I hardcoded for testing "password" and forgot to remove it. Glad there is a fix already on the way.
from sdk-for-dotnet.
Related Issues (11)
- Potential memory leak and deferred garbage collection cycle identified HOT 5
- GetFileDownload returns a string without Project parameter. HOT 3
- Upgrade our issue templates to use GitHub issue forms ✍️ HOT 13
- 📚 Documentation: HOT 1
- 🚀 Feature: Support GA Release HOT 4
- 📚 Documentation: How to use the dotnet SDK? HOT 5
- 🚀 Feature: Proposal for Building a separate API SDK - "Appwrite.Core" for Modern .NET Version (6+ onwards) Using Refit, System.Text, and HttpClientFactory HOT 4
- 🐛 Bug Report: query.limit unnoticed
- 🚀 Feature: Auto Serialize payload when creating a document
- 🐛 Bug Report: Updating attributes doesn't allow null defaults, min, max etc
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdk-for-dotnet.