canton7
canton7
CC#
Created by whatsinaname on 11/19/2024 in #help
migrate to .NET 9
6 replies
CC#
Created by on 11/19/2024 in #help
Declaring a struct as a constant
Yeah, there's been some discussion of that, but nothing yet
19 replies
CC#
Created by on 11/19/2024 in #help
Declaring a struct as a constant
The value of a const is baked into the assembly as a literal, and the compiler can't do that for arbitrary types that it doesn't know about
19 replies
CC#
Created by on 11/19/2024 in #help
Declaring a struct as a constant
You can't, not for a local variable
19 replies
CC#
Created by on 11/19/2024 in #help
Declaring a struct as a constant
* Structs can't be const * Readonly only works with fields, not local variablets
19 replies
CC#
Created by Neophyte on 11/18/2024 in #help
How to to dynamically provide T type of a generic method
The problem is, if that interface is generic, how does the caller provide the right T?
105 replies
CC#
Created by Neophyte on 11/18/2024 in #help
How to to dynamically provide T type of a generic method
I.e. the code which uses all of the code snippets pasted above
105 replies
CC#
Created by Neophyte on 11/18/2024 in #help
How to to dynamically provide T type of a generic method
The code which takes a Stream and a file type, gets the right sort of service to deal with that file type, gives it the stream, and gets back a set of DTOs which are specific to that file type
105 replies
CC#
Created by Neophyte on 11/18/2024 in #help
How to to dynamically provide T type of a generic method
The problem is that the caller does not know T, and cannot know T
105 replies
CC#
Created by Neophyte on 11/18/2024 in #help
How to to dynamically provide T type of a generic method
No
105 replies
CC#
Created by Neophyte on 11/18/2024 in #help
How to to dynamically provide T type of a generic method
E.g. in a UI framework, you might have Button and TextBox which inherit from Control. Control exposes the general control-related stuff, but the only code which knows how to lay out and render a button is inside the Button class: that code can be called from anywhere, because the Layout and Render methods are on Control, and are non-generic, etc. You don't have a separate ButtonRenderer service and ButtonData DTO
105 replies
CC#
Created by Neophyte on 11/18/2024 in #help
How to to dynamically provide T type of a generic method
But really, while the service / DTO split is nice and all, encapsulation is really the only neat solution in cases like this
105 replies
CC#
Created by Neophyte on 11/18/2024 in #help
How to to dynamically provide T type of a generic method
Glad I could help a bit!
105 replies
CC#
Created by Neophyte on 11/18/2024 in #help
How to to dynamically provide T type of a generic method
(and you might need to do some encapsulation, where your error info DTO only presents basic info, but can write out more complex info to CSV/JSON/a logger/etc if asked)
105 replies
CC#
Created by Neophyte on 11/18/2024 in #help
How to to dynamically provide T type of a generic method
If that code needs to access error information, figure out how you can present that information in a way that code which doesn't know anything about Azure vs HR can access it
105 replies
CC#
Created by Neophyte on 11/18/2024 in #help
How to to dynamically provide T type of a generic method
I think you've been designing this entirely from the point of view of the data loading services. Switch it around, and figure out what the API should look like from the code which uses those services
105 replies
CC#
Created by Neophyte on 11/18/2024 in #help
How to to dynamically provide T type of a generic method
Yep, because that Type is only known at runtime, but to be able to write code which uses a type, you need to know that type at compile-time
105 replies
CC#
Created by Neophyte on 11/18/2024 in #help
How to to dynamically provide T type of a generic method
In that case, isn't this exactly the problem we've been discussing already? If your IDataLoadingInterface.ParseStreamIntoSystemDto can return literally any type, with no constraints, then of course the calling code can't access that type in any meaningful way
105 replies
CC#
Created by Neophyte on 11/18/2024 in #help
How to to dynamically provide T type of a generic method
So SystemDto isn't actually a type?
105 replies
CC#
Created by Neophyte on 11/18/2024 in #help
How to to dynamically provide T type of a generic method
And ValidatedHrCsvData is a member of SystemDto?
105 replies