1
vote
2answers
38 views

What Data Annotations need to be shared/different between my Model & ViewModel to keep seperation of concerns?

I read this question and answers, about if Display Annotations on model properties violates the separation of concerns between view and model. And my interpretation of their answer was "No, not if ...
8
votes
4answers
550 views

Repetitive code driving me crazy!

Ok, So first I must say that everything I know about coding I have learned on my own in my spare time so bear with me if my code is primitive, but please, I am open to any comments to make me ...
3
votes
1answer
75 views

Looking for advice on how to make my code better

I have to make project for school in C# which has to use database and web service. I have made program which starts web service and gets function from web service which is used for connecting to ...
1
vote
0answers
52 views

Best practices in implementing service methods

Consider the following architecture: ASP.NET MVC Application having controllers which depend on service classes (MembershipService, EmailService etc.) which in turn depend on data access context ...
4
votes
3answers
157 views

Using ref for value types - Is this the right usage or is it weird at multiple levels

I chanced upon this code written by the Solution Architect for a MS CRM project and I am lost for words. Am I going crazy or is this code OK? string returnedOptionSetStringValue=string.Empty; int ...
1
vote
1answer
74 views

Accumulating inner exception messages

Say, there is a class with some methods, that have try catch blocks. I need to accumulate messages from all inner exceptions of generated exception and use throw new Exception(exceptionMessages). I ...
1
vote
1answer
28 views

Caching XmlSerializer in AppDomain

To work around the XmlSerializer memory leak thing I created this: public static class XmlSerializerCache { public static XmlSerializer GetXmlSerializer(Type type, XmlRootAttribute xmlRoot) { ...
2
votes
2answers
60 views

Email Template Referencer

Which is best practice for creating an enum-like look up for templates? I enjoy being able to bring up my templates with VS IntelliSense so either works for me. Option 1(enum/Dictionary Combo): ...
-1
votes
1answer
82 views

Single Responsiblity Principle with polymorphism question [closed]

So I'm somewhat new to the Model View Presenter design for testing my GUI. So far I really like it because now I can actually test my GUI's behavior instead of just having the "test" open up a ...
0
votes
2answers
88 views

How to take the some elements of a list of random numbers and sort them?

I want to create a file consisting take rows of distinct numbers in ascending order. They are randomly taken from the first total integer. The file will be used to make an excerpt as discussed here. ...
9
votes
2answers
451 views

Am I coding Java in C#?

Note: This ended up being much longer than I was expecting. I have a number of side questions that relate to specific parts of the code for if you don't want to slog through all this mess. Background ...
0
votes
1answer
60 views

Appropriate separation of concerns for this case?

This is a method that calls a web service, it uploads an audio file and fetches metadata back. While the advantage is that there is only one method to call there are a few concerns about it : There ...
6
votes
3answers
277 views

Better Alternative For Storing Multiple Booleans?

I have a class, which stores an enum to track if my object is modified, newly created, or no change. If the object is modified, I have additional booleans for each field that is modified. For ...
0
votes
3answers
89 views

Combine similar methods with different text?

I made the popular Guess-The-Number game and included an AI version that picks random numbers. The AI version has slightly different Console output that differ slightly, for example: I generated a ...
1
vote
1answer
91 views

Best way to handle repetitive error code or return value

I have a wrapper which interacts with a third party component. In Each function i am performing the operation if it the component is initialized. I have other function to check the errorCode and ...
2
votes
2answers
193 views

Reusable user control (ascx) design for multiple web application

My company's web application projects are heavily based on user controls. One common case is like we want to reuse the UI visual elements but note the packaged original logic . I have read some very ...
6
votes
2answers
190 views

Is there a better way to call the same method with different parameters?

I have a method(C#) which takes an XmlNodeList and a String and saves the xml data into a database. That code isn't the problem (at least for the moment), but because I have multiple XmlNodeLists, ...
7
votes
1answer
266 views

using <T> in generic delegates?

Here is my problem. Do I need to give a new identifier to each delegate I write of the following delegate type? like so: or could i use one delegate that accounts for any Datatype I need to use so i ...
8
votes
1answer
278 views

Does my code conform to modern conventions?

I've spent a few days making the transition from WinForms to WPF, and do not have much time for tutorials as the work needs to be done quickly. I was wondering if anyone could take a look at a sample ...
3
votes
1answer
404 views

A base class to handle mapping between entities and view models

I'm working on a fairly mundane ASP.NET MVC app that allows users to do basic CRUD operations on a number of different domain objects. I'm trying to minimize duplicate code and boring, monkey code as ...
5
votes
1answer
91 views

Is the use of return in the middle of a method a valid pattern for general use? [duplicate]

Possible Duplicate: Is it better practice to return if false or execute an if statement if true? I was recently doing a code review for the following code: public void ExecuteGet() ...
5
votes
4answers
294 views

Disposing of objects - is there such a thing as overkill?

I have the following using statement, used specifically for the purpose of archiving content in SharePoint libraries. In this statement my objects are disposed in two places: finally { ...
3
votes
2answers
192 views

Criticize my database interaction code

I'm a junior developer working on a hobby project to try to improve. For this I've written my first class to interact with a database. I was hoping I could get some feedback on the design of my class ...
7
votes
2answers
3k views

Generic repository and unit of work code

I am writing a WPF application that needs to access information from a database (I am currently using Entity Framework code first, so data access is via DbContext). My ViewModels directly ...
2
votes
2answers
178 views

Query and data manipulation review

The below sections of code are part of a list administration project I am working on to teach myself C#. This is from a tab that is used for list administration. There is a drop down box that allows ...
3
votes
2answers
62 views

Defaulting dependencies

What are some advantages and disadvantages of providing default implementations for dependencies. I have chosen to do this because it allows the objects to be easily used in the application but also ...
1
vote
0answers
205 views

Review ETL code to synchronize external system to internal database

I'm looking to see if my current evolution of ETL logic is getting in the ball park of "how it's done in the real world". Specifically, do I use the metaphors correctly (Extract, Transform, Load)? ...
3
votes
2answers
980 views

Best practices for decouple classes in C#

So this is a lot more confusing than it has to be (I could just stick all of this in the main class with the ui event handlers) but I wanted to decouple this class for learning purposes. Basic ...
2
votes
1answer
448 views

Passing an array of values in UrlAction

I need to pass an array of values in Url.Action. Currently I'm doing: var redirectUrl = Url.Action("search", new { q = criteria.Q, advanced = criteria.Advanced, salaryfrom ...
4
votes
1answer
404 views

C# Class of client methods for interacting with web servers

I'm in QA Automation, and C# isn't my first language. I've written a small class of methods for GETting and POSTing to web URLs. I use these when I want to test certain things that really fall outside ...
3
votes
2answers
528 views

Business Layer - UI communication

Taking the following cases in consideration. Witch one would you prefer and why? Suggestions appreciated. Using Delegates private void cmdDelete_enterClick(object sender, EventArgs e) { ...
6
votes
1answer
155 views

Trying to implement a collection class to represent a Path of Segments

I've posted a few times over on stack.overflow recently and have been advised to try here to sort out a good code implementation once and for all. I'm trying to implement a custom made 2D geometry ...
5
votes
7answers
357 views

Where to set default values

When setting initial values for class members we have the option of setting them in the declaration public class MyClass { public int someInt = 300; // etc. etc. } or within the constructor ...
2
votes
1answer
204 views

Asynchronous Programming Code Review

I did a load test for an ASP.NET MVC application. It was basically for 2 different pages which are doing the same thing but one was synchronous and the other was asynchronous. The result was shocking. ...
4
votes
2answers
1k views

Is this a valid Producer / Consumer Implementation for Parallel Processing in the TPL

I've stripped this down to it's bare bones removing stopping/cancelation logic etc... to keep it simple. First of all the Producer... A very simple class containing a timer. At regular intervals the ...
1
vote
1answer
105 views

Is there any flaws in my code which let me to save settings to a file?

This code allows me to save some settings from my small app to the text file which later I can retrieve by using substring and delimiter. I wonder if there's any better way of doing this. If not, how ...
4
votes
1answer
261 views

Should I split class or keep it all in one?

Currently, in my project I have one class that is dedicated to the all of the queries for the IBM i and converts it into usable models for my .NET code. There is already 12 methods in this class and ...
1
vote
2answers
2k views

Generic binary search

I have the following code for binary search using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Diagnostics; namespace ...
5
votes
5answers
698 views

Best practice / alternatives for string manipulation with an emphasis on readability

As a personal habit I generally prefer to use string replace and format methods, along with string "patterns", in lieu of string concatenation and other methods in most languages I use (typically C# ...
3
votes
2answers
331 views

How can I make this work for development AND eventually live?

I am developing a class library for processing credit cards. There is a thought in management in the short-term future to look for a new credit card processor. So I want to write once and use ...
7
votes
6answers
8k views

Is there a better way to do dynamic filtering and sorting with Entity Framework than this?

I'm developing an application using ASP.NET MVC 3 and Entity Framework 4.1. In that application I have a lot of paged lists. Users can filter and sort these lists. This results in code like the one ...
2
votes
1answer
195 views

Critical review of a Simple Class

public partial class CreateAdmin : System.Web.UI.Page { #region Events. protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ...
4
votes
1answer
249 views

Is this a good/safe way to convert enums?

Due to the fact that Entity does not support Enums, I am converting them to strings, string lists, and back again. The reason is two fold: type-safety, and consistency in the database. Now, I have a ...
1
vote
1answer
965 views

How to re register dynamic scripts registered with ClientScriptManager in asp dot net using session was bad idea

Following the normal pattern of adding inline scripts to gridview row/s is a bad practice it used to work like below protected void CustomersGrid_RowDataBound(object sender, GridViewRowEventArgs e) ...
3
votes
3answers
960 views

Is this architecture overly complex or following best practices?

I work as a C# developer at a company that doesn't use best practices at all. We're on .NET 3.5 but most code is written in a .NET 1.1 style (e.g. almost all the logic is in the code behind of the ...
6
votes
3answers
524 views

FTP Download Helper Method

This is my first post in this community and I'm genuinely excited as I can't wait to start reading your feedback. So I'm currently using an Open Source FTP library in all my projects as I've never ...
2
votes
1answer
437 views

Refactor for using ChannelFactory

I use VS 2008 and .NET 3.5 I have this code using CustomChannelFactory and Proxy ServiceReference. I would like refactor using lambdas, Action, ... any suggestions ? ...
2
votes
1answer
360 views

Best way to locate Find on List<T> with reflection

I am locating the find method of List in C# with the single Expression type parameter I am using the following ( where T is a List, in my case a SubSonic IActiveRecord ) MethodInfo info = ...
8
votes
4answers
719 views

Nested anonymous methods

I needed a function that would take a list of folders and removed all sub folders, so that only the top level folders stayed in the list. For example, given the list: c:\stuf\morestuff ...
5
votes
2answers
1k views

Best practice instantiating generic delegates and accessing property getters

I want to create delegates to access properties of different objects without knowing them in advance. I have the following definitions public delegate T MyMethod<K, T>(K data); public static ...

1 2