.net

Odd Reflector Decompile with Invalid Token Error

Would some kind person help me sort out the output of .Net Reflector v6.5 that does not compile? I think that the symbols are out of whack but global search and replace might fix that. I don't get the odd class definition. Ideas? [CompilerGenerated] private sealed class <ApplicationTaskIterator>d__0 : IEnumerable<ApplicationT...

How does indirection introduced by interfaces and factories affect performance?

Hi all, I would like to improve testability of some legacy code. To achieve this, I am introducing interfaces for existing classes (and have existing classes implement those) and factories that create an instance of a test object or an object of the original class, depending on some configuration setting. I can foresee some internal fe...

How are you using the pattern matching functionality in ReSharper 5?

Resharper 5's new pattern matching seems very powerful, though it takes a bit of tinkering to work out how to use it. For those who aren't familiar with this feature, it allows you to search for specific patterns within your code. Instances of such patterns may optionally be replaced with an alternative. In IntelliJ this was called st...

Using Events/Commands with XamlReader

I am dynamically building my datatemplate using XamlReader.Parse(string). The problem I have is that I can't put any events on any of the controls I create using the XamlReader. After doing some research online I've learned that this is a known limitation of XamlReader. I don't know a lot about commands in WPF but could I somehow use t...

implicit or explicit conversion from T to T[]

Is there a way to implement a generic implicit or explicit converter for anything to an array of anything, something like this: public static implicit operator T[](T objToConvert) { return new T[] { objToConvert }; } ...

which .net components does my application need?

I built a vb.net desktop application. it works beautifuuly on my pc. I created an installer and gave it to a co-worker to run. The program does not work. Question: How can I figure out which .net components i need to provide along with my application? Thanks ...

C# Efficiently Dividing Tasks Between Cores

I'm working on a small simulation that is running on my 8-core workstation. The simulation involves modeling the interactions between a large number of independent nodes. During one phase I need to perform a series of simple atomic operations to each node in parallel. I have been using Parallel.ForEach from System.Threading.Tasks to a...

Listview to Excel HTML markup issue

I'm using code similar to code mention at http://www.dutch-creatives.com/post/2009/08/11/Export-ListView-to-Excel.aspx to export Listview to excel My listview <asp:ListView ID="lv" runat="server"> <LayoutTemplate> <table runat="server" id="table1" class="datatable" > <tr class="r...

Directory.Move() works in debug mode, but not when deployed

I have a webapp which has read/write/execute access to an aliased directory. When I am in debug mode in Visual Studio, the following statement works: Directory.Move("\\\\localhost\\Alias\\oldDirectory","\\\\localhost\\Alias\\newDirectory"); The net result is that, oldDirectory is now newDirectory in the aliased directory. But, when ...

Change ToolTip font

I need a tooltip with custom Font. I have the following code, and this works... but the tooltip size does not fit the text. Where is the error? Public Class KeolisTooltip Inherits ToolTip Sub New() MyBase.New() Me.OwnerDraw = True AddHandler Me.Draw, AddressOf OnDraw End Sub Private _Font As Font Public Prope...

Creating extra type definitions at compile time

Recently I've been working with MSTest, and I noticed that the testframework generates accessor classes dynamically at compile time. How can one do this? There's an xml file in a VS2010 C# project. I'd like to make an enum out of certain data in this xml file. Can this be done? And if so, how? ...

Type mismatch error. F# type inference fail?

I'm trying to write a method in F# that returns a new instance of a generic type based upon the type of a value passed into the method. In FSI: open System.Collections.Generic type AttributeIndex<'a>() = inherit SortedDictionary<'a, HashSet<int array>>() let getNewIndexForValue (value: obj) : AttributeIndex<_> = match valu...

I want to programatically generate a click on a DataGridView Row in C#

I have a DataGridView in a form and I want to programatically click its first row. I have found code to select its rows or columns from code. For eg. datagridview.Columns[0].Selected = true; datagridview.Rows[0].Selected = true; However this code is not raising the click event on the datagridview. If any one has coded how to click a da...

DataContractJsonSerializer or JsonTextWriter for arrays

I'd prefer to use Microsofts System.Runtime.Serialization.Json.DataContractJsonSerializer to serialize my objects in JSON so I do not have to reference any third party assemblies. I'm trying to serialize arrays into a JSON string. There maybe just 1 array, with every other entry being the name and other being the value. e.g.[ "name1", "...

what is the best way to handle potential non thread safe events

please consider the following scenario for .net 2.0: I have an event that is fired on system.Timers.Timer object. The subscriber then adds an item to a Windows.Forms.Listbox upon receiving the event. This results in a cross-thread exception. My question is what would be the best way to handle this sort of situation. The solutions that ...

SqlFileStream Write bug?

I've been writing and reading PDF's to a SQL Server 2008 FileStream for a few months now without any major problems (apart from tedious user permissions). Yesterday I had a user inform me that some of their PDF's were being corrupted after being written into the FileStream. So, I did some debugging and I found the problem, but it appears...

Concatenating multiple result rows into a single result without using FOR XML PATH

I've inherited a stored procedure that uses FOR XML PATH in a subselect to concatenate multiple result rows from the subselect into a single result column on the "main" query. Consider the following, where table "z" is part of the main query's FROM clause: SELECT SUBSTRING((SELECT ('; ' + RTRIM(c.SomeField)) FROM a (NOLOCK) INNER JOIN ...

Should I create new Pens/Brushes per Paint request or keep them throughout the application lifecycle?

I have an application that does a lot of drawing, let's pretend it's a Viso-like application. It has objects that have multiple sub-objects that are drawn, things can be connected, resized etc. Currently when I call paint on a particular sub-object or object, I do the following: using(var pen = new Pen(this.ForeColor)) { // Paint fo...

Remove formatting from a string: "(123) 456-7890" => "1234567890"?

I have a string when a telephone number is inputted - there is a mask so it always looks like "(123) 456-7890" - I'd like to take the formatting out before saving it to the DB. How can I do that? ...

best practices for download big files using WCF and ASP.NET

I Have this architecture: WebSite ASP.NET <------> WCF Service <--------> DataBase DAtabase gathering very big files. User request a big file in aspx page, through WCF Service. Service call database, and get the big file. Now, my entity (datacontract) has those fields: string Data1 string Data2 string Data3 byte[] FileBigger How t...