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
0answers
23 views

calculate time in data processing into XML and CSV

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
29 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
19 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
58 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
46 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 ...
0
votes
1answer
136 views

Cancel Long Running Query using Cancellation Token AND SqlCommand.Cancel()

I need to be able to cancel a long running query programmatically through our application. The code below will kick off a long running query and give control back to the main thread. At any ...
-1
votes
0answers
31 views

Use of the is keyword to check if a nullable is not null [migrated]

I just figured out, that it is possible to use the is-keyword in C# for a null check on nullable stucts. I think it looks quite clean and is good to understand, but ...
1
vote
3answers
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
117 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
59 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
96 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 ...
12
votes
0answers
103 views

Open source project to ease the Assert part from the functional tests of .Net Core Web APIs

I have built an open-source project based on FluentAssertions in order to solve some recurring tasks I was doing while testing the .Net Core APIs I'm developing. I find the capability of doing in ...
2
votes
1answer
213 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 ...
1
vote
0answers
23 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 ...
3
votes
2answers
100 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
60 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
59 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
67 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
133 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
918 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
97 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 ...
0
votes
0answers
37 views

Stream wrapper for base 64 string

We have a scenario where we are receiving file as base64 string. This is not ideal and should be a binary stream. Because with file size memory utilization grows very rapidly as base64 representation ...
1
vote
1answer
38 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
3k 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
73 views

Seekable HTTP response stream wrapper

I created this wrapper to use together with HttpClient streams and ZipArchive. ZipArchive ...
6
votes
5answers
226 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
16k views

Disposing the Context in the Repository pattern

I have a question about the Repository pattern: ...
3
votes
2answers
115 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
76 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
499 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
77 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 ...
11
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
420 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. ...
3
votes
1answer
67 views

Wrapping third-party component to use in windows service

I'm using a third-party commercial server component to listen for SAP IDocs. I want to run the server inside a windows service and the vendor recommends having a separate method to check the server ...
-1
votes
1answer
48 views

Reduce CPU utilization in constant pinging to API and saving data in to database service [closed]

I have this hosted service which grabs the data from API every second and process the data and save it into the database. I have similar 3 more hosted services which run at the same time. Because of ...
4
votes
1answer
3k views

Generic repository and generic service

I use the Repository/Service design pattern in my projects. I have doubts whether it is worth using common services BaseEntity: ...
2
votes
1answer
76 views

Hosted service which perform CRUD operations in high update environment

I have this hosted services which garbs the data from the API and save it in the database. But before saving it checks if the data already exists in the DB if not it creates the new row and if it ...
4
votes
3answers
209 views

Poker Game: Refactor method to evaluate poker hands

Preface: I've perused the other related questions before creating this one but I believe that those solutions weren't applicable to my situation. I'll concede that its possible that I may not have ...
3
votes
4answers
142 views

Multiplying/Dividing before Adding/Subtracting

I'm working on a calculator for educational purposes and was asked to include a rule that multiplies/divides before it adds/subtracts. Let's assume I have the following equation: ...
2
votes
1answer
1k views

Project Euler 19 (count Sundays in the 20th Century) with a while loop

I'm working on Project Euler problem 19, which reads as follows: You are given the following information, but you may prefer to do some research for yourself. 1 Jan 1900 was a Monday. ...
19
votes
3answers
8k views

scoped_ptr for C++/CLI (ensure managed object properly frees owned native object)

Motivating SO question: Is there a C++/CLI smart pointer project (e.g. scoped_ptr)? I'm interested in any reviewer comments, and especially identified bugs or inconsistencies with the native ...
4
votes
2answers
5k views

Checking if a directory exists in FTP without relying on exception handling

I've written a method to check if a directory already exists on an FTP server. The only way I could see to make this work was to return a different result from the method if an exception is thrown - ...
4
votes
2answers
130 views

DropDown tree with search

I fetch a bunch of categories for a DropDown tree, and have to implement search in this dropdown. If there is a match in one of the elements, it should also get all ...
6
votes
1answer
6k views

Tracking which entity properties have changed

There are a number of topics pertaining to entity change tracking. All the ones I've seen involve either 1) notifying when a property has changed or 2) merely determining whether or not an entity is ...
2
votes
1answer
44 views

Posting images from request to Azure blob

I have base Controller for Attachments, here is code of it In this controller, I pass data from the request and return URL of the posted object. ...
1
vote
0answers
65 views

What pattern can I use to write CRUD functionality? [closed]

I am writing a console application. CRUD functionality.I would like to try to apply the pattern. Is it possible to apply a "state" pattern? In the AddCustomer () ...