.net

Access fields or properties from within the declaring class

Public Class FooBar { private int _foo; public int Foo { get { return _foo; } set { _foo = value; } } public void DoStuff() { _foo++; // Do this? Foo++; // Or this? } } Is there a more accepted practice to either access fields or properties (if one exists) in a class? I've alwa...

How to cast a control to IOleObject

I want to invoke GetClientSite on a .net control. For this purpose I am trying to cast a control (in example Windows.Forms.Form) to IOleObject which returns null. What should I do to get IOleObject? using System; using System.Runtime.InteropServices; using System.Security; using System.Windows.Forms; namespace Test001 { public cla...

Can Microsoft.Contracts' static checker be used without Team System?

Aside from the requirement on Visual Studio Team System to be able to install Microsoft.Contacts with the static checker, is it possible to run the static checker without team system? Or, does it depend on an API exposed by studio's team system components? Also, is it within the license to copy the static checker from a computer with ...

.Net and plugin architectures

Following on from Jeff and Joel's discussions of plugin architectures. Plugins in C++ (using runtime loaded dlls) are always a bit of a pain. You have to do a lot of ground work to enable them and then the plugin must also be written in C++, often even with the same compiler. COM objects and ActiveX solved some of these problems but int...

Is LINQ (or linq) a niche tool, or is it on the path to becoming foundational?

After reading "What is the Java equivalent of LINQ?", I'd like to know, is (lowercase) language-integrated query - in other words the ability to use a concise syntax for performing queries over object collections or external stores - going to be the path of the future for most general purpose languages? Or is LINQ an interesting piece o...

Unhandled Exception in Windows Service

I am using system.timer in a windows service application (c#) and have added: AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyExceptionHandler); To handle my exceptions, does this work in a Windows Service as it does not seem to work? Does nyone have any alter...

Why do `Assembly` and `Module` have no publicly defined constructors?

I'm building a .NET assembly loader in C# for an "experiment"/learning more about .NET internal operations. I've implemented the reflection API by deriving types like: RuntimeType : Type RuntimeFieldInfo : FieldInfo RuntimeMethodInfo : MethodInfo RuntimeParameterInfo : ParameterInfo RuntimeConstructorInfo : ConstructorInfo RuntimePrope...

Iterator block generates try-fault in IL

After experimenting with an iterator block I noticed the generated IL code is not what I expect it to be. Instead of a try-finally block a try-fault block is generated, which I have never seen. I noticed that the compiler doesn't allow me use the fault keyword in 'handwritten' C#. Is there any difference between the 2? C# code: stati...

How do I make my code perform a random function

I want my code to randomize between three different functions: private void BackPack1() { Player.Skin.SetComponent((PedComponent)3, 3, 0); } private void BackPack2() { Player.Skin.SetComponent((PedComponent)3, 3, 1); } private void BackPack3() { Player.Skin.SetComponent((PedComponent)3, 3, 2); } Is there an easy way? ...

Visualization of the timestamps in a call stack

I'm trying to tune the performance of my application. And I'm curious what methods are taking the longest to process, and thus should be looked over for any optimization opportunities. Are there any existing free tools that will help me visualize the call stack and how long each method is taking to complete? I'm thinking something that ...

Making sure C# program can run on machine with only .Net v2

I'm using VS 2005 Standard SP1, with .Net 3.5 SP1 installed on XP. The client machines only have .Net 2.0.50727 installed (also on XP). How can I tell the compiler to reject any classes or methods that are not available in .Net 2? ...

Which one is better ? URLReWriter.net or URLReWriting.NET

I don't know whether you've been come across urlrewriter.net because as I've seen so far urlrewriting.net is kinda more popular. Could someone please tell me which one is actually easier to implement and more powerful? Thanks... ...

How do I convert a regular expression in a valid .NET format to valid Java format?

Hi, I want to use the following regular expression which is written within a C# .NET code, in a Java code, but I can't seem to convert it right, can you help me out? Regex(@"\w+:\/\/(?<Domain>[\x21-\x22\x24-\x2E\x30-\x3A\x40-\x5A\x5F\x61-\x7A]+)(?<Relative>/?\S*)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singlelin...

C#.NET - How Can I Get typeof() to Work With Inheritance?

I will start by explaining my scenario in code: public class A { } public class B : A { } public class C : B { } public class D { } public class Test { private A a = new A ( ) ; private B b = new B ( ) ; private C c = new C ( ) ; private D d = new D ( ) ; public Test ( ) { // Evaluates to "false" ...

The right way to mock (with moq) methods that return mocked objects?

Which of these is correct? var mockLogger = new Mock<EntLibLogger>(); mockLogger.Setup(i => i.CreateTracer(It.IsAny<string>())) .Returns((string operationName) => { var mockTracer = new Mock<EntLibTracer>(operationName); mockTracer.Setup(i => i.IsTracingEnabled()) .Returns(true); ...

Best Way to Render HTML in WinForms application?

I have a WinForms application, running on .net 3.5. This Application generates HTML on the fly, which includes the complete document, and also an inline-CSS-Stylesheet (inside the head element). I am using the WebBrowser control and setting browser.DocumentText to my generated HTML, but that does not seem to properly apply styles on the...

Is WriteFileGather supported in the .NET Class Library

I would like to use the Overlapped IO functions in a .Net app, specifically WriteFileGather. Is this supported through the standard class library? Bonus points: does it work in Mono? ...

HttpWebRequest has no close method?

I am very surprised to see HttpWebRequest has no close method, but its counter-part HttpWebResponse has. It makes me a little bit confused and inconvenient. :-) So, we only need to call Close on response and no need to treat with request? My concern is about leaks and better resource usage efficiency. I am using VSTS2008 + C# + .Net 3.5...

GetLastInputInfo is user specific - is there something similar which gives machine-wide last input time

As per MSDN, http://msdn.microsoft.com/en-us/library/ms646302%28VS.85%29.aspx GetLastInputInfo does not provide system-wide user input information across all running sessions. Rather, GetLastInputInfo provides session-specific user input information for only the session that invoked the function. Is there something simi...

.NET / Mono Database Engine

Are there any DB engines that are implemented entirely in .NET and Mono compatible? I would like to have a DB solution that will run on all platforms via Mono so that I don't have to worry about having separate native binaries for each platform. ...