July 2009 Entries

Declare local variable within the loop instead of using loop variable in Linq methods

I've noticed in my LINQ code Resharper Warning "'Access to modified closure'". The search pointed that there is very confusing potential error. If for/foreach loop variable is used only in Linq methods (more general, only as a parameter for delegates) , only the last value of the variable will be used for all calls. It always required to create local variable inside loop and use the local variable instead of loop variable. More about the issue: Linq: Beware of the 'Access to modified closure' demon ......

Implement Copy constructor using Serialization or Reflecton

Some time ago I wrote a post No Copy Constructor support in .Net framework. and was adviced by Tim Hibbard to use reflection like this. I've created Copy method to copy Fields(not only properties, and found that the private fields of any base class are not copied. The article Where are my fields? « Andrew Smith explains that it's required to iterate base classes. But when looking in the Google for the solution,I've found the suggestion for serializable objects: MemberInfo [] sm = FormatterServices ......

Text from SQL Management Studio reformatted by Google Docs when using IE.

When I am using Google Docs, quite often I am copying the portion of code from Visual Studio or SQL Management Studio. but the text is reformatted to become messy. E.G. ALTER PROCEDURE [dbo].[CheckNotProcessed] @limit int = 10 AS declare @StartDate datetime declare @EndDate datetime declare @NotProcessedCount int is shown as ALTER PROCEDURE [dbo].[CheckNotProcessed] @limit int = 10 AS declare @StartDate datetime declare @EndDate datetime declare @NotProcessedCount int I've tried to manually insert ......

Custom alert on the SQL Database

I wanted to create a custom alert on the SQL Database when number of records with some values(considered as invalid) exceeds the expected limit. First of all you need to Set up Database Mail for SQL 2005 and follow procedure How to setup SQL Server alerts and email operator notifications IMPORTANT: don't forget to Restart SQL Agent to activate settings. Similar to the article Define custom error messages in SQL Server 2005 I've defined the error EXEC sp_addmessage 60001, 1, N'Number of not-processed ......

MSbuild Task FileUpdate to replace content in text files

I wanted to replace some strings in files using my deployment MSbuild script. I've noticed that MSBuild Community Tasks Project has RegexReplace task. But when I've looked in documentation (By the way, it will be good if Reference help will be available online, not only from download) I've realized that the task is applicable for strings(e.g file names) not to content within a file. Almost accidently in one of the posts i've found a reference to FileUpdate task, that support Regex and does content ......

«July»
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678