Questions tagged [c#]

C# is a multi-paradigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform. Use this tag for questions related to C#. In case a specific version of the framework is used, you could also include that tag; for instance .net-2.0.

623 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3
votes
0answers
2k views

Optimising looping through large data set and updating database

I have a database table storing information about documents (MigrationMaster). There is another table with security information on these (DocumentSecurity). There are 4 steps I can see that I need to ...
3
votes
0answers
220 views

Extension for BindableBase that can dispose the old value of a property if that property implements IDisposable and is not null

I am interested in hearing opinions on this. I need a way to dispose the old value of a property in a way that's compatible with BindableBase. Specifically, I have ...
3
votes
0answers
101 views

Multitenant app authorization

Role based security does not work for me well in a multitenant app, as I need to query DB to decide on permission allowance. Here is the solution I came to. All implementations of this interface will ...
3
votes
0answers
833 views

Tiny calculator using dependency injection and inversion of control

I've started to learn very interesting concept of DI, IoC and related stuff. I have decided to learn it using simple application, very tiny calculator (only basic functions: add, subtract, multiply &...
3
votes
0answers
91 views

Event delays for a Monogame project

I am making a GUI for my C# Monogame project. So since this was the first time I ever made a GUI that is not winforms-based I took a wrong approach in making it and thus I decided to change it ...
3
votes
0answers
119 views

Rbac Principal with Binding support

I've been maintaining a Rbac helper for some time now. My goal is to provide an easy way to tell the following: When does an user have a role What can a user do (...
3
votes
0answers
415 views

Lazy WebAPI object

I am working to design an object which would abstract away the use of a WebAPI. I want the developer to be able to use these objects as if they are using a traditional API. My core problem is how to ...
3
votes
0answers
1k views

Workaround proxy to be able to call 32-bit dll

I had a problem that I posted on StackOverflow about that I could not connect to windows phone 7 from a 64-bit application. I got one response that said I should try to create a WCF Service over named ...
3
votes
0answers
218 views

Safely aborting thrid-party code using TPL

I'm using some third-party libraries in my project. Once in a while the code in these libraries freaks out and produces infinite loops and other nasty things. My goal is to write a wrapper that allows ...
3
votes
0answers
2k views

Web API 2 - JWT with X509 certificate

I got my JWT generation working with X509 and wanted to ask if you would recommend any changes in respect to: Signing certificate storing / handling. Publishing for anonymous access public key ...
3
votes
0answers
1k views

Wrapper for jQuery Ajax to ensure redirects occur on clientside - Round 2

A while back I posted Wrapper for jquery ajax to ensure redirects occur on clientside on handling ajax and redirects when a server side error occurs. Since that post I've been using this module ...
3
votes
1answer
140 views

Improvements to data access layer

...
3
votes
1answer
57 views

UnitTest strong exception guarantee

I want to properly test the strong exception guarantee of a method. The method in question is SetFiles. It does not have side-effects (it only modifies the object ...
3
votes
1answer
139 views

TimeoutManager: check whether a task has been finished within a given time

I want to make a helper class, which raises an event whenever something is not finished in a certain time. Example: my program sends out multiple network messages concurrently. After a random delay, ...
3
votes
1answer
189 views

Validating the model outside of the controller in ASP.NET

I wasn't quite sure whether I should do it this way or create a validation service and inject it, but this works: Controller: ...
2
votes
1answer
45 views

Remove redundancies in similar properties

I have a lot of redundancy here, but I am not sure how could I make it look shorter. ...
2
votes
0answers
81 views

Split a list of points into a list of lines in C#

I have a list of points (System.Drawing.Point) obtained from an edge finder function that scanned a bitmap for objects. Each point is guaranteed to be a part of an ...
2
votes
0answers
135 views

Tic Tac Toe game using WPF+MVVM

I am looking for some advice on how to create a new ViewModel within an already existing ViewModel. I am creating a Tic Tac Toe game, to improve my knowledge of the MVVM pattern, WPF and C#. I am ...
2
votes
0answers
77 views

Read compressed XML file inside ZIP and parse data as fast as possible

I am trying to read and parse an XML file inside of a ZIP archive as fast as possible. The XML file is roughly 85GB in size, so I know for a fact that I/O also plays a role here, as I need to ...
2
votes
0answers
62 views

Visitor pattern, Extensible visitor for custom implementation

I'm writing my own expression tree system, just for fun, but I have a few doubts about my code. My goal here is to create an abstract layer of expressions, and allow different "languages" to ...
2
votes
0answers
71 views

Find the largest contiguous sum of two or more integers in an array of positive or negative integers?

I received an interview question: Find the largest contiguous sum of two or more integers in an array of positive or negative integers. I wrote a brute force solution, which is slow at O(n^2). Is ...
2
votes
0answers
90 views

C# Learning MVVM by creating a Login functionality

I am trying to get my head around how MVVM pattern works. Would like to hear some reviews if I am implementing it correctly. View ...
2
votes
1answer
168 views

A* Pathfinding Algorithm

I have programmed a A* Pathfinding algorithm in the Console. I would now like to know if there are any things that I could do to improve the time it takes, to find a path. Right now it takes around ...
2
votes
0answers
74 views

How to use single child Unity container for OWIN middleware and WebAPI

I am using OWIN to self host a WebAPI service. There is Unity to serve as an IoC container. Within several OWIN middlewares (e.g. authorization layer) as well as in WebAPI I need to access a Unity ...
2
votes
0answers
32 views

What is the correct way to alter ComboBox between two DataSources?

I am looking to alter one combobox between two DataSources depending on the button clicked. Here are the 2 lists: ...
2
votes
0answers
62 views

Simple Sqlite-driven WinForms app in C# 7.0 - database interaction code

Description This is a simple "demo" app designed to help gain familiarity with interacting with an Sqlite database from C#, particularly storing images as blobs. The database has a single ...
2
votes
0answers
53 views

Handle ASP.NET WebSocket connections using TPL Dataflow

I was recently introduced to the wonders of TPL Dataflow and thought it would be a good exercise to create a wrapper class which wraps around an ASP.NET WebSocket ...
2
votes
0answers
166 views

Extracting Excel cell format with Microsoft.Office.Interop.Excel in C#

I am trying to fetch the format (e.g. background color, border settings) of each cell in Excel file with Microsoft.Office.Interop.Excel class. I know that there are many tools could be used well in ...
2
votes
0answers
37 views

Performance impact of using reflection instead of an “Options” class

I am trying to refactor a service by providing some options on what to bring back. I can't decide what is best way to go between the below A. Use a class for the options Create a new class for the ...
2
votes
0answers
68 views

C# Scraper - EventHandler

It might help to check my previous question out, its part of the same application. The only minor changes are with the entity class names. They now each have their own entities, and I use interfaces ...
2
votes
0answers
93 views

Fnv1a hashing of C# Guid

I have the following implementation of the Fnv1a hashing for a string, which should be correct: ...
2
votes
0answers
34 views

C# MySQL library: How can I reduce bundling and abstraction?

I'm a teen developer who just does this as a hobby, but I still care about good practice even if I don't fully understand it. Two of the most used phrases when sharing the code of my C# MySQL library ...
2
votes
0answers
81 views

ASP.NET Core 3.1 Multi-tenant with separate database

I am following this sample by Gunnar Peipman to create a multi-tenant architecture in my ASP.NET Core 3.1 application. It is working as expected up to the point shown in the sample. ...
2
votes
0answers
70 views

Marching Square algorithm

The following source code is a solution to the Marching Square problem. The explanation of using random numbers in ambiguous cases can be found here. ...
2
votes
0answers
89 views

C# Color implementation with conversions from RGB to HSL and CMYK and vice versa, targetting Blazor and CSS

This is an implementation of a Color class, primarily targetting the web to be used in a Blazor app. Color.cs ...
2
votes
1answer
62 views

Multiple producer single consumer on the same thread

I implemented a multi-producer single consumer class, with an important restriction that once the consumer started working, it must continue its work on the same thread (the reasoning behind this is ...
2
votes
0answers
180 views

Windows user form to fill data to be sent to MySQL database

I have created an application to send data to MySQL. On top of that, I am attaching a file and storing into a folder. Also, If trying to attach an excel sheet - another form opens, giving you the ...
2
votes
0answers
27 views

Uploading CV file to an e-commerce website and sending the CV to employer's email

I am working on an e-commerce website. In this specific scenario, people can upload their CV to apply for a job. The job application is sent to ApplyForJob action ...
2
votes
0answers
118 views

Making 90% similar code for 20 different objects

Basically, I have 20 very similar objects and most importantly I want to do the same thing for all of them. This is the ImportProcessor class for ...
2
votes
0answers
62 views

Building a string with only two repeating characters (different code)

Context I would like to receive feedback on my code for the question which can be seen here. Problem This is another C# implementation for the a function for given parameters ...
2
votes
0answers
38 views

Managing invalid cookie when 2 users use the same computer and therefore share the same cookie

I have asked this question on stackoverflow... here, I am asking for some feedback on the solution that I have implemented. I am using ASP.NET MVC default template to logout user: ...
2
votes
0answers
65 views

I'm just starting out with tasks. I need to know if there's a better way to do TAP for socket handling (serving a request)

I've got this quick and dirty little console app in C# to serve an HTTP/HTML page. ...
2
votes
0answers
21 views

Is this way of handling events in a Xamarin project memory safe?

I inherited a Xamarin project and I'm trying to find my way. The first task I completed involved creating a new reusable view and adding it to an existing screen. This was iOS specific, so I went and ...
2
votes
0answers
42 views

Trie to index files and search for them

Basic idea (foo and foa are filenames): ...
2
votes
0answers
32 views

Basic login by username logic with SQL Server

My goal is to make a very simple library with the authentications basics: create a user and save its hashed password, change its password, have a method to check if the password is correct for login. ...
2
votes
1answer
364 views

Deserialise Json and Read Stream twice in C#

So this is a modern implementation of a HTTP client, trying to find a way to optimise/simplify this. Specifically the DeserializeAsync method with the GetStream and the compiler statement for if/debug ...
2
votes
0answers
30 views

How to best structure an abstract class where a member field will depend on the deriving type?

Puts and calls are two types of options. One parameter that they both share is called a strike price. The valuation of an option is related to the strike price, but the exact methodology is different ...
2
votes
0answers
213 views

C# class to dump the memory of a process in several formats

I made this because I couldn't find any good C# classes/libraries that allow you to dump the contents of a process' memory into a file or a byte array. I haven't tested this on 32 bit systems but it ...
2
votes
0answers
236 views

How to efficiently execute multiple async calls in parallel to cassandra in C#?

I am working with Cassandra where I am getting some stuff out of it using Datastax C# driver. Below is my code which interacts with Cassandra db and in my ...
2
votes
0answers
32 views

Email Service - Sending an email with azure blob storage Version 2.0

Now implemented changes suggested in my previous post and now am back again for the internet to tear me and my shitty code down. PatchNotes Extracted templateRetriever class from the email service ...

1 2 3
4
5
13