Questions tagged [.net]

.NET is a software framework supporting a multi-language paradigm and supporting language interoperability. .NET applications are executed in a virtual machine (CLR) which provides a few important services: security, memory management and exception handling.

Filter by
Sorted by
Tagged with
-2 votes
1 answer
84 views

C# Implementing a list indexed by generic enums [closed]

I've seen a lot of code bases use Dictionaries with strings as their key. This can be redundant and expensive, so I'm trying to make a class that extends ...
user3337705's user avatar
1 vote
1 answer
66 views

Find Method Implementation for Multidimensional Array in C#

I found that Array.Find(T[], Predicate) Method is only support one dimensional array. I am trying to generalize it to multi-dimensional array in this post. The experimental implementation The ...
JimmyHu's user avatar
  • 4,708
-1 votes
1 answer
53 views

Should the SqlConnection Be a Class Field or Should I Pass It In and Out Of Functions As Needed?

I am writing a C# Database connection class and I am trying to adhere to best practices and produce clean code. In the CreateAndOpenDatabaseConnection function ...
BeeFriedman's user avatar
-1 votes
1 answer
112 views

Should I Break Up My C# Connection Function In Two, To Adhere To The Single Responsibility Principle?

I am writing a C# Database connection class and I am trying to adhere to best practices and produce clean code. In the CreateAndOpenDatabaseConnection function ...
BeeFriedman's user avatar
3 votes
2 answers
122 views

Truncating/abbreviating strings in the middle with an ellipsis (…) (or other) separators with a fixed character limit

Problem For some user-facing string, I want to truncate it to some given maximum length (also useful for file name/path lengths on Windows etc.). However, I want to do it a little more elaborately ...
rklec's user avatar
  • 33
2 votes
2 answers
203 views

How can I design the configuration of the library with Typed HttpClients in DI better?

I have written a .Net Client wrapper for Google Gemini (Generative AI) REST API and published it as a Nuget package. I am seeking a review of the code. I have spent quite some time in designing how it ...
Junaid's user avatar
  • 137
2 votes
1 answer
92 views

Simple .NET Web App for managing family budget

I am creating some small project for my portfolio. It will be an app written in .NET and React but for now I've done backend part and I seek code review. I wanted it to be aligned with DDD principles ...
Gustaw Ohler's user avatar
1 vote
2 answers
276 views

Thread-safe int wrapper in c#

My system is a .NET Core 7 console app, which starts some background threads. I need to pass some int values (counters, etc.) between the main and background ...
lonix's user avatar
  • 143
3 votes
5 answers
732 views

Optimisation: Fastest way to multiply every number in an array by 2

I'm trying to find the fastest way to multiply every element in an array by a given number, in this case 2. So far I have written a SIMD instruction that performs at 33 ns multiplying every number in ...
Henners2002's user avatar
4 votes
1 answer
354 views

Porting xoroshiro1024** from C to C#, and seeding it

I require a PRNG which: Has repeatable results from a given state. Is both seeded from and has a state containing a sufficiently large amount of data (somewhere in the region of 700 bits or more) to ...
Pikanchion's user avatar
2 votes
1 answer
420 views

Client disconnection and reconnection in C# NamedPipeServerStream

I have written a C# .NET code that utilizes NamedPipeServerStream to send and receive data. My goal is to ensure that when a client disconnects, the server waits ...
poqdavid's user avatar
  • 131
1 vote
1 answer
584 views

Recursively create a TreeView for file paths using C# and WPF

I'm building a program that allows the user to monitor files on their local system. To display the files, I created a TreeView using ...
Ramza's user avatar
  • 171
0 votes
1 answer
383 views

Mapping Entity Database Table to Model

I am not sure of the correct way to do this. I want to separate my Entity database model from the model I use throughout my application, as it will have fields in it that I may not want added to the ...
Scottish Smile's user avatar
0 votes
1 answer
167 views

Probability Library for .NET

I'm looking to create a library for dealing with probability in C#. My current system takes an ordered array of probabilities as an input then generates a random double. It then accumulates each ...
Henners2002's user avatar
1 vote
1 answer
139 views

Self-written mapper on C#

I develop my own application. I would like to write a good and elegant mapper. My idea is to use an extension methods. Could you please rate the following solution. I use ...
cinosz's user avatar
  • 21
5 votes
2 answers
242 views

C# console app that computes the Jaccard Index

So I wrote a basic C# console application that computes the Jaccard Index. This has its applications in cybersecurity and machine learning. Given two sets X and Y, the basic formula is: $$ J(X, Y) = \...
Aleksey's user avatar
  • 173
2 votes
3 answers
297 views

A hierarchical dictionary for dotnet

Is there an existing class in .Net for representing and querying hierarchical data; i.e. providing methods which allow you to test whether one item is an ancestor or descendant of another, or to ...
JohnLBevan's user avatar
  • 1,409
4 votes
1 answer
844 views

Threadsafe Non-Overlapping Timer

I was working on a project recently, where I needed to process some tasks periodically, but the execution of those tasks could not overlap with one another. ...
rickmanalexander's user avatar
1 vote
0 answers
131 views

Thread-safe key-value cache with expiration

I need my cache hold items to be accessible by key. The items should disappear after a configured time period. I do not need the lifetime of items to be exactly as configured. All I need is to make ...
C-F's user avatar
  • 111
3 votes
1 answer
439 views

My own ThrowHelper extension methods

I really like ArgumentNullException.ThrowIf(...) and ArgumentException.ThrowIfNullOrEmpty(...) and there are upcoming ones in ....
nop's user avatar
  • 739
0 votes
1 answer
3k views

Copy object without reference using reflection

Recently I was in need of a method to copy an object and pass it to a method which alters the data. Since a class is passed by reference this would alter the class in the caller which I don't want. So,...
Roe's user avatar
  • 121
2 votes
0 answers
4k views

Optimizing a EF Core "upsert" operation

I'm trying to "optimize" the command below. In other words, to make it suit my needs using best practices. I found a lot of posts regarding the "upsert" operation and there were a ...
nop's user avatar
  • 739
1 vote
0 answers
941 views

Extend the login timeout in a ASP NET 7 application

My ASP Core web application was recently upgraded from NET6 to NET7. Almost zero problems except one, which still puzzles me. With the "old" NET6 version, once an user log then app in (...
Mario Vernari's user avatar
1 vote
1 answer
319 views

Request-response model over sockets/websockets

This is a request-response model over sockets/websockets (like HTTP) where you technically match request id to response id and return the response. In addition to that, there is timeout in case that ...
nop's user avatar
  • 739
2 votes
1 answer
145 views

Saving entity containing complex jsonb column with validation and comparision

I've been a .NET Developer for almost 4 years. I'm stronly learning and trying using design patterns and following SOLID principles for 3 months right now (I know - a little late, but better late ...
KJanek's user avatar
  • 123
2 votes
1 answer
859 views

Serilog logging extension methods

I've been using this extension in almost all of my projects. What's your opinion? Do you think there is something else to add or to be improved? The idea is to ignore all default ASP.NET messages that ...
nop's user avatar
  • 739
1 vote
0 answers
113 views

Modified PoC for BlogEngine.NET CMS (CVE-2019-6714)

This is a modified exploit proof of concept targeting the BlogEngine.NET content management system (CVE-2019-6714) for the .NET framework. I modified it (from Cobb 2019) to execute payloads via ...
Aleksey's user avatar
  • 173
1 vote
0 answers
63 views

A service that downloads the whole trade history off an exchange and involves Redis cache

This service is pulling off the whole trade history for the Binance accounts. More precisely, it's a wrapper around https://binance-docs.github.io/apidocs/spot/en/#all-orders-user_data. Since their ...
nop's user avatar
  • 739
3 votes
1 answer
2k views

Find closest value in a big list

There are solutions e.g. list.OrderBy(item => Math.Abs(number - item)).First() or ...
nop's user avatar
  • 739
4 votes
1 answer
2k views

Use a static field for cache an authentication token in .NET API

I have a .NET 6 web API that does some requests to another third party API, this API has a token that expires after a few hours, so I want to cache this token and reuse in the requests. Here how I ...
Vanderlei Adriano's user avatar
2 votes
2 answers
441 views

Decrypt incoming HTTP request headers

During each HTTP request incoming from my Angular front-end I send encrypted pair of access & refresh token. On the back-end ASP.NET web APIs are used. The way I decrypt them currently is by ...
Andrеw's user avatar
  • 21
0 votes
2 answers
584 views

C# .NET 6, implementation of concurrent throttling tool

I'd like to seek advice on my implementation of rate controlling or throtting tool which implemented by C#.NET 6. correctness of implementation performance issue or any improvement can be done. <...
Timeless's user avatar
  • 109
1 vote
1 answer
750 views

RabbitMQ ConnectionFactory wrapper

This is a wrapper around RabbitMQ.Client's ConnectionFactory. Here is the simplest Producer/Consumer RabbitMQ example https://github.com/delaneybrian/jumpstartCS-...
nop's user avatar
  • 739
2 votes
2 answers
2k views

Extension methods to modify an async Task's type from Task<IEnumerable<T>> to Task<List<T>>

I've written a lot of (await SomeTask).AsList(); in my project, and it's kind of annoying to keep wrapping it. To fix this I've written a little extension method on ...
Joost00719's user avatar
3 votes
5 answers
1k views

Struct that parses full name into first name, middle name, last name and suffix

The struct below parses full name into first name, middle name, last name and suffix. Perhaps Builder pattern is more appropriate here? I remember there was a principle referring to the number of ...
nop's user avatar
  • 739
1 vote
1 answer
428 views

Creating complex object step by step

Builder pattern separates object construction from its representation I have to generate username and password for the Account class. Since this operation is a bit ...
nop's user avatar
  • 739
1 vote
0 answers
191 views

TPL Dataflow ActionBlock that doesn't allow the same data to exist in the buffer

I'm implementing a queue to update leaderboards when score data changes in the background. Updating the leaderboard is a relatively expensive operation, so if we say "Update leaderboard 5" ...
Mike Christensen's user avatar
2 votes
2 answers
107 views

Project sequence to multiple sequences using LINQ (or extension methods)

I'm creating a method that expands a sequence. This is a sample of how it works: Input: {1, 2, 3} Output: {1}, {1, 2}, {1,2,3} So far, I've been able to solve the ...
SuperJMN's user avatar
  • 233
1 vote
2 answers
226 views

Factory method doesn't meet the DRY principle

I'm using Proto.Actor and I have an actor which acts as a proxy and forwards the messages to the appropriate exchange just because each exchange has different subscription methods, different ...
nop's user avatar
  • 739
2 votes
1 answer
262 views

Parsing information from Excel files

I have to parse information from several Excel files (.xls, .xlsx). The structure of the files is nearly identical except for the columns order. In this case it is ...
nop's user avatar
  • 739
4 votes
1 answer
1k views

Transliterate between Cyrillic and Latin scripts

I want to get a code review on the following transliteration code. I wrote it because there were some libraries that I have tried and they were specifically failing with the name "Yuliya" ...
nop's user avatar
  • 739
1 vote
1 answer
121 views

Finding exceptions and optimisations in weather forecast service

When creating a new Blazor project, there is a page called FetchData which gives an example of a razor page using a service to pull data to a page. I set myself a ...
AT123's user avatar
  • 13
0 votes
2 answers
451 views

Drawing a rectangular playing field

I created a method to print a playing field in the console, but I think there are much better ways to do this than mine. ...
user avatar
1 vote
1 answer
125 views

Asynchronous tasks to subscribe to orders and fills

Pretty straightforward question. The methods SubscribeToOrdersAsync and SubscribeToFillsAsync are pretty similar due to ...
nop's user avatar
  • 739
2 votes
1 answer
920 views

Redis Output Cache Store refactoring - IOutputCacheStore Redis Implementation

This code incorporates the new .NET 7 Output Caching. I would like to get some refactoring tips on the RedisOutputCacheStore class. How to use ...
nop's user avatar
  • 739
1 vote
1 answer
271 views

File Abstraction Library

This library is a layer of abstraction over file operations in C#. It aims to provide easy file IO syntax, and implicit error handling behaviors, to ensure robustness in scenarios including, but not ...
Divan's user avatar
  • 113
2 votes
2 answers
954 views

C# Binary Search Tree implementation

I have implemented a Binary Search Tree and would really appreciate it if someone could take time to check it and give me feedback. I try to keep my code clear and simple. Is it readable? Is the API ...
Kirill Dolghi's user avatar
0 votes
1 answer
227 views

ASP.NET Core simple DB cleaner background service

In an application there is a table for one-time-passwords (OTP) which will be sent to users via SMS. These OTPs are needed for a maximum of two hours in order to detect abusing behaviours. A simple DB ...
Parsa99's user avatar
  • 133
2 votes
1 answer
802 views

ASP.NET Core background logger queue with dynamic workers

In a docker compose environment there are several apps that communicate with each other. One of these apps is a logger (a centralized logger). Every part of the system that needs to log something, ...
Parsa99's user avatar
  • 133
0 votes
1 answer
208 views

Improving multiple FirstOrDefault statements on same collection

I'm having multiple FirstOrDefault() statements, in this case 2, on a collection. ...
juFo's user avatar
  • 103

1
2 3 4 5
25