Not Mark
Not Mark
CC#
Created by blast2857 on 4/7/2024 in #help
Static helper class/method design question
As for the caching logic, I don't really see a problem with it as long as you know the types for a given path wouldn't change during runtime.
7 replies
CC#
Created by blast2857 on 4/7/2024 in #help
Static helper class/method design question
For testability's sake, I'd personally make this a non-static class with an interface (with _pathCache being a non-static field). You can then register this class as a singleton to be injected into your other classes. Then for the FillCache method, you can either call that in the constructor (although typically you would avoid complex logic like that in a constructor) or maybe call it when registering your class.
7 replies
CC#
Created by Gecko on 2/9/2024 in #help
405 Method Not Allowed
From the error it sounds like whatever endpoint you're trying to hit doesn't support whatever http method you're sending.
_http.PostAsJsonAsync("api/permit", permit);
_http.PostAsJsonAsync("api/permit", permit);
This suggests you're sending a POST, but does that endpoint actually support a POST? Or if it does, does the PostAsJsonAsync method actually send it as a POST?
8 replies
CC#
Created by Dawnbomb on 2/27/2023 in #help
❔ ✅ Help with searching a class of classes for something?
Assuming you have this sort of structure:
public EntryClass
{
public string Name { get; set; }
public string SomethingSpecial { get; set; }
}

public MiddleClass
{
public List<EntryClass> EntryClasses { get; set; }
}

public StartingClass
{
public List<StartingClass> MiddleClasses { get; set; }
}
public EntryClass
{
public string Name { get; set; }
public string SomethingSpecial { get; set; }
}

public MiddleClass
{
public List<EntryClass> EntryClasses { get; set; }
}

public StartingClass
{
public List<StartingClass> MiddleClasses { get; set; }
}
Then you would need to iterate over over every MiddleClass inside of StartingClass's list, and inside each one of those MiddleClass object, iterate over that list until you find your target. So something like:
public EntryClass FindTarget(StartingClass startingClass, string nameTarget)
{
foreach (var middleClass in startingClass.MiddleClasses)
{
foreach (var entryClass in middleClass.EntryClasses)
{
if (entryClass.Name == nameTarget)
return entryClass;
}
}

// we have iterated over every possible EntryClass and none had the "nameTarget"
return null;
}
public EntryClass FindTarget(StartingClass startingClass, string nameTarget)
{
foreach (var middleClass in startingClass.MiddleClasses)
{
foreach (var entryClass in middleClass.EntryClasses)
{
if (entryClass.Name == nameTarget)
return entryClass;
}
}

// we have iterated over every possible EntryClass and none had the "nameTarget"
return null;
}
If the nesting of your classes is more "deep" you would just add more for loops.
4 replies
CC#
Created by Pacrombie on 1/31/2023 in #help
❔ Singleton Pattern StackOverflowException
Happy to help! 🙂
12 replies
CC#
Created by Pacrombie on 1/31/2023 in #help
❔ Singleton Pattern StackOverflowException
Correct
12 replies
CC#
Created by Pacrombie on 1/31/2023 in #help
❔ Singleton Pattern StackOverflowException
Your Instance property checks if Instance (itself) is null, but that only calls the Instance getter which you are already in
12 replies
CC#
Created by Pacrombie on 1/31/2023 in #help
❔ Singleton Pattern StackOverflowException
Declare a private _instance field and have your Instance getter and setter get/set the field instead of getting and setting itself.
12 replies
CC#
Created by warden161 🍉 on 12/30/2022 in #help
Text.Json Error
You could try that. I find it odd though that the API you're interacting with is giving quotes wrapping the whole json in the response though
53 replies
CC#
Created by warden161 🍉 on 12/30/2022 in #help
Text.Json Error
I guess there are several ways to handle this. One way is to read the string response.Content and manually remove the " quotes at the beginning and end, and then deserialize. You could also deserialize response.Content into a string first and then deserialize that string into your Player[]. I just tested this way and it seems to work. I don't know if that's the best way of handling that though... lol
53 replies
CC#
Created by warden161 🍉 on 12/30/2022 in #help
Text.Json Error
So it's taking a string representing a string literal which represents your json instead of just taking the string of your json
53 replies
CC#
Created by warden161 🍉 on 12/30/2022 in #help
Text.Json Error
What I'm guessing is what is happening is it's trying to deserialize "[{your_object}]" as a list of players instead of just [{your_object}] as a list of players.
53 replies
CC#
Created by warden161 🍉 on 12/30/2022 in #help
Text.Json Error
I think it's the end of the string when I tested it
53 replies
CC#
Created by warden161 🍉 on 12/30/2022 in #help
Text.Json Error
But I think that's not the original issue you had?
53 replies
CC#
Created by warden161 🍉 on 12/30/2022 in #help
Text.Json Error
well that specific case you can't because the json represents a list of players
53 replies
CC#
Created by warden161 🍉 on 12/30/2022 in #help
Text.Json Error
Can you do me a favor and copy and paste your Player model? I'm just trying to test it on my end to replicate your issue
53 replies
CC#
Created by warden161 🍉 on 12/30/2022 in #help
Text.Json Error
How is it read in? Is it just hard coded in the same way your exampleData in the screenshot is shown?
53 replies
CC#
Created by warden161 🍉 on 12/30/2022 in #help
Text.Json Error
This might just be a copy-paste thing, but is there an end quote on the original json? Where are you reading the original json from? I copied the original and replaced the \" with just a " and it seems like valid json ignoring the starting "
53 replies