Anarchist
Anarchist
CC#
Created by Anarchist on 2/7/2024 in #help
Deserialise part of a json response
Thanks, I've got it working with "root" and "product" classes, where Root has a List<Product> Response and Product the desired attributes. A little bloated, but it seems to work.
12 replies
CC#
Created by Anarchist on 2/7/2024 in #help
Deserialise part of a json response
At the moment I keep getting null
12 replies
CC#
Created by Aadarsh on 8/10/2023 in #help
❔ what do large scale enterprise level applications use?
Our companies policy is to use Angular, but my particular product is in React because it precedes this preference. I’m not entirely sure why they chose angular over react but I understand their desire to have everyone using one framework for easier component reuse and collaboration.
39 replies
CC#
Created by Anarchist on 12/12/2022 in #help
❔ Are TryAsync methods acceptable?
Hmm yeah perhaps this is too problematic, I might just drop the async approach since atm it's a single threaded console app
10 replies
CC#
Created by Anarchist on 12/12/2022 in #help
❔ Are TryAsync methods acceptable?
For context, this is the class. It's a FIleLoader where the user has the option to load a file async or synchronously.
internal class FileLoader : ILoader<string?>, IAsyncLoader<string>
{
private readonly string _path;

public FileLoader(string path)
{
_path = path;
}

public bool TryLoad(out string? data)
{
return TryDoLoad(path => File.ReadAllText(path), out data);
}

public bool TryLoadAsync(out Task<string>? data)
{
return TryDoLoad(path => File.ReadAllTextAsync(path), out data);
}

// Used so reading can optionally be async whilst reusing the rest DoLoad
private delegate T ReadFileFunc<out T>(string path);

private bool TryDoLoad<T>(ReadFileFunc<T?> read, out T? data)
{
data = default;
try
{
data = read.Invoke(_path);
return true;
}
catch (FileNotFoundException ex)
{
Console.WriteLine($"Could not find file at {_path}");
Console.WriteLine(ex);
}
catch (IOException ex)
{
Console.WriteLine($"Failed to read file at {_path}");
Console.WriteLine(ex);
}

return false;
}
}
internal class FileLoader : ILoader<string?>, IAsyncLoader<string>
{
private readonly string _path;

public FileLoader(string path)
{
_path = path;
}

public bool TryLoad(out string? data)
{
return TryDoLoad(path => File.ReadAllText(path), out data);
}

public bool TryLoadAsync(out Task<string>? data)
{
return TryDoLoad(path => File.ReadAllTextAsync(path), out data);
}

// Used so reading can optionally be async whilst reusing the rest DoLoad
private delegate T ReadFileFunc<out T>(string path);

private bool TryDoLoad<T>(ReadFileFunc<T?> read, out T? data)
{
data = default;
try
{
data = read.Invoke(_path);
return true;
}
catch (FileNotFoundException ex)
{
Console.WriteLine($"Could not find file at {_path}");
Console.WriteLine(ex);
}
catch (IOException ex)
{
Console.WriteLine($"Failed to read file at {_path}");
Console.WriteLine(ex);
}

return false;
}
}
10 replies
CC#
Created by Anarchist on 12/12/2022 in #help
❔ Are TryAsync methods acceptable?
It doesn't have to be, I've got an ILoad and an IAsyncLoad that some classes implement both of so down the line I have the option. It also doesn't have to be a try method, but if there's no issues I think it's a good idea
10 replies