Tag Info

New answers tagged

1

EEK... nooo my friend, hiding controls is the last thing you should do. If your using MVC, and I assume (Judging by your description) the Model Binding syntax, where your forms are generated using Razor and the HTML Helpers, then your already half way towards letting MVC do all the work for you. There are 2 main strategies when it comes to ASP.NET MVC. ...


0

When designing an API for operations which may fail because of foreseeable reasons, but at unforeseeable times, one should generally allow a means by which callers can indicate whether they are expecting to cope with the semi-foreseeable failures. If the only methods which are available return with error codes rather than exceptions, then every call site ...


2

There is a deeper issue here: the fact that C# and Java insist most/all types must be distinguishable by name rather than structure: e.g. class MyPoint2D and class YourPoint2D are separate types even if they have the exact same definitions. When the type you want is "some anonymous thing with an x field and a y field" (i.e. a record), you're out of luck. So ...


6

Is the duplication of classes ever useful/good design? Its good practice to have a separate view model class for use in the UI layer rather than using the same class that's used in the data layer. Your UI/web page might need to display other bits of information that aren't strictly related to the data entity. By creating this extra class, you are ...


3

This is called “syntactic sugar”. C# has several examples of this, one of the oldest being the lock statement. lock (x) { // Do something } is really: Monitor.Enter(x); try { // Do something } finally { Monitor.Exit(x); } The object initializer syntax introduced in 3.0 is another example, as are extension methods.


4

Item level permissions will require both database modelling and application enforcement. Essentially, You'll want to create an "item security" table that relates the RowIDs and PermissionIDs to each other. The application will then have to determine if the current user has the right permissions to view the item that they requested. The database can also ...


1

The two interfaces are actually part of Reactive Extensions (Rx for short), you should use that library pretty much whenever you want to use them. The interfaces are technically in mscrolib, not in any of the Rx assemblies. I think this is to ease interoperability: this way, libraries like TPL Dataflow can provide members that work with those interfaces, ...


0

Entity Framework is not the implementation of Repository Pattern. EF is the Object Relational Mapper. Yes, it looks and behaves like Repository Pattern with Save/Update functionality. Your IManager makes sense, and with enough abstraction, the Manager doesn't have to be coupled to EF at all. That will give you an option of switching ORMs if needed.


9

Aside memory allocation reason (which, by the way, looks like premature optimization to me), there are other elements in favor of catching invalid arguments as soon as possible: Stack trace When an exception occurs, you expect the few last lines to show you the location of a mistake. Having to search from bottom to top of the stack to find the culprit will ...


2

The answer is: it depends. In your example, you should let List throw its exception and let any exception bubble up the chain. Your example method should not know or care whether the value is invalid, since it's sole purpose is to pass it along to something else. If you were using the value in ReadAll as something other than an argument to List, you ...


1

Gotta disagree with the accepted answer. The argument about allocating memory, etc. is only relevant if this method is called often with an illegal argument. The purpose of checking arguments (programming by contract) and throwing exceptions is primarily to fix bugs during development. During development, efficiency is not an issue. Combined with unit ...


0

Short answer: no, it's not OK. Because even calling the constructor of List means, from the compiller's perspective: memory allocation for the new object, writing references for it in the reference table, accessing other subroutines just to create the new List object, just to have it basically blow up in your face by throwing an exception. I know it doesn't ...


0

You're right. The example works poorly for multiple IObservables. I guess OnComplete() doesn't provide a reference back because they don't want the IObservable to have to keep it around. If I were writing that I would probably support multiple subscriptions by having Subscribe take an identifier as a second parameter, which gets passed back to the ...


5

F# doesn't define generic array types per se. Arrays in F# are the same array type rest of .NET uses, and despite all syntactic evidence pointing to the contrary, they're not generic. This can sometimes backfire on you when you're using reflection in F# - even if you have an array<int> which appears to be a perfectly valid generic type, when you ...


3

How does C# support strongly-typed specialized array types like int[] based on the non-generic System.Array? Very likely, by generating a specialized class that inherits from System.Array since generics weren't available in 1.0. The behavior has likely been kept around for compatibility. Given that C# manages to do this, why does F# define generic ...


4

It is a subjective issue. On every new project we (myself and some colleagues I know) start, we set warnings to compile errors by default. We end up with a clean code base, easy solution. (Plus, we also enable FxCop, StyleCop issues as errors, very low cost if you do it from the beginning). Every warning has some impact on quality, maintainability, ...


2

You decorate a method with [Pure]: If the method doesn't have side effects. For example, if the method accesses a database and modifies it or its result depends on the database, it's not pure. And if you expect to use it in code contracts. For example, if the method is pure, but you have no intention to use it in code contracts, adding [Pure] would have no ...


1

The object cannot be used until it is constructed in this case. Therefore the constructor is pure. If the constructor called other code, or invoked a delegate, and the other code modified the mutable property, it would not be pure. To be safer, it is better to make the property immutable.


0

What about Comma-separated values(CSV)? simple text-based format can be edited via Text editor Excel and a lot of other tools are able to read and/or write it You just need to be aware of the fact, that not all CSV is CSV. There are a lot of flavours out there with different separators.


1

ASP.NET Identity comes in two flavors: You can use your own signin, which will essentially become a 'private IDP' for you. You an use external IDPs (Facebook, Twitter, LinkedIn, etc.) via ASP.NET Identity, which will handle all the complexity. I am not sure which option is "nothing for Production" in your opinion. If you can explain the concerns, the ...


2

There's a decent overview of the .NET Common Language Runtime on MSDN. There are a few key paragraphs that may get you started understanding the process: The common language runtime provides the infrastructure that enables managed execution to take place and services that can be used during execution. Before a method can be run, it must be compiled ...


1

As far as I understand you, there is no maintenance for those older versions to do - only for the newest version (changing of older version is forbidden, right?). That means, even if the function names become very technical after versioning, this should not be too much of a problem, since you never have to touch that code again. You need to store the ...


1

I don't think it is a wise idea to have View and Presenter being coupled so tight. Based on either the Passive Screen or Supervising Presenter the presenter and the view are separated by an interface that is implemented by the view. The presenter calls the interface. Here is an example of a supervising presenter. PRESENTER this class has no dependency on ...


0

Use a different channel on a message queue for each consumer. For each line in one of your big files write a message to each channel (e.g. each consumer). Each consumer can process messages on its channel deleting the messages once received.


4

Below is an example using an interface and two implementations in a console application: using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var processes = new List<IProcessable>(); processes.Add(new Process1()); ...


0

Use a hash which contains as key the name of the Process and as value the Object containing the process. That way you get just one line of code: Note: the following is in perl since I don't know C#, but the logic is the same $hashContainingProcesses{processName}.doSomething(); Depending on how C# will handle this you probably want to check first if the ...


1

You can guarantee that the bi-directional association between the Person and Organization objects cannot be broken by code outside the classes themselves by using events: public class PersonCreatedEventArgs : EventArgs { public readonly Person Person; public readonly Organization Organization; public PersonCreatedEventArgs(Person person, ...


4

First, it is clear from the context that by conditional expression Hunt means the boolean expression in a conditional statement. This is a section about flow control, and not about the use of boolean expressions for other purposes, or about (what I would call) conditional expressions based on the ternary '?:' operator. I believe the underlying intent here ...


5

You should also consider function calls that have side effects (e.g. change some global variables). This can be a more important issue than just readability. if (funcA() && funcB()) ... It might be intended that funcB only gets called when funcA succeeds, but you also might do a mistake here. If both functions have side effects and both are needed ...


7

Well, I did not read Hunt's document in full, it seems that his advices are mainly about readability. A statement like if(myObject1.functionA() && myObject1.functionB()) { // do something } has a certain risk of beeing misunderstood, because of short-circuit evaluation, and also because of the if-line length. Instead, bool resultOfA = ...


1

Displaying a second view on btnShowView2.Clicked is some kind of business logic, so the right place for implementing this is in the event handler of presenter1 which deals with that event (I assume that presenter1 is registered to all relevant button-click events of View1). Lets call it HandleBtnView2Click, so the initial code inside that handler might look ...


1

IMHO if that is ok depends mostly on the context of the Do method, and what you know about the stuff in the try-block. Lets assume you have an UI application, and the Do part is just a Button-Click handler. Lets further assume the part within the try block does some fairly complex non-UI things which might fail with any kind of unforseeable exception (but ...


2

Instead of catching the exception, why don't you just let it bubble up to the calling code? So either your model or controller (depending on how you call InsertAccount) would have the ability to catch the exception (or, in fact, any exception) and display it to the user in an appropriate fashion. My general rule is to only catch an exception when I can do ...


1

Multiple points: When I was reading DDD, I remembered one thing: You want to avoid double-sided relationships if possible. You should only define one direction and have the other direction be accessible through query in repository. In your case, you could have Organization as attribute of Person, but not have list of Person as part of Organization. And make ...


2

Seems like this would be easier to do if there were a third entity: Membership. Your three rules are enforced: Person handles - must have a Membership (which requires an Organization) Organization - gets it's list of people from the membership, so it knows about them. Membership - maintains unique Person and prevents same person from joining another ...


2

Make either the Person constructor "internal", or make the _people list accessible by an internal property, so the Person constructor can add this to _people right after creation. Of course, this solution is not perfect since it will still allow other classes belonging to the same domain assembly wrong usage of your objects, but at least it will forbid any ...


1

The biggest improvement for Rosyln is actually compiling code outside of your IDE. ie. the new ASP.NET allows you to drop your source code files onto the server and Rosyln is used to compile it automatically into binaries that run the website. In other words, your ASP.NET site becomes as easy to update and code for as all those scripting languages. I'm ...



Top 50 recent answers are included