.net

constructor chaining

Sample code : public class CA { public CA(string s, List<int> numList) { // do some initialization } public CA(string s, int num) : this(s, ListHelper.CreateList(num)) { } } public static class ListHelper { public static List<int> CreateList(int num) { List<int> numList = new List<int>()...

Proper way to Mock repository objects for unit tests using Moq and Unity

At my job we are using Moq for mocking and Unity for an IOC container. I am fairly new to this and do not have many resources at work to help me out with determining the best practices I should use. Right now, I have a group of repository interfaces (Ex: IRepository1, IRepository2... IRepository4) that a particular process needs to use ...

How to access app.config/web.config for the current Application?

Although in name this question is similar to this and this, it's not. I'm currently developing a library that may require some custom configuration depending on the user's desire. I have created a custom configuration section, and everything works just fine. However, when I was debugging I noticed that the configuration section const...

Publish Version vs Assembly (etc) Versions

Hi! I've read threads here about the Assembly, File and Assembly Informational versions. I'd like to know where the Publish version fits in. The result of... string thisAppsVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); ...appears to be the AssemblyVersion. Up until now I've been using the ...

Dynamically changing the DLL in .NET

I am trying to find a solution for dynamically loading the updated dll from a folder or database in a winform (C#.NET) application. Suppose I have an exe (say MainApplication.exe), which will act as a wrapper/container for the real business logic. The business logic will sit inside the assembly (say Business.dll). Now, how would I dynam...

Comment trees in sql and html

I want to think of a way to display and query comments. Each comment can have children and siblings. I would like to display 40 comments in a page. However, I would like to show all the children. The problem here is if a child has more then 40 comments beneath it this will not work out. Also, I have no idea how I might get the comments....

Scanning a coin and then determining the date from the image

I want to write a .NET program that takes an image of a specific coin type (say a US nickle) and then searches the image for the year. Assume the scan is always 300dpi and has a consistent image size cropped to the coin. What changes is the rotation of the coin. So how would I determine the date? Should I image match by creating a libra...

Finding which function was used to assign the variable (Through variable which is assinged )

I have one function GetControlRectangle(Rectangle MethodRect) that accepts the rectangle of the control. Now I write the code like Rectangle rct=dataGridView1.GetCellDisplayRectangle(1,0,false); which finds the location of the cell(1,0) of the datagridview1. And I pass this rct to the method GetControlRectangle. Now how to find throu...

Is it possible to create a collection of generic contrained types in .net?

Is something like this possible? Dim l As New List(Of T As Type Where GetType(BaseClass).IsAssignableFrom(T)) Note, my collection will be a collection of Types, not objects of type T - which I know is possible. ETA: The answers I've had so far are as expected - I didn't think it was possible. What I'm trying to get my head round is...

.NET memory model, volatile variables, and test-and-set: what is guaranteed?

I know that the .NET memory model (on the .NET Framework; not compact/micro/silverlight/mono/xna/what-have-you) guaranteed that for certain types (most notably primitive integers and references) operations were guaranteed to be atomic. Further, I believe that the x86/x64 test-and-set instruction (and Interlocked.CompareExchange) actuall...

Simple description of worker and I/O threads in .NET

It's very hard to find detailed but simple description of worker and I/O threads in .NET What's clear to me regarding this topic (but may not be technically precise): Worker threads are threads that should employ CPU for their work; I/O threads (also called "completion port threads") should employ device drivers for their work and ess...

Can Text-to-speech work on Windows Azure ?

I've got a web app that converts text to audio using Microsoft .NET Speech library (System.Speech). i want to know if this app can be migrated to Windows Azure, and if Azure can still allow me to use the System.speech namespace without any problem ? ...

How to Reflect on the main app from a DLL with .NET?

I have a DLL. from which I would like to get the app's name. The following code, called from the DLL, returns the DLL's full name: string assemblyFullUncPath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase; ...so it isn't quite what I'm after. I could add an Assembly parameter, but I'd prefer not to. Is it ...

Hash quality and stability of String.GetHashCode() in .NET?

I am wondering about the hash quality and the hash stability produced by the String.GetHashCode() implementation in .NET? Concerning the quality, I am focusing on algorithmic aspects (hence, the quality of the hash as it impacts large hash-tables, not for security concerns). Then, concerning the stability, I wondering about the poten...

How do you get the username in Silverlight Out-Of-Browser (SLOOB) apps?

We currently use Silverlight within the browser. ASP.NET writes the Windows Authenticated user name to the ASPX page that the Silverlight control is on. The username is passed as a parameter in to the control when it loads. How would you get the username with an out-of-browser application? ...

Is it possible to to execute code befor all tests are run?

Hi, I am writing integration tests.Now, before tests are run I want to setup the database with initial data.For this, I have created a separate project, which is run before test project is executed(using MSBuild file).But, I want to merge the db setup code in testproject, and have it executed before any tests get executed.I am using MBu...

C# using one method on timer-based and UI event-based calling

In WPF app I have a timer which cyclically performs some database quering operations (LINQ to SQL) and visual controls updating operations by calling a particular method. Sometimes I need to call this the same method by UI events (button clicks, for example). Is there any danger, in case timer-based calling and UI event-based calling o...

Sending and Receiving data through SOAP web service in .Net

I am working on a client - server application and in which I used to send and receive data through SOAP web service. Now after sometimes I have heard from someone that I might lost some data while this process on soap service created in ASP.net. So now I have decided to send and receive data through batches like first I will send List o...

Immediate-window-like command prompt?

Hi, Does anyone know if there exist some kind of immediate-window-like command prompt, either to run from inside VS or as a separate program. It would be nice to have something like that to try and evaluate static methods etc without having to debug the solution (for example, evaluate Path methods) ...

How can I switch .NET assembly for execution of one method ?

I have different versions of dlls for my .NET application and most of the time I want to use the latest one. However, there is one method which I run on a separate thread where I need to be able to select an older version of the dll based on some criteria. I have learned that it is not possible to just load an assembly and then unload i...