.net

How do I escape from a Snippet? (Vb.Net)

In C# when I am done entering the fields of a snippet, I can hit Enter to get to the next line. What is the equivalent Key in VB? Edit: I prefer not to use the mouse. ...

How do I use XPathNodeIterator to iterate through a list of items in an XML file?

This is a sample (edited slightly, but you get the idea) of my XML file: <HostCollection> <ApplicationInfo /> <Hosts> <Host> <Name>Test</Name> <IP>192.168.1.1</IP> </Host> <Host> <Name>Test</Name> <IP>192.168.1.2</IP> </Host> </Hosts> </HostCollection> When my application (VB.NET app) load...

Convert a string to a date in .net

I'm reading text from a flat file in c# and need to test whether certain values are dates. They could be in either YYYYMMDD format or MM/DD/YY format. What is the simplest way to do this in .Net? ...

How to unload an assembly from the primary AppDomain

I would like to know how to unload an assembly that is loaded into the main appdomain. I have the following code: var assembly = Assembly.LoadFrom( FilePathHere ); I need/want to be able to unload this assembly when i am done. Thanks for your help. ...

Rhino Mocks: Re-assign a new result for a method on a stub

I know I can do this: IDateTimeFactory dtf = MockRepository.GenerateStub<IDateTimeFactory>(); dtf.Now = new DateTime(); DoStuff(dtf); // dtf.Now can be called arbitrary number of times, will always return the same value dtf.Now = new DateTime()+new TimeSpan(0,1,0); // 1 minute later DoStuff(dtf); //ditto from above What if instead of...

Modifying Existing .NET Assemblies

Is there a way to modify existing .NET assemblies without resorting to 3rd party tools? I know that PostSharp makes this possible but I find it incredibly wasteful that the developler of PostSharp basically had to rewrite the functionality of the whole System.Reflection namespace in order to make existing assemblies modifiable. System.R...

.NET: How to wait for a BackgroundWorker to cancel?

Consider a hypothetical method of an object that does stuff for you: public class DoesStuff { BackgroundWorker _worker = new BackgroundWorker(); ... public void CancelDoingStuff() { _worker.CancelAsync(); //todo: Figure out a way to wait for it to be cancelled } } How can one wait for a BackgroundWorker to...

What CLR/.NET bytecode tools exist?

I'm well aware of Java tools for manipulating, generating, decompiling JVM bytecode (ASM, cglib, jad, etc). What similar tools exist for the CLR bytecode? Do people do bytecode manipulation for the CLR? ...

Get the resolution of a jpeg image using C# and the .NET Environment?

Our clients will be uploading images to be printed on their documents and we have been asked to come up with a way to get the resolution of the image in order to warn them if the image has too low of a resolution and will look pixalated in the end-product If it comes to it we could also go with the dimensions if anyone knows how to get ...

How can one simplify network byte-order conversion from a BinaryReader?

System.IO.BinaryReader reads values in a little-endian format. I have a C# application connecting to a proprietary networking library on the server side. The server-side sends everything down in network byte order, as one would expect, but I find that dealing with this on the client side is awkward, particularly for unsigned values. U...

how to find usb drive letter?

I'm writing a setup program to install an application to USB drive. the application is meant to be used only from USB drives, so it would save an extra step for the user by automatically selecting USB drive to install to. I might explore using Nullsoft or MSI for install, but since I'm familiar with .NET the most I initially plan to try...

how to determine USB Flash drive manufacturer?

I need my program to work only with certain USB Flash drives (from a single manufacturer) and ignore all other USB Flash drives (from any other manufacturers). is it possible to check that specific USB card is inserted on windows using .NET 2.0? how? if I find it through WMI, can I somehow determine which drive letter the USB drive is ...

Is MEF a replacement for System.Addin?

Is the Managed Extensibility Framework a replacement for System.Addin? Or are they complementary? ...

What's the best way to implement clean UI functionality in WinForms while maintaining a decent decoupled architecture?

I tend to implement UI functionality using fairly self-documenting void doSomething() methods, i.e. if the user presses this button then perform this action then enable this list box, disable that button, etc. Is this the best approach? Is there a better pattern for general UI management i.e. how to control when controls are enabled/disa...

.NET + Copying large amounts of memory tricks

Back in the olden days, there were tricks used (often for blitting offscreen framebuffers), to copy large chunks of memory from one location to another. Now that I'm working in C#, I've found the need to move an array of bytes (roughly 32k in size) from one memory location to another approximately 60 times per second. Somehow, I don't ...

Why are Exceptions not Checked in .NET?

I know Googling I can find an appropriate answer, but I prefer listening to your personal (and maybe technical) opinions. What is the main reason of the difference between Java and C# in throwing exceptions? In Java the signature of a method that throws an exception has to use the "throws" keyword, while in C# you don't know in compilati...

.NET Generic Method Question

I'm trying to grasp the concept of .NET Generics and actually use them in my own code but I keep running into a problem. Can someone try to explain to me why the following setup does not compile? public class ClassA { ClassB b = new ClassB(); public void MethodA<T>(IRepo<T> repo) where T : ITypeEntity { b.MethodB(repo); } } pub...

Using .Net, how can I determine if a type is a Numeric ValueType?

Title says it all... But here's an example: Dim desiredType as Type if IsNumeric(desiredType) then ... EDIT: I only know the Type, not the Value as a string. Ok, so unfortunately I have to cycle through the TypeCode. But this is a nice way to do it: if ((desiredType.IsArray)) return 0; switch (Type.GetTypeCode(desiredType...

Is there a Max function in SQL Server that takes two values like Math.Max in .NET?

I want to write a query like this: SELECT o.OrderId, MAX(o.NegotiatedPrice, o.SuggestedPrice) FROM Order o But this isn't how the MAX function works, right? It is an aggregate function so it expects a single parameter and then returns the MAX of all rows. Does anyone know how to do it my way? ...

.net - How do you Register a startup script?

I have limited experience with .net. My app throws an error this.dateTimeFormat is undefined which I tracked down to a known ajax bug. The workaround posted said to: "Register the following as a startup script:" Sys.CultureInfo.prototype._getAbbrMonthIndex = function(value) { if (!this._upperAbbrMonths) { this._upperAbbrMonths = this...