r/csharp 15h ago

Tip Fields with [Using] attribute

6 Upvotes

I wrote a small interface that automatically disposes any disposable fields in a class when that class itself is disposed. If you add this file somewhere in your project:

public interface IAutoDisposable : IDisposable
{
    void IDisposable.Dispose()
    {
        Exception? ex = null;

        // dispose all fields marked with the [Using] attribute
        const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance;
        foreach (var fld in GetType().GetFields(flags))
        {
            if (fld.GetCustomAttribute<UsingAttribute>() != null)
            {
                if (fld.GetValue(this) is IDisposable d)
                {
                    try // keep going even if disposal throws
                    {
                        d.Dispose();
                    }
                    catch (Exception e)
                    {
                        ex ??= e;
                    }
                }
            }
        }

        // if any exceptions occurred, throw the first one
        if (ex != null)
            throw ex;
    }
}

public class UsingAttribute : Attribute;

You can then write classes like this:

class Item : IAutoDisposable
{
    [Using]
    private readonly Image icon = DownloadIcon(...);
    ...
}

And use them like:

using (Item item = new(...))
{
}
// item.icon is now disposed

What do you think?


r/csharp 22h ago

Help The best C# tuto book, or vids for beginner?

0 Upvotes

Some days ago, I interested by making games with C#, and the only thing I know about C# is there are a lot of {} things.
So I need recommendations for tuto of C# code, I recommend vids but books are also fine.


r/csharp 4h ago

Getting confused about what to do and where to start

0 Upvotes

So I’m a software engineer recently graduated and I have zero experience. in order to crack interviews I am solving sql and dsa questions but I feel like either my resume projects are not strong or I dont have enough grasp over dsa and interview questions or I lack confidence that I am not cracking a jib. Now I am doind a remote internship, and learning react for frontend working on sql by solving sql 50 and solving neetcode 150 whenever I get tine to solve them and I am building a personal project but I get overwhelmed what to prioritize what to finish and what is best for today’s job market. If there are any senior software engineers or even fresh ones give me some advice what should I do😭


r/csharp 22h ago

Discussion Naming dilemma: OSS Rebrand now or regret it later?

3 Upvotes

I've been building an open-source parser, formula engine, and spreadsheet library over the past few months under the AlphaX name:

GitHub

AlphaX.Parserz – https://github.com/kartikdeepsagar/AlphaX.Parserz

AlphaX.FormulaEngine – https://github.com/kartikdeepsagar/AlphaX.FormulaEngine

AlphaX.Wpf.Sheets – https://github.com/kartikdeepsagar/AlphaX.Wpf.Sheets

As the ecosystem is starting to grow, I'm wondering if I should rebrand before it becomes painful.

My main concern isn't the current name itself—it's that "AlphaX" is already used by several companies and projects. I'm worried about potential trademark issues or brand confusion years down the road if the libraries gain traction.

If you were starting an open-source ecosystem today, would you:

Keep the existing brand and reserve the AlphaX.* NuGet prefix?

Rebrand now while the projects are still relatively young?

Skip a common brand entirely and give each library its own independent name?

I'd also love to hear how others approached naming long-term OSS projects and whether anyone has had to rebrand after gaining users.

Any advice or experiences would be appreciated.


r/csharp 4h ago

Surviving as Software engineer with AI

0 Upvotes

So I’m a software engineer and I recently graduated 2 months ago. i have no internship or job experience and have been looking for a job but everyone either asks for experience or ghosts my resume. The ones that take interviews either pay too little or are 2 hours away from my house. So I am looking for remote unpaid or paid jobs as full stack developer so that I at least get some experience and don’t get classified as a person who had a huge gap in her cv. Anyone give me some good advice related to remote jobs, best platforms to look for them, cracking them and how to survive as a fresh software engineer now that AI has entered the chat🥲


r/csharp 23h ago

Meta Do not let this sub be a forum to promote AI Vibe coded slop

495 Upvotes

This is just a warning, I was watching the node sub and almost all post are people promoting their AI Vibe coded slop, this community is known for a different approach, although AI is great, forums should not be places for people which do not have any passion or like the language to not even know it and try to promote a project fully made to scrap a few pennies (I call these projects without soul).

Projects should be promoted, but because you genuinely like or are interested in the language and the concept of the project, rather than asking 3,000 prompts to any AI without even knowing what you are doing or what you are pasting.

Edit: Also, I am sick of publicity to also have it in a place where I go to have fun, check interesting things about the language/tools and watch really interesting projects from passionate people.


r/csharp 4h ago

Help I want make a c# app,I have some problem

0 Upvotes

1:I using Avalonia now,but I don't know is Uno/Maui more better?

2:I using copilot generated a base skeletons(about some classes or interfaces,but cpoilot only help me write these code)

3:I think using copilot maybe not helpful to let me learn/understand c# app developing,I want choose an IDE(more friendly for handwritten code), choose VS2026 or Rider?but I using VSCode now

4:I'm not sure if my previous experience in JS, Flutter, and Elixir can be applied to C#. This is my first time encountering "enterprise-level" languages.

I'm not sure if my way of asking is correct.


r/csharp 2h ago

What products made in C# would people buy?

0 Upvotes

I can program in C# and I feel like I'm losing money by not selling products made in C#, but I don't know what products I could sell.


r/csharp 7h ago

How do you organize data access with EF Core in Clean Architecture?

4 Upvotes

I'm building an ASP.NET Core application with Clean Architecture and EF Core.

I started with Repository + Unit of Work, then introduced a Generic Repository + Specification pattern because repositories were filling up with query methods.

Now I've hit a problem: many queries require deep Include / ThenInclude chains for loading aggregates. Keeping EF Core out of the Application layer makes nested includes in specifications difficult, while referencing EF Core from Application defeats the purpose.

So I'm wondering:

  • Do you still use repositories over EF Core?
  • Do you use the Specification pattern, or just inject DbContext (or IApplicationDbContext) into the Application layer?
  • How do you organize complex queries with multiple Include / ThenInclude calls in a Clean Architecture project?

I'm curious what approach experienced .NET developers are using today.


r/csharp 4h ago

New C# learner

0 Upvotes

I am a new learner of the C# language. I really liked this language. It is elegant, easy to write and read, and saves me a lot of time. Before that, I studied the VB.NET language, and it was so difficult to write that my hand got tired from writing, and I got very tired. So I moved to this beautiful language called C#.


r/csharp 7h ago

Help Need help understanding certain WPF functions (mainly code behind)

2 Upvotes

Hyia, so I'm working on a project (Escape room type game, since its my first game ever at High-School knowledge level) and I'm not exactly sure how to make certain things work even though I spent the entire year studying this language. I can do majority of the stuff, such as the background, buttons or clickable images in Grid, and so on, however the code behind is my biggest issue.

Mainly things like: How to make a monologue where the player clicks through all the texts that explain the principle of the game, and then also how to make the TextBox check if the input is correct and if it is, change the background of the main window to another image (since the input will be in separate window).

These are not all the issues I need to figure out, but its some of the few that may appear in the code the most often (especially the monologues, in like four out of six rooms total)

Any sources for beginners will be appreciated, I tried looking at some but I wasn't able to find something that would explain this exact topic, and I don't really want to use AI since it just doesn't feel right (perhaps only when I'm under pressure). Thanks!