.net

Convert tabs to spaces in a .Net string

I am building a text parser using regular expressions. I need to convert all tab characters in a string to space characters. I cannot assume how many spaces a tab should encompass otherwise I could replace a tab with, say, 4 space characters. Is there any good solution for this type of problem. I need to do this in code so I cannot use a...

T4 template for NHibernate? - not Fuent NHibernate

Wondering if anyone knows of a set of T4 templates for generating C# POCO classes and also mapping XML files for NHibernate from a set of tables in a database. I saw that David Hayden has created T4 for generating FluentNH code based upon a DBML model, but I'm not quite ready to use FluentNH yet as there isn't even an official release ye...

Mono feature complete

Does Mono miss any functionality from .NET? If not, when will we see official MS recognition for it, like including Mono platforms in the Platforms section on MSDN? It seems like they are seen as separate things. ...

What is the shortest way to implement a proxy or decorator class in c#?

When you have a class car that implements IVehicle and you want to wrap it in a decorator that forwards all calls to car and counts them, how would you do it? In Ruby I could just build a decorator without any methods and use method_missing to forward all calls to the car object. In Java I could build a Proxy object that runs all code ...

What is the correct implementation for GetHashCode() for entity classes?

Below is a sample implementation of overriding Object.Equals() for an entity base class from which all other entities in an application derive. All entity classes have the property Id, which is a nullable int. (It's the primary key of whatever table the entity class corresponds to.) public override bool Equals(object obj) { ...

Implementing a nested asynch "call stack" scenario in .NET

I'm attempting to refactor some moderately complex existing .NET code to be usable in Silverlight. The core issue is that all Silverlight web services calls must be asynch, and the existing code was implemented in a fairly typical synchronous manner. Existing call stack for a typical operation might be something like this: Page -> Get...

Is there a way to dynamically execute a string in .net, similar to eval() in javascript or dynamic sql in sql?

Is there a way to dynamically execute code contained in a string using .net 2.0, in a similar way to eval() in javascript or using sp_executeSQL in tsql? I have a string value in a variable that I want to manipulate at some point in my application - so the code would essentially be string manipulation. I don't know what different manipu...

ODP.NET Configuration in Web.config

I'm adding the odp configuration in the application web.config file. For this I have a configuration section named "oracle.dataaccess.client". Therefore I'm adding an entry in the <configSections> section. Something like this: <section name="oracle.dataaccess.client" type="System.Data.Common.DbProviderConfigurationHandler, System.Data,...

What are the benefits of maintaining a “clean” list of assembly references?

Just like Carl's question over here I would like to ask you (because I couldn't find it out on my own :( ) if there is any benefit by removing an assembly reference that is not statically nor dynamically (via reflection for example) used. ...

Starting a new app with database support

Hello, I'm starting a new C# project that uses a database, but I want it all to be version controlled. I'm thinking about a SQL server database (If I make a mdf file, will I be able to use it in a computer without SQL Server installed?) and LINQ to SQL. How do you usually start a project like this? Do you create a .sql file to create th...

How to make WebBrowser to save its content as an MHT file?

Internet Explorer can save its content as an MHTML file using the "Save As..." menu command. Is this feature exposed by its COM interface? ...

.NET: How to talk to a form during BeginInvoke callback?

i have a long running function¹: public string FindPasswordFromHash(String hash) { ... } which is called like: private void Button1_Click(object sender, EventArgs e) { PasswordTextBox.Text = FindPasswordFromHash(HashTextBox.Text); } Now i want to convert it into the asynchronous BeginInvoke/EndInvoke delegate pattern: priv...

How would you display a 3D banana in C#?

I am trying to put together a desktop app for a client. They want the logo in the top corner (on a tool bar) to be a spinning 3D banana. I had planned to write this in C#. Any ideas how I could pull this off? ...

ASP.NET Web Application - compiling .cs files

I guess I have been using the Web Site model ever since .NET 2.0 and never looked back. Now I'm using the Web Application mode on a few projects. How do you tell the compiler to compile .cs files in the project? I assume you can do this since the newer-MVC projects do it for the Controllers. I have a class, RestRouteHandler, that implem...

.Net C# Design View errors

Hi, I have subclassed a Treeview and on instantiation it loads a new ImageList (and the associated Images). Whenever I switch to the designer view, it's also trying to run this code, however the images aren't in the designer's path, so it crashes. I ended up putting in a hack to see if the current directory is "Visual Studio", then do...

Set properties on dynamically added UserControl

I'm dynamically adding a custom user control to the page as per this post. However, i need to set a property on the user control as i add it to the page. How do I do that? Code snippet would be nice :) Details: I have a custom user control with a public field (property ... e.g. public int someId;) As I add a UserControl to a page,...

Multiple Base Addresses in single WCF Service

I have an environment where multiple sites hosted on the same server will use a single service to make its calls. For example: http://domain1.com/Api/Service.svc http://domain2.com/Api/Service.svc The Api application has been setup as a virtual directory in each site mapped to the same physical directory, so that the source is only l...

Machine's domain name in .NET?

There gotta be an easy way to do this, I can't believe there's none. I have scanned through net and found, like, 20 different methods to find in which domain current user is, but none to get domain (or workgroup) of current machine. In unmanaged c++ this is retrieved by: WKSTA_INFO_100 *buf; NetWkstaGetInfo(NULL, 100, (LPBYTE*)buf); do...

How to bind nested objects, or master-detail-binding, in code?

I have a three nested classes, Show, Season and Episode, where a show has seasons, and seasons has episodes. I want to bind two listboxes so that the first lists seasons, and the second lists episodes in that season. How can I do this? I prefer to set this up in code, not xaml, but if you know how to do it with xaml, it's better than ...

Linq - Row not found or changed

I have the following code: Guid id = imageMetaData.ID; Data.LinqToSQL.Image dbImage = DBContext.Images.Where(x => x.ID == id).SingleOrDefault(); dbImage.width = imageMetaData.Width; dbImage.height = imageMetaData.Height; DBContext.SubmitChanges(); Looking at SQL Profiler, the following SQL is...