The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,318 other followers

Archive for July 15th, 2009

C#/.NET – GetExecutablePath – borrowed a bit from the Delphi 2006 RTL

Posted by jpluimers on 2009/07/15

Somehow, at every client I need a function like GetExecutablePath.

Maybe you do too, so here is the code that I adapted a long time ago from the Delphi 2006 RTL:

using System;
using System.Diagnostics;
using System.Reflection;
namespace bo.Reflection
{
    public class AssemblyHelper
    {

        public static string GetExecutablePath()
        {
            // borrowed from D2006\source\dotNet\rtl\Borland.Delphi.System.pas function ParamStr():
            string result;
            Assembly entryAssembly = Assembly.GetEntryAssembly();
            if (null != entryAssembly)
            {
                result = entryAssembly.Location;
            }
            else
            {
                Process currentProcess = Process.GetCurrentProcess();
                ProcessModule mainModule = currentProcess.MainModule;
                result = mainModule.FileName;
            }
            return result;
        }
    }
}

Enjoy :-)

–jeroen

Posted in .NET, C#, C# 2.0, C# 3.0, Delphi, Development, Software Development, Visual Studio and tools | 2 Comments »

C#/.NET – Small TextBoxTraceListener for quick and dirty tracing in Windows.Forms applications

Posted by jpluimers on 2009/07/15

Don’t know how many decades ago I got the idea, and there are probably dozens of unfinished samples like these, but below is complete one.

bo.Forms.TextBoxTraceListener.

But first the feature list:

  • Allows Trace statements to be catched in a TextBox (you probably guessed this from the name TextBoxTraceListener)
  • Works in both the UI and non-UI threads (so it does not fail when calling from a non UI-thread)
  • Supports Write and WriteLine (no need to override the others as they all come down to this)
  • Does not do indentation (hey, it’s quick and dirty!)

Note that TextBox.Text is not meant for large amount of data, or frequently appending to the data, but again: it’s meant as quick and dirty, not as your tracing ‘silver bullet’.

Read the rest of this entry »

Posted in Debugging, Development | Leave a Comment »

 
<span>%d</span> bloggers like this: