.net

Freakishly weird interface polymorphism using interface composition

I ended up with something like the following code in a project I'm working on. I thought it was really odd that I was allowed to do it, but now I'm starting wonder what is most likely an architectural gaff on my part led me to this. My questions to you are: What exactly is this called? What are some real world uses of this? Why would...

How to call a VSTO AddIn method from a separate C# project?

I have a C# Excel Add-in project "MyExcelAddIn" that has a public method Foo() to do something complex. For testing purposes, the add-in also defines a toolbar button which is wired to Foo() so I can test this and verify that clicking the button calls Foo() and does what I want it to do. This is fine. Now I want to call this method from...

When do you need to call IDisposable, if you are using using statements?

I was reading another answer. And it made me wonder, when do does one need to explicitly call Dispose if I am using using statements? EDIT: Just to vindicate myself from being a total know-nothing, the reason I asked was because someone on another thread said something implying there was a good reason to have to call Dispose manual...

.Net DirectoryInfo path

Does anyone know how to set the path for DirectoryInfo when I want to map to a folder named images on webRoot. /images Any help much appreciated, Thanks ...

How do you package external libraries in your .Net projects?

A lot of my projects contain the Castle/NHibernate/Rhino-Tools stack. What's confusing about this is that Castle depends on some NHibernate libraries, NHibernate depends on some Castle libraries, and Rhino-Tools depends on both. I've built all three projects on my machine, but I feel that copying the NHibernate/Castle libraries is a bit...

DataTable to Generic List

public static IList<T> ConvertTo<T>(DataTable table) { if (table == null) { return null; } List<DataRow> rows = new List<DataRow>(); foreach (DataRow row in table.Rows) { rows.Add(row); } return ConvertTo<T>(rows); } public static ...

Joining/merging arrays in C#

I have two or more arrays -- one with IDs, one or more with string values. I want to merge these into a hash table so I can look up values by ID. The following function does the job, but a shorter and sweeter version (LINQ?) would be nice: Dictionary<int, string[]> MergeArrays( IEnumerable<int> idCollection, ...

Windows Workflow Foundation NullReferenceException

Hi, I got a NullReference problem using WWF and externaly raised events. The WWF state machine works together with a service instance raising events in the state machine to provide data and - of course - to change the state. While the "normal" operation works fine using events I got a strange problem. To handle timeout scenarios I let...

process tree

I'm looking for an easy way to find the process tree (as shown by tools like Process Explorer), in C# or other .Net language. It would also be useful to find the command-line arguments of another process (the StartInfo on System.Diagnostics.Process seems invalid for process other than the current process). I think these things can only ...

ADO.NET - What is best practice for getting datareader values?

Just wondering what is best practice for getting the values of a datareader. For example: I have been doing this: MyValue = Dr("ColumnName") But have noticed other people doing: MyValue = Dr.GetString("ColumnName") I am intested to know the benifits of the 2nd method ...

What is the best way to make a graph in WPF? (or in general that would apply to WPF as well)

So I am making a piece of software in WPF, and I want to be able to make graphs out of the data I am storing. Just line graphs with x and y axises. Ideally I would want them to have a nice elegant simplicity to them. I know WPF doesn't come with graphs, and I have tried ZedGraph in a WinForms project, but I thought frankly it looked...

Is it possible to add an accessor to a property in .NET by overriding it?

Is it possible to do something like this? class A { public virtual string prop { get { return "A"; } } } class B: A { private string X; public override string prop { get { return X; } set { X = value; } ...

ASP.NET TextBox Control - Get the default text value in code behind?

Hi all! I have been spying the MSDN and can't see a property/method for TextBox that allows you to get the default text value that was set on a field; I want to be able to compare the current txtMyTextBox.Text to the default value (like this psuedo code shows): var myValue = (String.Compare(txtMyTextBox.Text, txtMyTextBox.DefaultText) ...

How to translate MS Windows OS version numbers into product names in .NET?

How to translate MS Windows OS version numbers into product names? For example, in .NET the following two properties could be used to work out that the product is MS Windows Vista Ultimate Edition : Environment.OSVersion.Platform returns Win32NT Environment.OSVersion.Version returns 6.0.6001.65536 ...

Complex query in nHibernate using DetachedCriteria

Hello! I'm currently trying to move from hand-crafted hql to queries constructed via DetachedCriteria. I have and HQL: from GenericObject genericObject left join fetch genericObject.Positions positions where (positions.Key.TrackedSourceID, positions.Key.PositionTimestamp) in (select gp.Key.TrackedSourceID, max(gp.Key...

using c# .net librarires to check for IMAP messages from gmail servers

Hi, Does anyone have any sample code in that makes use of the .Net framework that connects to googlemail servers via IMAP SSL to check for new emails? Thanks ...

Baffling Child object instantiation

I have an object (Incident) which has a child object (Action). An Incident may have zero or or one Action objects. I'm attempting to test whether the Incident object has a child Action object with the following code: If Not MyIncident.Action Is Nothing In theory this should work but for some reason the child Action object is mysterious...

Convert datetime?

i try to write some code: Firstly there is a textbox. if you write 13 in textbox, it equals 13.02.2009 (datetime) Secondly if datetime.now equals 15.02.2009 , you write 13 in textbox, a function return 13.03.2009. Help me thanks... ...

ASP.NET MVC performance has suddenly become very slow

I'm using Billy McCafferty's rather excellent S#arp Architecture. Everything was spiffing and running very quickly. I then updated to the the latest ASP.NET MVC RC. This meant I had to get the latest trunk of S#arp. Also, two weeks ago, I updated from XP to Vista (32 bit) My problem is that the performance has suddenly become woeful...

What is the most impressive LINQ statement that you have come across?

I recently came across this raytracer in LINQ. Just wondering if anyone can top that? var pixelsQuery = from y in Enumerable.Range(0, screenHeight) let recenterY = -(y - (screenHeight / 2.0)) / (2.0 * screenHeight) select from x in Enumerable.Range(0, screenWidth) let recenterX = (x - (screenWidth / 2.0)) / (2.0 * screenWidth) ...