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
1 vote
1 answer
54 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,450
-1 votes
1 answer
47 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
103 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
109 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
187 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
88 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
218 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
651 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
351 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
337 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
489 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
279 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
127 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
133 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
232 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
279 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
0 votes
0 answers
39 views

Changing the state of an entity in a multi threaded environment using Stored Procedures

According to my current design various processes and threads(written in .net core or framework) will call this stored procedure to change the status of various entities in a multi threaded environment:...
Spongebob Comrade's user avatar
4 votes
1 answer
745 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
0 votes
0 answers
135 views

Service Locactor with accessing service safely for .Net DI

I have implemented a service locator, but I am unsure if the services (instances) obtained from it can guarantee the security of the accessed or manipulated data. In some classes where services cannot ...
YUu's user avatar
  • 23
1 vote
0 answers
123 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
0 votes
0 answers
150 views

Code structure for 3rd party API calls

The Problem: I need to create a HttpService (Interface + Implementation) within an application that will be responsible for communicating with an external API service. There are three types of data ...
Vedran Knezevic's user avatar
3 votes
1 answer
402 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
2k 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
3k 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
880 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
271 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
143 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
777 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
107 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
0 votes
0 answers
527 views

Is this a good implementation of Dependency Injection using MVVM without any nuget packages?

So I've been looking into dependency injection for WPF while still using an MVVM pattern. And something that's been incredibly difficult to wrap my head around was, how to create a navigation service ...
Jess Chan's user avatar
  • 101
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
1k 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
412 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
546 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
708 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
0 votes
0 answers
3k views

Unit testing / TDD MediatR Queries and Validators

I would like to get a code review for the following code. It's meant to filter mocked products. I used to not like writing tests, but some time ago I realized how great TDD is. Not only it makes the ...
nop's user avatar
  • 739
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
396 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
182 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
106 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
219 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
251 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
119 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
427 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
894 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
0 votes
0 answers
287 views

BaseController with Generic Entity and Model

I created a controller with generic TEntity and TModel so that i will not have to repeat common actions like save/delete for each entity. I just want to ask if this is a good or a bad practice? ...
John Louie Dela Cruz's user avatar

1
2 3 4 5
25