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.
1,129
questions
1
vote
1answer
77 views
Initialize bunch of variables in constructor by extracting value from dictionary
I have a headers dictionary value being passed to one of my constructors and based on that dictionary value I am extracting individual headers I need and setting ...
3
votes
1answer
2k views
Dependency Injected StackExchange.Redis Client
I am currently building cache for my application, and I would like to have my redis cache client work the same way you would dependency inject a DbContext.
I am using StackExchange.Redis to manage my ...
3
votes
1answer
809 views
Creating a shortcut class in C#
I'm working on making a shortcut... manager, if you will. It will be reused throughout the rest of the application for registering types that can later be resolved into views. I have a rule that the ...
7
votes
2answers
1k views
HKDF Implementation in C#
Based on my prior question about HKDF here https://crypto.stackexchange.com/questions/43933/use-of-pbkdf2-when-no-access-to-hkdf and the responses I received I decided to go ahead an implement HKDF ...
4
votes
1answer
83 views
A* pathfinding for integer Vectors
This class is for calculating the shortest path in a 2D World (without minding obstacles).
I'm using the A* algorithm and 2D Vectors (from the SFML Framework).
It is working but takes (a lot of) time ...
0
votes
0answers
33 views
Handling disconnected entity scenario in Entity Framework Core
As some you you may know, handling disconnected entities in EF can be a bit of a headache. After a really long weekend, I managed to make it work for my use case and refactor the code to the best of ...
2
votes
1answer
39 views
Send Data from DynamoDB to Lambda (C#) and to Azure Queue
I am a beginner and trying to send data from AWS DynamoDB to Azure Queues. Note that this code will be invoked 10,000 and alot more. Can you guys review it once.
...
5
votes
5answers
4k views
Property caching
Trying to figure out how to efficiently cache property calculations with dependency tracking to invalidate the cache. Here is the syntax I have at the moment (one ...
6
votes
4answers
218 views
All your Base - Exercism.io
This is an exercise on the website Exercism. I am self taught trying to learn C# and C++. This is the information from the readme.
Convert a number, represented as a sequence of digits in one base,...
1
vote
0answers
36 views
Handle login method with external users and LDAP users
I'm working with a ASP.NET Core (v2.2) Web Api project and implemented some APIs. However, I'm facing performance issues, hence trying to optimizing the code. Here is the login API code.
...
3
votes
1answer
973 views
Secure password hashing implementation with salt and pepper
I share below my password hashing implementation with salt and pepper in C#, for your review and feedback. In my implementation methods like ValidatePassword(), ChangePassword() are in the user class.
...
1
vote
1answer
78 views
Getting names/values of multiple properties [closed]
Lets say I have one method, which extracts property name and value:
...
3
votes
0answers
69 views
PowerShell script to execute Docker maintenance, optionally non-interactively
Problem
Developers in my team are new to Docker. I wanted to provide a way to accomplish general Docker housekeeping tasks (like pruning unused images and compacting the Hyper-V volume) largely ...
2
votes
1answer
75 views
Programmatically getting the GUID of an application
Intrigued by the events chronicled here (also here and here), I saw the inherent utility in having a program-specific GUID available. The SO answers that were correct seemed a bit tightly-coupled and ...
1
vote
0answers
70 views
Extension method: Task<T>.CoalesceAwait
There has been ongoing concern about the question of awaiting a task that could possibly be null, as when using null-coalescing operators. Consider the following:
...
1
vote
1answer
86 views
Serializing object graph to proprietary binary file
I'm creating a class library to read/write .3di files which are binary files describing 3D models for a video game. This review is for the write/serialization process.
I've mapped the different ...
2
votes
1answer
107 views
Can this async method be improved or simplified
I was tasked to write process that initially seemed like a straight forward thing. "Fetch data from database, create a cache object, and assign this data to it. Use existing class to model this after."...
2
votes
0answers
452 views
Generic CQRS Query handler with custom return type
I am trying to build a generic query handler using the MediatR (v8) library. Let's jump to the code:
First of all I have an abstract query class like this:
...
1
vote
0answers
32 views
calculate time in data processing into XML and CSV [closed]
I made a program (C#, .NET) that calculates time for XML and CSV export and please I have a question for improving my knowledge in programming. Do you think that I can improve the structure of the ...
1
vote
0answers
375 views
Reactive Extensions wrapper around Confluent.Kafka for .NET
Just an Rx wrapper around Kafka to represent topic consumption as IObservable<T>:
...
1
vote
0answers
662 views
Accurately measure ASP.NET Core 3.x actions execution times (Web API project)?
I want to be able to log the time spent by a certain Web API action in an ASP.NET Core 3.x application.
This is a very old question from ASP.NET which relies on global action filters, but in ASP.NET ...
4
votes
1answer
512 views
WPF Custom Control with a Single ObservableCollection DependencyProperty
I'm learning how to write WPF custom controls. My example, NameLister, exposes a single DependencyProperty, Names, of type ...
3
votes
0answers
145 views
Creating SQL Server Database Users Dynamically from User Input
The Application
I have an application in testing that runs off of an MS SQL Server database. The app allows users to authenticate using Windows authentication (that is, using the Windows username the ...
1
vote
2answers
6k views
Replace all occurrences with the properties of an object
The basic idea is to replace all special expressions, e.g., [%InvoiceNo%], [%DueDate%], in a string with the properties of an ...
3
votes
1answer
130 views
Bulk inserting/updating people with additional properties
The below code is either inserting or updating a list of person with a lot of properties of these persons. The code is repeating itself a lot but is working as intended.
Unfortunately making all the ...
4
votes
2answers
65 views
Feedback on automatic form filling with reflection
Context:
I need to fill a handful of .docx templates with answers that come from form.responses, which is a dynamic object that comes from a JSON and can have different properties that vary according ...
4
votes
3answers
106 views
Method that fetches rows from database and maps it to a Model class with SqlDataReader
So, I have a project that has a lot of methods that look alike.
In the below method as you can see it just fetches a bunch of rows from database and maps it to a model class.
In this case ...
3
votes
1answer
7k views
Generate Unique ID in C#
Objective
To create a unique id with few characters as possible.
Language: C#
Engine Unity3D
Target : iOS && iPadOS
Scenario
I found quite a few solutions from Stack Exchange but would ...
3
votes
2answers
162 views
Validate if either or both of two fields has been provided, as a ValidationAttribute
I have a binding model where at least one of two fields must be specified. I can't just set them both as [Required]. Here is what I came up with:
...
3
votes
1answer
63 views
Calculating all flight connections
I am working on an API to return all the possible flight route between point A and B. I have a set of data which includes the flight number, airline, departure airport, destination airport, departure ...
3
votes
1answer
67 views
Formatting a type's name
I'm writing a code generation library, I've exposed a couple of methods and of course in order to define a member you need to specify it's type, the easiest way is to use ...
1
vote
0answers
74 views
Running some code every day at certain times
I am currently developing a windows service in C# which is supposed to run a data import every day at configurable times. For this purpose I have created a class "ExecutionTime" which contains the ...
5
votes
1answer
243 views
Encrypting credit card data
I need an encryption algorithm that would be secure enough to store credit card data. So it should be reasonably secure.
Here's what I've come up with. I'd appreciate any constructive criticism.
<...
3
votes
2answers
4k views
Algorithm generating a unique ID based on client name
Following code is supposed generate a new ID (PID) for a new client based on the client name's first letter and the existing IDs in the range which are stored in a database.
For ex lets say if the ...
0
votes
1answer
2k views
Convert IEnumerable to HTML table string
My code can generate HTML table strings well, but it depends on JSON.NET.
I'm converting IEnumerable to an HTML table string using Json.NET but I think I shouldn't....
4
votes
2answers
184 views
/proc/net/tcp results filter and converter
Being unable to easily read the output of /proc/net/tcp I made a small C# console app that modifies the output to be in decimal notation instead of the standard hexadecimal, show the corresponding ...
1
vote
1answer
45 views
Small service for hashing and validating passwords, using PBKDF2
As part of a larger authentication/authorization system, I've developed a small .NET Core 3.0 service for hashing passwords using PBKDF2 (with a salt) and validating passwords against a stored hash/...
9
votes
3answers
5k views
Take previous element from array if condition on current element matches
Any ideas to simplify this beauty; I would prefer a LinQ expression if possible:
...
19
votes
4answers
4k views
Matrix class in C#
I've been learning C# during my free time in the past months; before that, I was mostly writing Java, so the transition hasn't been too hard, but I've never had my code reviewed or read by someone ...
2
votes
0answers
351 views
Seekable HTTP response stream wrapper
I created this wrapper to use together with HttpClient streams and ZipArchive. ZipArchive ...
6
votes
5answers
789 views
Take N elements from List of Lists
I've come with a solution super tricky for a simple requirement. I think I could solve the problem using LinQ, but I'm not seeing it so clearly at all.
What's sure, I'm not comfortable with my code.
...
10
votes
4answers
17k views
3
votes
2answers
118 views
Parcel size classifier [closed]
I submitted a technical assignment for a job interview process and I am stressing out wondering if my submission was any good. I would like to learn and be a better developer, so please give me ...
4
votes
1answer
204 views
Iterating over combinations
Background
The following describes the real world problem that my code is intended to solve. It is may help you understand what the code is doing and why. I don't think this is strictly necessary in ...
9
votes
1answer
3k views
Database Class Creator
Overview
I've written a class that will create C# code. The output is a single .cs file for each table in the default database (the database is defined inside a web.config file). I'm looking for a ...
6
votes
2answers
9k views
Database access class
I'm looking for any comments or feedback on my database access class. Security and speed are two things I'm most concerned about.
One thing to note is this class has to work in a C# .NET 2 ...
4
votes
1answer
1k views
SemaphoreSlim extension method for safely handling cancellation and disposal
I have often found myself using a try {semaphore.Wait()} finally {semaphore.Release()} pattern when using a semaphore, so decided I wanted to try and write an ...
2
votes
1answer
115 views
Should I re-throw exceptions within a method, or is there a better way to handle it? [closed]
When handling errors in C#, is it acceptable/appropriate to re-throw exceptions that are caught in a try/catch?
My scenario is that I am making an HTTP request and ...
12
votes
2answers
5k views
Math expression parser in C#
EDIT: Added refactored version 2.0 to the end!
I have a parser that is supposed to take a string similar to a math expression and return a Tuple of:
An array of strings where each string ...
4
votes
1answer
505 views
Sauna experiment - Celsius to Fahrenheit converter
This is my program for a sauna. It is a Swedish sauna meant to only understand Celsius, but the user can only understand Fahrenheit, so when the user inputs Fahrenheit, it is converted to Celcius. ...