.net

Regex to match a substring within 2 brackets, e.g. [i want this text] BUT leave out the brackets?

I've managed to find the Regex to get almost the result I want here i.e. Regex r1 = new Regex(@"\[(.*?)\]"); string row = HEADERNAMES[COL1,COL2,COL3,COL4]; Match match = r1.Match(row); string result = match.ToString(); Outputs: "[COL1,COL2,COL3,COL4]"; I know I can then use: result.Replace("[", ""); result.Replace("]", ""); to get...

Indexing ServiceEndpointElementCollection

In the following config file excerpt, the WCF service has two endpoints. <service behaviorConfiguration="AtomTcpHub.Behavior" name="AtomTcpHub.HubTcp"> <endpoint address="" binding="netTcpBinding" name="AtomHubEndpoint" contract="AtomLib.IAtomPublisher"> <identity> <dns value="localhost" /...

Using a base class for unit test setup and teardown

Assuming Visual Studio.NET 2008 and MsTest are used to run unit tests. When a system is based on a service container and dependency injection unit testing would naturally require the setting up of services. Should these services rather be setup in a base class that all unit tests derive from or in each unit test class. If they should b...

Does it load the data from database?

Assume we have a method like this: public IEnumerable<T> FirstMethod() { var entities = from t in context.Products where {some conditions} select t; foreach( var entity in entities ) { entity.SomeProperty = {SomeValue}; yield return entity; } } where context is ...

Implementing Forms in ASP.net MVC

I have a simple form on a view page, implemented as a user control, that looks something like this: <%=Html.BeginForm("List", "Building", FormMethod.Post) %> //several fields go here <%Html.EndForm(); %> There are two problems I would like resolved, the first is that I would like the controller method that receives this to take a ty...

What is the name of term meaning next approach: A a = new A { Prop1 = a, Prop2 = b };

Hi! Could you please tip how to properly name object construction approach where public proprieties values are being set on object creation? For example, SqlCommand command = new SqlCommand { Connection = connection, CommandType = CommandType.Text }; ...

How do I bring a string from one aspx.cs page to another?

I want to use a string that I have been using in one aspx.cs file over to another. I know this is easy, but how do I go about doing that? ...

Is it possible to evaluate a string containing valid LINQ dynamically / at runtime?

The basic idea is to take a string and evaluate it against an XML File (or any LINQed provider) I found this LINQ Dynamic Query Library. Just had a cursory glance at the documentation which is a single page in the download bundle. This seems to be adding extension methods to parameterize parts of the LINQ Query. Does anyone know if this...

Is there a bug in SqlDataReader.HasRows when running against SQL Server 2008?

Take a look at these two queries: -- #1 SELECT * FROM my_table WHERE CONTAINS(my_column, 'monkey') -- #2 SELECT * FROM my_table WHERE CONTAINS(my_column, 'a OR monkey') -- "a" is a noise word Query #1 returns 20 rows when I run it in Management Studio. Query #2 returns the same 20 rows, but I also see the following in the Messages t...

Convert Enum to String

Which is the preferred way to convert an Enum to a String in .NET 3.5? Enum.GetName Enum.Format toString Why should I prefer one of these over the others? Does one perform better? Justification for Accepted Answer Based on the forum post in panesofglass answer, it appears that Microsoft indirectly endorses the following method of c...

When should I opt for IsolatedStorage versus AppData file storage?

I've recently discovered the IsolatedStorage facilities in .net, and I'm wondering when I should use them for my application data versus when I should use (e.g.) Application.LocalUserAppDataPath. One thing that I've noticed is that Application doesn't exist outside of a winforms app, so it seems that IsolatedStorage might make sense for...

Examples of using F# to query Entity Framework

I'm looking all over Google to find an example or tutorial about using F# to query an Entity data source. Honestly I haven't found much. Have any of you had any luck ? ...

HQL in operator and parameters

Hello. There is need for quering NHibernate for several instances of the entity. I've tried following code, but it failed with wired NRE indepth of NHibernate. var query = NHibernateSession.CreateQuery("from User u where u.id in (:ids)"); query.SetParameterList("ids", new Guid[]); query.ToList(); It looks like common problem - any s...

Mitigating double mapping model overhead

After too much thought, I've decided to use Linq To SQL as a DAL for my project, but keep the business objects as POCO objects. This will give some flexibility because the database schema is old and have some problems that can not be solved, because backward compatibility. I'm thinking about making some methods to retrieve or complete ...

Why is System.Object not abstract in .NET?

I know it is commonly used as a lock object, but is that really sufficient reason? What is the meaning of object o = new object(); An non-abstract class is something that represents actual objects. "asdasdf" is a string. What actual instance can there be of "object" class? It doesn't make sense, OOP-wise. My question is if there is so...

How to avoid duplicate app.config using Visual Studio 2008 unit testing?

When I have one app.config in my main project I always have to duplicate it to its test project. How to avoid it? Update I also asked a very similar, and slightly complicated question ...

Is it possible to achieve the "Aero Glass" look on XP?

Does anyone know any kind of framework that enables (not exactly the same, but) Vista's Aero Glass on XP? I need to develop a little desktop application with WPF, which has a Vista-like UI on XP. I don't need exactly the Aero Glass, some UI like "Windows Live Messenger" will do the thing. Is there any way to make it a reality? ...

P/Invoke SHSetKnownFolderPath

EDIT: Scotty2012 and David Morton's answers don't work for me so I have put a bounty on this question. I think I need to change the type of the string to something else before passing it in. I'm not much cop at P/Invoke and I'm struggling with declaring and calling SHSetKnownFolderPath. I'm using VB9 but if anyone puts answers in C# I...

How to avoid duplicate settings when using 2 projects and 2 testing projects in Visual Studio?

Following my previous question, now I have 2 projects: one Console Project and a Library Project. They also have their respective unit test projects. When I run a test for the console project that uses a method from the library project and the library project needs an app.config setting, that setting must be in the console test project's...

Visual Studio 2010 - WPF / Silverlight and built-in Grid

I haven't had a chance to look at VS2010. Is there a built-in Microsoft Grid for WPF or Silverlight yet? ...