.net

Can LINQ to SQL generated objects be decoupled?

I like LINQ to SQL, but it seems like the classes it generates are tightly coupled to the database they are stored in, which seems like a Bad Thing. For example, using ye olde Northwind database, if I create the dbml with the Products table, a Product class is generated. I can use this class in any other tier, which is all well and goo...

Why calling Dispose() on BinaryReader results in compile error?

I have a following class witch uses BinaryReader internally and implements IDisposable. class DisposableClass : IDisposable { private BinaryReader reader; public DisposableClass(Stream stream) { reader = new BinaryReader(stream); } protected virtual void Dispose(bool disposing) ...

Disable Debugging Output

I'd like to sprinkle some print statements in my code to show where I am and print important values to a console window. How do I do that, but then be able to turn it off for the release version? ...

Parse filename from full path using regular expressions in C#

How do I pull out the filename from a full path using regular expressions in C#? Say I have the full path C:\CoolDirectory\CoolSubdirectory\CoolFile.txt. How do I get out CoolFile.txt using the .NET flavor of regular expressions? I'm not really good with regular expressions, and my RegEx buddy and me couldn't figure this one out. Also...

What's the point of the garbage collector

SqlConnection connection = new SqlConnection(FROM_CONFIGURATION) SqlCommand command = new SqlCommand("SomeSQL", connection); connection.Open(); command.ExecuteNonQuery(); command.Dispose(); connection.Dispose(); It is recommended that the code above should include try/catch (or using) so that if an exception is thrown, all resourc...

Can I create a file that sits next to a .Designer.cs file in Visual Studio?

In Visual Studio, two files are created when you create a new Windows Form in your solution (e.g. if you create MyForm.cs, MyForm.Designer.cs and MyForm.resx are also created). These second two files are displayed as a subtree in the Solution Explorer. Is there any way to add files to the sub-tree or group for a Windows Form class? ...

How do I open alternative webbrowser (Mozilla or Firefox) and show the specific url?

Hey, I know there is built-in Internet explorer, but what I'm looking for is to open Firefox/Mozilla window (run the application) with specified URL. Anyone can tell me how to do that in C# (.nET) ? ...

.Net exe memory footprint

Even a simple notepad application in c# consumes megabytes of ram as seen in the task manager. On minimizing the application the memory size in the task manger goes down considerably and is back up when the application is maximized. I read somewhere that the dot net process reserves a lot of memory for runtime allocation in advance that...

Should I Print the Exception Stack Trace?

How inefficient is it to get the stack trace for an exception? I know it's costly, but how costly? Should they definitely not be used in production environment? ...

ASP.NET MVC: Best way to get form checkboxes into many-to-many DB assoc table with LINQ To SQL?

Hi, I have an ASP.NET MVC view which contains checkboxes for user-defined categories. <td><% foreach (Category c in (List<Category>)ViewData["cats"]) { if (selCats.ContainsKey(c.ID)) { %> <input name="CategoryIDs" type="checkbox" value="<%=c.ID %>" checked="checked" />&nbsp;<%= c.Name%><% } else { %> <inpu...

How to use Reflection to Invoke an Overloaded Method in .NET

Is there a way to Invoke an overloaded method using reflection in .NET (2.0). I have an application that dynamically instantiates classes that have been derived from a common base class. For compatibility purposes, this base class contains 2 methods of the same name, one with parameters, and one without. I need to call the parameterle...

How do I update a WinForms ListView when using VirtualMode=True?

I have an app with a large ListView which is terribly slow so I'm implementing VirtualMode. MSDN does not seem to cover how I would add and delete new items in the middle of the listview. For example, the ListView has 1000 items (representing files on disk) and after the initial population of the ListView (by the RetrieveVirtualItem eve...

.NET RegionInfo class

When I try to create a new RegionInfo with certain ISO 3166 country codes ("BD" for Bangladesh, "SO" for Somalia, "LK" for Sri Lanka), I get an ArgumentException that says it's not recognized. What's the deal? The Intellisense of RegionInfo(string) says it conforms to ISO 3166, but these country/region codes are not supported? I don't...

Do Spring.NET and Common.Logging XML schemas (XSD) exist?

Spring.NET 1.2.0 M1 comes with several XSD files for the <objects> node, database stuff, etc. However, it is an incomplete collection because it does not seem to include <spring> (used in App.config), <context>, or <parsers> elements. Additionally, Common.Logging doesn't appear to have any XSD's included in the source or distribution. ...

Awesomebar-like behavior with Windows Forms

I'm trying to make a combo box that behaves somewhat like the Firefox 3 Awesomebar, with the following behavior: Type in text Asynchronously bring back results Up and down selects results in the list, BUT leaves the text that was typed in the entry box so the user can continue editing to limit the resultset differently Enter fires an e...

Developing ArcMap extension .Net books?

We have 2 new GIS programmer/analyst in our department (new to programming and ArcObjects) and I don't feel I'm qualified enough or have the time to teach them. So I'm looking for entry level books/tutorials for them to use as reference. The only books I can find for developing Extensions for ArcMap are written for VBA. Besides the ES...

C# - Optimising binary serialization for multi-dimensional generic arrays

I have a class that I need to binary serialize. The class contains one field as below: private T[,] m_data; These multi-dimensional arrays can be fairly large (hundreds of thousands of elements) and of any primitive type. When I tried standard .net serialization on an object the file written to disk was large and I think .net is stori...

c# create an instance of a class from a string

Is there a way to create an instance of a class based on the fact I know the name of the class at runtime. Basically I would have the name of the class in a string. ...

.Net webservice, how to access...?

Note: I am just consuming webservice I have no control over webservice code. So in .net 2.0 I reference the webservice and see a class in the webservice namespace, say foobar. It's defined as: public class foobar : System.Web.Services.Protocols.SoapHttpClientProtocol but in .net 3.5 when i add a reference to the same webservice I no ...

Business logic invading UI in a large winforms app

I have seen this theme present itself more than once now. I am hoping that people here who are currently in similar situations or have been in the past can offer some insightful advice. It might be useful if you share your past experiences as well. So there is this fairly large windows forms application that has been developed over the ...