Tagged Questions
C# is a multiparadigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform.
0
votes
0answers
6 views
A generic MemoryCache class
I want to have a caching class to cache different types, I want each type to be cached in a different MemoryCache but in a generic way, here is my implementation:
internal static class RecordsCache
{
...
1
vote
2answers
37 views
How can I simplify these if/else clauses?
I have a few if, else-if, else clauses. The only different thing in the context of these clauses is my LINQ query, one clause has StartsWith, one clause has Contains, and the other does a simple ...
-1
votes
0answers
9 views
Project Unavailable in Visual Studio 2010 Solution [on hold]
Does anyone have experience with building Visual Studio 2010 Solutions with multiple projects?
I've got one that had been working for a while, but I did not have a backup of the tool.
I made some ...
0
votes
1answer
33 views
lazy instantiation and instance lifetimes in POM [on hold]
I've been considering the pro's and con's between implementing my page objects with privately backed properties and lazily instantiating them or just returning new instances every time and am curious ...
2
votes
2answers
47 views
How to get the Split value from collection?
I have the following key value pair in an array, and am trying to extract and load them into a collection.
The below code is working but it can be optimized using Linq:
string _data = ...
2
votes
1answer
30 views
A TaskScheduler that always run tasks in a specific thread
The following is an TaskScheduler that always run tasks in a thread it maintains.
When created, a name of the thread was specified. Once you schedule the first task, untill it is been Disposeed, a ...
1
vote
1answer
54 views
Where to put common method used in controllers that calls service layer?
I have an asp.net mvc5 web application using the repository pattern, and I have several controllers that need to call my _loggingService (queries audit logs) to get the last updated information for ...
0
votes
0answers
27 views
Why is this producing an “Empty Path Name Is Not Legal” exception? [on hold]
I'm attempting to serialize the state of a program I'm developing, but I'm getting the following error when I attempt to Deserialize the resulting file:
System.ArgumentException
Message=Empty ...
8
votes
3answers
214 views
Refactor foreach statement to LINQ
I have been working on a project and I'm actually refactoring some code. I have encountered myself with lots of foreach and if statements, which could be easily replace with LINQ.
But I have this ...
5
votes
3answers
416 views
Lots of repeating code, trouble refactoring
I'm looking for a design pattern or suggestions that can help refactor my code into something a bit less repetitive. I have a method that has several sequential steps (10-15) that if any of them fail ...
3
votes
1answer
40 views
Async Queue Processing
I have a Queue that needs to try to process when anything updates in it (add, remove or update).
However, I don't want any of the callers to wait while the processing is happening (either for the ...
5
votes
1answer
81 views
How do I extract interfaces from existing similar classes?
I have about 11 singleton-esque classes divided over a dozen files:
the first file is one that gathers all singleton definitions and makes them callable on a request scope:
public sealed partial ...
3
votes
2answers
59 views
Dependency on overridden method
In my code I have a base type which is OnlinePaymentTransaction:
public abstract class OnlinePaymentTransaction
{
public abstract void Complete( PaymentGatewayCallbackArgs args );
}
The ...
0
votes
0answers
5 views
Suggest a best practice to create Constants class [migrated]
There is a debate in between my team members about declaration of Constants class. We are moving the constant variables into separate class as like below
public class Contants
{
public const ...
2
votes
0answers
40 views
Listen to multiple RabbitMQ queue by task and process the message
Single app which listen to multiple RabbitMQ queue and process the message. This is working fine but not sure this implementation is right one or I am missing something.
Implementation is inspired ...
16
votes
5answers
4k views
Why is my C# program slower than my Python program?
I made a program on python, and wanted it to be faster, so I wrote it on C#, because it's compiled. To my surprise, the python program is much faster. I guess there is something wrong with my C# code, ...
3
votes
1answer
72 views
Call to external web service
The architecture is showing a call to an external Web Service which is called by me. Then I will expose the data using WCF to be callable from another WCF client. But I really don't like how it's ...
3
votes
1answer
65 views
C# 5.0 TPL - Chaining Tasks with async/await
I've been trying to learn how to use the TPL for quite some time now.
Basically I'm trying to fire off a group of Tasks, wait for them to complete and then fire off another group of tasks, waiting for ...
4
votes
1answer
50 views
Is this UnionFind code efficient?
The Wikipedia article on the union find problem gives a very simple implementation, which I ported to C# and tested.
I know that the code should be, in the aggregate, asymptotically almost linear. ...
1
vote
1answer
62 views
Winforms Enhanced ListView Class
Here is an "enhanced" Listview class. You can just add it your project and you're good to go. Most of the code came from here and there. It's not perfect by any means, so any input is appreciated.
...
3
votes
1answer
77 views
Naive implementation of attached properties for WinForms
I need to implement something like "attached properties" from WPF that targets WinForms.
What I came up with seems to work. Can you find any issues with it? The helper class and example are shown ...
5
votes
2answers
194 views
Relevant performance difference C#-VB.NET - Integer Division
C# code
static int KEY_NOT_FOUND = -1;
private void Form1_Load(object sender, EventArgs e)
{
int[] A = createArray(1, 100000);
Stopwatch sw1 = performCalcs(1, A);
Stopwatch sw2 = ...
3
votes
1answer
45 views
Async TcpListener
I'm trying to implement a TcpListener using the TPL. I'm not sure If I'm doing everything correctly though. I'm trying to keep the code as small as possible as well. It all works fine in a console ...
1
vote
0answers
26 views
Improving XNA's default project template
I hope this isn't getting annoying, but I've asked a lot of questions about improving my game lately:
How can I improve my game project design?
Using the observer pattern with collision detection
Is ...
1
vote
0answers
22 views
Inheritance and setting up for an API request
I am setting up a class to be used for an API request (with JavaScriptSerializer)
I am using it to send a complaint to their ticketing systems. So for example I send Title, Description, Custom_Fields
...
2
votes
2answers
64 views
How to declutter dependencies?
I'm running into a problem with my code in a ASP.NET MVC application. Maybe it's not a problem and I'm just being paranoid, but it seems like a problem to me (might be because I've just read the book ...
5
votes
2answers
62 views
Am I using Lazy initialization properly?
The following code is intended to implement a LinFu DynamicProxy interceptor to lazy load given virtual properties from an Umbraco datastore.
My concerns:
Thread safety, Have I covered all the ...
3
votes
2answers
42 views
Get array of pressed buttons using extension method
In my game, I need to detect whether any buttons/keys are pressed at all before I try to process any input. This is easy enough for keys since the XNA library provides a GetPressedKeys method on the ...
6
votes
2answers
96 views
How can I layout this class to make it easier to use for API developers?
I have an application that allows the user to place a string of text into a PDF document. I have three different ways that they can do this:
Use a Form Field. Then they have four properties to ...
7
votes
1answer
117 views
SQLite Helper Class in C#
Here is a SQLite Helper Class I created. Any input appreciated, including security and simplification.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
...
9
votes
2answers
140 views
Setting up keyboard bindings using JSON (no reflection!)
I got a lot of good feedback on my other question. So I will take another swing at it, post my revisions, and hopefully get some more.
First, the configuration hasn't changed. Here's the JSON file:
...
4
votes
1answer
54 views
Abstract factory or inversion of control pattern?
I have several generic methods that use the typeof operator to determine the type of mapper class to create. Eventually this is going to get out of hand.
Can anyone suggest a better way to handle ...
2
votes
1answer
71 views
Are there any improvements I can make to my implementation of the strategy pattern?
I'm not sure about that if else statement in function Change(). I'm guessing there is a way to eliminate this and make better use of OOP principles. Does anyone have any suggestions?
PS This code ...
2
votes
1answer
53 views
Is this correct for hashing a password?
Does this look like a good method to hash a user password. I'm not very familiar with how this whole hashing process works and below is a bunch of stuff I've seen on many different posts.
My main ...
3
votes
0answers
32 views
Anonymous methods, factory methods, threading, and XML input
I have an application which retrieves data from a (potentially) very large XML file. A combination of XMLReader and XDocument seemed to be the only way I could manage the entire thing the way I ...
0
votes
0answers
21 views
C# ENCOG SVM classification with my own dataset [closed]
I would like to do a multiclass classification application in C#. I decided to use encog to do so. Now I am stuck at one point. I found a XOR example, which I understand. But when I am going to use my ...
7
votes
2answers
124 views
Game passive skill system
I'm trying to create some easily accessible database of different skills. General idea is that every skill should do something different and be able to act on different things (ex. one skill which ...
3
votes
2answers
56 views
In-memory cache implementation revisited
As a follow-up on my earlier question, here is the new implementation. The major change is now that the base class just deals in ICacheValue values which are implemented by the derived classes and ...
5
votes
1answer
45 views
Setting up keyboard bindings using JSON and reflection
My game uses configuration files in JSON format. One of them is used for setting up control bindings, and it looks like this:
{
"DisplaySettings": {
"IsFullScreen": false,
...
10
votes
3answers
126 views
Design pattern for implementing multiple data sources
I've written a program to populate a particular object from multiple data sources, however I'm not convinced I'm going about this in the right way:
I have no idea which (if any) design pattern I ...
3
votes
4answers
110 views
Clean way of passing parameters
I have the following code:
public EmployeeProcessOutput RetrieveEmployee(EmployeeProcessInput input)
{
var employee = input.Employee;
if (input.EmployeeId == null)
employee= ...
12
votes
3answers
538 views
Is decoupling necessary for very small applications?
I threw together a small solution for my organization today for some basic data review and approval procedures. This particular application will likely not change or add functionality at any time.
...
2
votes
1answer
41 views
Delegate that selects a writable property on a generic
In the following contrived example, I have a collection of PropertyManagers that each contains selector and assigner delegates to read from and write to a property on the generic type. It feels clunky ...
2
votes
2answers
57 views
Returns Office Details from Database
I am building an Administration web site for the Office details in my database. Right now, I am just trying to display the office details.
public class OfficeRepository
{
public static Office ...
0
votes
1answer
25 views
Class for Managing Office Details
public class Office
{
private Int32 _SyncID;
private string _OfficeName;
#region Properties
public Int32 SyncID
{
get { return _SyncID; }
set { _SyncID = value; }
...
4
votes
3answers
66 views
Return Office Details From Multiple Tables
public void GetOffice(int syncID)
{
string strQry = @"
Select so.SyncID,
so.title
From Offices o
Left Outer Join SyncOffices so On so.id = o.SyncID
Where o.SyncID = @syncID
";
...
2
votes
1answer
41 views
Run the most recently requested action after finishing current, skip middle tasks
The goals for the code below are in the class summary below. Can anyone see that the code fails at any of those goals? I'm unsure how to thoroughly test it. Is there a way to keep the Queue method ...
3
votes
1answer
48 views
Generic object pool - what should be changed to make it easier to understand
I have created a simple class that maintains a pool (with maximum size) of objects. It acts like a connection pool (that is where the name came from - initially it was used just to maintain a pool of ...
7
votes
3answers
363 views
Ternary extension method
I created the following HtmlHelper extension method for my Asp.Net MVC Razor views because the ternary syntax sucks when you need to use it intermixed with markup.
Is there a better way to write this ...
5
votes
4answers
395 views
Sharing data between Forms
I want to create a class that has properties that can be set from one form, and accessed by any other form in the program. I created the form below and this works perfectly but I'm not sure if this ...