Sidebar

C Sharp

csharp
C Sharp DrDeadCrash 1 month ago 94%
Option Result library for c#

A collection of tools for dealing with nulls, failures and the generic type issues that arise in this domain. https://github.com/Andy3432344/SafeResults I'm the author, let me know what you think! *Edit: updated to show GitHub link, sorry!

17
13
csharp
C Sharp SmartmanApps 2 months ago 86%
Only Anders can C#
31
6
csharp
C Sharp Spyros 2 months ago 94%
A proposal for type unions (aka discriminated unions) in C# github.com

From [the meeting minutes](https://github.com/dotnet/csharplang/blob/main/meetings/2024/LDM-2024-07-24.md): >First up today, the discriminated unions working group presented the proposal they've been working on for a while to the broader LDM. This was a broad overview session, rather than a deep dive into nitty-gritty questions; there are still plenty of little details that will need to be filled in, but we're cautiously optimistic about this proposal and moving forward with it. There was some concern about some of the ternary behavior, but we can dig more into that as we bring this proposal back for detailed follow ups in the future.

17
0
csharp
C Sharp Cyno 2 months ago 100%
Question regarding generic type and Type

Let's say I have a method that I want to make generic, and so far it had a big switch case of types. For an simplified example, ```csharp switch (field.GetType()) { case Type.Int: Method((int)x)... case Type.NullInt: Method((int?)x)... case Type.Long: Method((long)x)... ``` I'd like to be able to just call my GenericMethod<T>(field) instead and I'm wondering if this is possible and how would I go around doing it. ```csharp GenericMethod(field) public void GenericMethod<T>(T field) ``` Can I use reflection to get a type and the pass it into the generic method somehow, is it possible to transform Type into <T>? Can I have a method on the field object that will somehow give me a <T> type for use in my generic method? Sorry for a confusing question, I'm not really sure how to phrase it correctly, but basically I want to get rid of switch cases and lots of manual coding when all I need is just the type (but that type can't be passed as generic from parent class)

5
8
csharp
C Sharp bluestarshield 5 months ago 100%
C# workbook recommendations?

Hi all. I've been wanting to get into programming for a while now, specifically C#. However, I am not good at self-study or self-guided learning. Are there any good textbooks/workbooks that you'd recommend to learners of C# as a first programming language? I have *some* experience with coding, but not much more than simple command-line calculators (due to aforementioned lack of self-teaching skills). To clarify, I'm looking for a straightforward textbook where I could read a chapter and do the associated "exercises" (for lack of a better word)

13
1
csharp
C Sharp notnotmike 6 months ago 100%
Opinions needed: Best way to develop NuGet packages

My favorite way to develop applications is microservices, or at least smaller services that can separate concerns a little bit. In our current application, there is an API we've created with an OAS document and an auto-generated .NET SDK based on the document. We then have a web console that makes calls to the backend API using the SDK and, ideally, customers would also use the SDK. So my question to everyone is: what is the best "flow" to develop a NuGet package? Currently, we have pipelines which publish the NuGet package of the SDK to our internal NuGet repository on every commit within a merge request. We have a manually incrementing semver with an additional build number tacked on (for example `1.2.3+abc123`). Now this works pretty well, but we often run into problems where a tester's NuGet doesn't pull down the latest version based on the build number if it detects it has the proper semver number. For example, if we create `1.2.3+abc456` NuGet won't pull down this version as long as it has the original `1.2.3+abc123` in its `.nuget/packages` directory. Testers and developers have to manually delete the version from the packages directory and do a fresh restore. So, is there a better way to do build numbers? Or should I be deleting the NuGet package from the private repository every time (doesn't sound ideal...)? The other part of this question is what is the best way to develop and test NuGet packages locally? My current flow is a PowerShell script which will create the new `.nupkg` file, publish it to a local/filesystem NuGet directory with some random semver number (i.e., `9.9.9`), update the `.csproj` with the version (temporarily), and then do a fresh `dotnet restore` on the target project. However, this can be cumbersome and feels like something that should be built into the `dotnet` command. Am I missing something, or is this really the best way to develop locally?

12
5
csharp
C Sharp Eezyville 7 months ago 95%
Farewell to the .NET Foundation · AvaloniaUI Avalonia · Discussion #14666 github.com

[Twitter Link](https://twitter.com/AvaloniaUI/status/1759942133316809084) I personally like Avalonia and I hope this decision is for the best. But at the same time I don't know the benefits or disadvantages of being part of the .Net Foundation.

21
1
csharp
C Sharp SmartmanApps 7 months ago 100%
Build Levels.fyi in DotNet! - How To Use Google Sheets API in C# https://www.youtube.com/watch?v=HDl9DrAtWsU

cross-posted from: https://programming.dev/post/10028855 > [Build Levels.fyi in DotNet! - How To Use Google Sheets API in C#](https://www.youtube.com/watch?v=HDl9DrAtWsU)

6
0
csharp
C Sharp SmartmanApps 7 months ago 100%
MAUI 8.06 Windows Flyout "Element is already the child of another element"

cross-posted from: https://programming.dev/post/9780587 > In MAUI 8.03 we had the Flyout bug where the NavigationPage Title wouldn't update from the first page you had been on. In MAUI 8.06 that bug has been fixed but has introduced a new one on Windows (sigh). > > Starting on Page1 I can use the Flyout to switch to Page2. Then, on Windows, if I use Flyout to switch back to already-existing Page1 it crashes with... > > ``` > System.Runtime.InteropServices.COMException (0x800F1000): No installed components were detected. > > Element is already the child of another element > ``` > > It works on Android, and it works if you are creating a new page each time, it just doesn't work on Windows to switch back to an already-created page (which defeats the whole purpose of having a Flyout menu - switch between 2 pages without making a new one every time). > > 1. Does anyone know of a workaround to this? I can't find anything that relates to this in the context of a MAUI Flyout. > 2. Does anyone have a real simple Flyout template that could be used for the repro (to put in the issue I'm gonna need to create). The one I'm working on has a whole bunch of my own libraries in it, so I'm gonna need to tear them all out before I can use it to make a repro (and of course they don't provide a template, and their sample doesn't work due to different bugs - sigh).

4
2
csharp
C Sharp SmartmanApps 8 months ago 100%
Brisbane-based dotnet role

cross-posted from: https://programming.dev/post/9650331 > Just had this pop up in my Mastodon feed, if we have any Brisbane-based dotnet engineers in the job market here [eigenmagic.net/@arichtman/111883866093603121](https://eigenmagic.net/@arichtman/111883866093603121)

8
0
csharp
C Sharp pips34 8 months ago 100%
Suggestions on a design pattern for logging in .NET?

Hello! I'm starting a personal project in .NET. For a logging solution, I want to achieve something similar to what I have in a Python REST API I wrote a while back using the decorator pattern (example in the image). In the example, the outter "log" function receives the logger I want to use, the decorator function receives a function and returns the decorated function ready to be called (this would be the decorator), and the wrapper function receives the same arguments as the function to be decorated (which is a generic (*args, **kwargs) ofc, because it's meant to decorate any function) and returns whatever the return type of the function is (so, Any). In lines 17 - 24 I just call the passed in "func" with the passed in arguments, but in between I wrap it in a try except block and log that the function with name `func.__name__` started or finished executing. In practice, using this decorator in Python looks like this: ``` import logging from my.decorator.module import log _logger = logging.getLogger(__name__) @log(_logger) def my_func(arg1: Arg1Type, arg2: Arg2Type) -> ReturnType: ... ``` Ofc it's a lot simpler in Python, however I was wondering if it would be possible or even recommended to attempt something similar in C#. I wouldn't mind having to call the function and wrap it manually, something like this: `return RunWithLogs(MyFunction, arg1, arg2);` What I do want to avoid is manually writing the log statements inside the service's business logic, or having to write separate wrappers for each method I want to log. Would be nice to have one generic function or class that I can somehow plug-in to any method and have it log when the call starts and finishes. Any suggestions? Thanks in advance.

13
14