TheBoxyBear
TheBoxyBear
CC#
Created by TheBoxyBear on 2/10/2024 in #help
✅ Release slower than Debug
I'm doing some benchmarks on two async methods and strangely for both, they consistently have twice the execution time on Release vs Debug. I have the default project settings regarding configurations and sadly I can't share the code but I'd like some clues at what could cause such issues in general as I couldn't find much info
19 replies
CC#
Created by TheBoxyBear on 1/11/2023 in #help
❔ Populating existing instances
I'm migrating from Newtonsoft to System.Text.Json but my model uses a property in the json to determine the runtime type of the object from a common base type. This article mentions that new instances are always created but that custom converters can populate an existing instance but I can't find how to do that anywhere. https://learn.microsoft.com/dotnet/standard/serialization/system-text-json/migrate-from-newtonsoft?pivots=dotnet-7-0#populate-existing-objects
3 replies
CC#
Created by TheBoxyBear on 10/27/2022 in #help
Linq Concat not defined?
var result = mappings.Where(m => m.Difficulty != Content.Difficulty).Concat(newMappings); I have Linq in my usings and setting result to only Where compiles but when I append Concat, it's saying IEnumerable<> has no definition for Concat. The types of mappings and newMappints are the same and I get recommended Concat when I type it.
16 replies
CC#
Created by TheBoxyBear on 9/18/2022 in #help
Bridging the gap between Linq expression trees and Roslyn parse
Trying to make a script generator that converts C# code and so far I'm using Linq expressions for that but unfortunately, it only allows single line lambdas even though the expression model seems to support full on methods with locals and loops etc. I've been looking into using actual methods compiled with CodeDom instead but ideally I want to support both so the user can define simple expressions without having to export anything to be read with CodeDom. Is there any bult-in way of converting between a Linq expression tree and a CodeDom expression? If not, that would mean I have to parse both types to generate scripts.
6 replies
CC#
Created by TheBoxyBear on 9/14/2022 in #help
Emitting classes with TypeBuilder [Answered]
The idea is to have certain primitive properties bound to a type through an attribute. The user of the library can create the type and bind it or use a different attribute that creates the type automatically and adds the previously mentioned attribute with that new type. I know it's much slower, but it would be a good option to have for simple prototyping. So I found TypeBuilder.CreateType https://docs.microsoft.com/en-us/dotnet/api/system.reflection.emit.typebuilder.createtype?view=net-6.0 but the method isn't static and TypeBuilder has no constructors. The example in the docs gets an instance through some other objects and it all starts with AppDomain.DefineDynamicAssembly which for some reason I don't have despite being on .net 6 with all the same usings as in the example.
5 replies
CC#
Created by TheBoxyBear on 9/9/2022 in #help
Confused about interface default implementations [Answered]
Trying out default implementations for methods in the interfaces for the first time. In the interface there's a public method that if I define in a class, that class implementation is used. However, the second method is the same concept but when called, the default implementation from the interface is called instead. I found out it has to do with the method being internal instead of public but why does it work like that?
11 replies
CC#
Created by TheBoxyBear on 8/31/2022 in #help
Accidentally merged untested code in the stable branch, can't find the merge to revert [Answered]
Title explains it. https://github.com/TheBoxyBear/charttools I accidentally merged beta into stable which included nearly 100 commits. I can see other merges that were done in the commit history but not the last one yet the merge did happen and all the files are in the branch.
43 replies