Tag Info

Hot answers tagged

34

If you find Guid.NewGuid() == Guid.Empty you have won the hardest lottery on earth. Don't bother with any uniqueness or collision checking. Not having to do that is what guids are for. I will spare you the math, it's everywhere on the web. Also, Windows guids always have one "digit" equal to 4. There is some structure to guids. That code snippet you posted ...


26

I would suggest it's not worth checking for Guid.Empty. The docs for Guid.NewGuid for some reason mention that The chance that the value of the new Guid will be all zeros or equal to any other Guid is very low. Guid.NewGuid is a wrapper for the Win32 API CoCreateGuid, which makes no mention of returning all zeroes. Raymond Chen goes further, ...


10

I personally prefer to use the [TestCase] where the input and expected outputs are all passed as arguments to the test function, whenever possible: [TestClass] public class PersonAgeTest { [TestCase("Philips","Mr. Phillips")] public void GetFullNameWithPrefix_SimpleValue_ReturnsValueWithPrefix(string input, string expected) { // ...


9

If you are going to check the GUID against the zero GUID, you by the same logic also need to do due diligence of checking it against all other GUIDs in your application (as the probability of getting a zero should be the same as the probability of getting any other GUID in your app*). You need to do this to prove the axiom you are acting under is that this ...


5

Depending on what kind of requirements you have for the application you're trying to build. (Maybe if you are a litle more specific I can help you more, otherwise is a too generic question). There's many ways of saving complex data. For example, and naming only a few ways to do it, you can use a small database like SQL Compact or SQLite, or you can just use ...


5

My problem is that the code that I have inherited is, in my opinion, absurdly over-engineered. I have enormous problems following the program flow and finding any concrete implementations of anything. The amount of abstractions are totally mind-boggling and there is no documentation whatsoever. Its not you, I find that a lot of C# and Java (and ...


4

Look at the source code of Guid.NewGuid method: public static Guid NewGuid() { Contract.Ensures(Contract.Result<Guid>() != Guid.Empty); ... } See the code contract? The Guid.NewGuid method never gives an empty GUID.


3

Ask yourself whether it makes sense for a consumer of a library to use one part of it without using another one. Let's say you've developed a library which parses LESS files, processes LESS files into non-minified CSS files and minifies CSS files. Does it make sense to have a library which does just the parsing? For general use, not really. But it makes ...


3

Building on Franck's comment, you can use a DataSet to save to XML. Writing DataSet Contents as XML Data System.IO.StreamWriter xmlSW = new System.IO.StreamWriter("Customers.xml"); // This example assumes you have a custom dataset called ds holding customer data ds.WriteXml(xmlSW, XmlWriteMode.WriteSchema); xmlSW.Close(); This will produce an XML file ...


2

To me, the middle tier is not actually the middle tier because regardless of how isolated the design is and how stateless the DLLs are, they execute in the context of a web server only and essentially a part of the web application. No, the middle tier could be in another server(s) altogether when it comes to large applications. For example you ...


2

We know that nowadays the systems are designed as web applications. Every imaginable system is either converted or planned to be converted to a web app. Huh? While web apps are certainly quite popular and useful, they are by no means the be-all-end-all. Here are some cases where web apps are a poor choice and a "desktop" app would be a much better ...


2

Whether you place the "Middle Tier" code in DLLs loaded by the Front End site or place it into a separate web service application is just a detail. This placement decision does not change the code architecture in a meaningful way. It's more of a deployment decision. No, the tiers are not defined by physical deployment decisions but by code architecture and ...


2

What is there to do. In my view, the decision to turn an exception during validation into a failed validation is a correct way of handling such exceptions. Letting the exception pass through and crash the application has a significant risk that you lose the work the user had been doing, even if the situation was caused by bad user-input and entirely ...


2

Why don't you design the interface of CardBoardBox utilizing an IEnumerable: public class CardboardBox { // [...] public IEnumerable<int> GetChildBoxIDs(CardboardBoxList fullListOfBoxes) { List childIdList = fullListOfBoxes.GetChildIdList(this.Id); foreach(int childId in childIdList) { yield return childId; ...


2

Since the .NET framework standard UI controls do not catch unhandled exceptions by themselves, and offer you some mechanisms to catch those exceptions in a central place, I agree that it is questionable why a 3rd party control should behave differently. Lets assume, from the nature of your application, in case of a severe failure, you are 100% sure you can ...


1

It actually depends. I would only create a Class which contains instance attributes if more than one of its methods uses it. On the other hand, if an attribute (or variable) is only used inside the method, then it should be defined local to the method it uses. In the example you describe, I think that you are using functions instead of methods, which to me ...


1

I am on mobile so bear with me. This is a basic walk through of object serialization. I think that there are pros and cons to either solution. You have to weigh them out and decide which is right for you, but I would go with a database. I would say my reasoning is quite arbitrary but this is exactly the purpose of a database. However... If I were going ...


1

I am very fond of hard error & fail fast, I believe they are the one true and right way to go, but I try not to be dogmatic about them. There are cases where the best thing to do with an unexpected exception is to log it and swallow it. I will give you an example which is more simple than your situation: suppose you have an observable collection which, ...


1

I recently solved a similar problem with a third-party library. Allow me to restate to make sure I'm not misinterpreting your situation. You know how to work around it, but you don't like the repetition of the workaround, and you feel it obscures your actual code? I solved my problem using a python decorator that catches an exception and handles it ...


1

For the public SDK scenario, I would strongly consider using Microsoft Code Contracts as these provide informative errors, static checks and you can also generate documentation to add into XML docs and Sandcastle generated help files. It is supported in all paid for versions of Visual Studio. An additional advantage is that if your customers are using C#, ...


1

Visual Studio community edition appears to provide access to the VS object model. I was able to create a project and do basic code editing with no issues. I've just started but it looks like this solves my issue.



Only top voted, non community-wiki answers of a minimum length are eligible