.net

.Net: Convert Generic List of Objects to DataSet

Does anyone have code to do this? ...

What guidelines are appropriate for determining when to implement a class member as a property versus a method?

The .NET coding standards PDF from SubMain that have started showing up in the "Sponsored By" area seems to indicate that properties are only appropriate for logical data members (see pages 34-35 of the document). Methods are deemed appropriate in the following cases: The operation is a conversion, such as Object.ToString(). The opera...

How to get Single XElement object using Linq to Xml ?

I would like to use Linq to Xml to get a single XElement from a .xml file by attribute name, similar to how you retrieve single objects in Linq to Sql by Id below: var singleDog = context.Dogs.Single(p => p.Id == int.Parse(Id)); Is this possible? ...

Protecting Section in App.config file Console Application

Hi, I am trying to encrypt the appSettings and connectionStrings section in App.config file of the console application. For some reason section.SectionInformation.IsProtected is always returning true. static void Main(string[] args) { EncryptSection("connectionStrings", "DataProtectionConfigurationProvider"); ...

Writing a Scheduled Windows Service in .NET

I want to write a windows service which the user can schedule. i.e, the user can choose to run the service from 9:00 AM to 6 PM daily, or he could run it every night, starting from night 12 o clock at night to next day morning 6, etc. Is there any out of the box .NET API that will help me do this? I know I can do this using the Scheduled...

Should repositories implement IQueryable<T>?

I'm considering one of two IRepository interfaces, one that is a descendant of IQueryable and one that contains IQueryable. Like this: public interface IRepository<T> : IQueryable<T> { T Save(T entity); void Delete(T entity); } Or this: public interface IRepository<T> { T Save(T entity); void Delete(T entity); I...

How do I create an email-sending service?

I've been kicking around this idea for a while and would like to read your thoughts. I'd like to create a .NET service to send and track email messages. My rough ideas: Within various applications, serialize instances of .NET email (System.Net.Mail.MailMessage) objects and put them into a database or file system queue The mail servic...

Moq'ing an interface

While I'm googling/reading for this answer I thought I would also ask here. I have a class that is a wrapper for a SDK. The class accepts an ILoader object and uses the ILoader object to create an ISBAObject which is cast into an ISmallBusinessInstance object. I am simply trying to mock this behavior using Moq. [TestMethod] p...

Searching For String Literals

In the quest for localization I need to find all the string literals littered amongst our source code. I was looking for a way to script this into a post-modification source repository check. (I.E. after some one checks something in have a box setup to check this stat) I'll probably use NAnt and CruiseControl or something to handle the m...

Determining if enum value is in list (C#)

Hello, I am building a fun little app to determine if I should bike to work. I would like to test to see if it is either Raining or Thunderstorm(ing). public enum WeatherType : byte { Sunny = 0, Cloudy = 1, Thunderstorm = 2, Raining = 4, Snowing = 8, MostlyCloudy = 16 } I was thinking I could do something like: WeatherType _badWeat...

Exposing Member Objects As Properties or Methods in .NET

In .NET, if a class contains a member that is a class object, should that member be exposed as a property or with a method? ...

Omitting XML processing instruction when serializing an object

I'm serializing an object in a C# VS2003 / .Net 1.1 application. I need it serialized without the processing instruction, however. The XmlSerializer class puts out something like this: <?xml version="1.0" encoding="utf-16" ?> <MyObject> <Property1>Data</Property1> <Property2>More Data</Property2> </MyObject> Is there any way ...

Calling stored procedures

I have a c# application that interfaces with the database only through stored procedures. I have tried various techniques for calling stored procedures. At the root is the SqlCommand class, however I would like to achieve several things: make the interface between c# and sql smoother, so that procedure calls look more like c# function ...

How can I see my applications threads while debugging in Visual Studio?

I would like to see the threads currently active in my application while debugging it. How can I do this using Visual Studio? ...

Why are try blocks expensive?

I've heard the advice that you should avoid try catch blocks if possible since they're expensive. My question is specifically about the .NET platform: Why are try blocks expensive? Summary of Responses: There are clearly two camps on this issue: those that say that try blocks are expensive, and those that say "maybe a tiny little bit...

Using Crystal Reports in Visual Studio 2005 (C# .NET Windows App)

I need to create reports in a C# .NET Windows app. I've got an SQL Server 2005 database, Visual Studio 2005 and am quite OK with creating stored procedures and datasets. Can someone please point me in the right direction for creating reports? I just can't seem work it out. Some examples would be a good start, or a simple How-to tutorial...

Office 2003 PIA Prerequisite in the .Net framework and Office 2007

What happens when the Office 2003 PIA prerequisite and launch condition in a Windows installer are run against an Office 2007 system? ...

.NET DBNull vs Nothing across all variable types?

I am a little confused about null values and variables in .NET. (VB preferred) Is there any way to check the "nullness" of ANY given variable regardless of whether it was an object or a value type? Or does my null check have to always anticipate whether it's checking a value type (e.g. System.Integer) or an object? I guess what I'm lo...

Redirect Standard Output Efficiently in .NET

I am trying to call php-cgi.exe from a .NET program. I use RedirectStandardOutput to get the output back as a stream but the whole thing is very slow. Do you have any idea on how I can make that faster? Any other technique? Dim oCGI As ProcessStartInfo = New ProcessStartInfo() oCGI.WorkingDirectory = "C:\Program Files\Applicati...

WinForms: Implementation question for having my UI run independently of my BLL layer?

I am trying to do a Windows Forms application in an MVP style and - not having done much with threading before - am getting all confused. My UI is a set of very simple forms. Each of the forms implements an interface and contains a reference to a mediator class which lives in the Business Logic Layer and vice versa. So as simplified di...