Every time I use regular expressions (or post about them), it makes me think about the classic RegEx post by Jeff Atwood: to compile or not to compile.
BTW: Happy 2013!
–jeroen
Posted by jpluimers on 2013/01/01
Every time I use regular expressions (or post about them), it makes me think about the classic RegEx post by Jeff Atwood: to compile or not to compile.
BTW: Happy 2013!
–jeroen
Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, RegEx, Software Development | Leave a Comment »
Posted by jpluimers on 2012/12/26
There is a lot of information in Assembly that is either internal or private. Luckily you van get an AssemblyName instance through Assembly.GetName() or Assembly.GetName(Boolean) which has quite a few public members that get initialized while calling the internal AssemblyName.Init method.
This is the member mapping of AssemblyName members to Assembly members:
| AssemblyName member | Assembly member |
| Name | GetSimpleName() *internal |
| GetPublicKey() | GetPublicKey() *internal |
| GetPublicKeyToken() | null |
| Version | GetVersion() *internal contains the AssemblyVersionAttribute of the assembly |
| CultureInfo | GetLocale() *internal |
| HashAlgorithm | GetHashAlgorithm() *private |
| VersionCompatibility | AssemblyVersionCompatibility.SameMachine |
| CodeBase | GetCodeBase(Bool) *internal |
| Flags | GetFlags() | AssemblyNameFlags.PublicKey |
| KeyPair | null |
| ProcessorArchitecture | complex set of calls |
–jeroen
Posted in .NET, .NET 3.5, .NET 4.5, ASP.NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2012/12/20
Posted in .NET, Development, F#, Software Development | Leave a Comment »
Posted by jpluimers on 2012/12/18
Ever since .NET 1 there has been no built-in way to create a file including all its parent directories.
Hence small FileHelper class far below.
The fundament of the class is this CreateUnderlyingDirectory method, that uses System.IO.Path.GetDirectoryName to obtain the parent directory of a path, and then System.IO.Directory.CreateDirectory to create it (and any parent directories) if needed.
public static void CreateUnderlyingDirectory(string path)
{
string directoryPath = Path.GetDirectoryName(path);
Directory.CreateDirectory(directoryPath); // NOP if it exists, will create all parent directories if not
}
A few helper methods get you a StreamWriter either empty/appended, or always empty Read the rest of this entry »
Posted in .NET, .NET 3.5, .NET 4.5, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2012/12/12
One of our solutions would not completely build.
An console application that was hardly used, was not built.
No warnings or hints in the “Error List”.
This is what the build log would show:
------ Skipped Build: Project: App404.UI, Configuration: Debug Any CPU ------
Project not selected to build for this solution configuration
========== Build: 21 succeeded or up-to-date, 0 failed, 1 skipped ==========
None of the suggestions at the Stack Overflow question visual studio 2005: skipping builds for unknown reason? would work (not even running msbuild with the highest verbosity level, you get so much information that it is impossible to weed the useful from the useless information).
Luckily, About | WishMesh pointed me in the right direction: inspect your solution file for anomalies. Read the rest of this entry »
Posted in .NET, C#, C# 4.0, Development, Software Development, Visual Studio 11, Visual Studio 2005, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools | Leave a Comment »
Posted by jpluimers on 2012/12/07
While developing x64 applications, most Windows development tools are actually running in x86 mode, and use an intermediate x64 layer to debug the x64 process even for local debugging.
For Visual Studio 2008 and up, this is msvsmon.exe (for Delphi XE2 and up it is PAServer.exe for remote debugging or [WayBack] dbkw64_16_0.exe for local debugging, other tools use a similar mechanism).
The fun thing with Visual Studio is that when msvsmon.exe fails to load locally, you get a misleading error message:
[Microsoft Visual Studio]
Error while trying to run project: Unable to start debugging.
The Microsoft Visual Studio Remote Debugging Monitor has been closed on the remote machine.
[OK]
I found two workarounds myself :
I learned the why from Steve Steiner: he posted the StackOverflow answer explaining msvsmon.exe is also used for local x64 debugging.
Delphi XE2 and up sometimes have a similar cryptic message (I forgot to jolt it down, next time I come across it, I will edit this blog post) and usually killing PAServer.exe or dbkw63*.exe or restarting the IDE solves it.
–jeroen
via:
Posted in .NET, Debugging, Delphi, Delphi x64, Development, QC, Remote Debugging, Software Development, Visual Studio 11, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools | Leave a Comment »
Posted by jpluimers on 2012/12/06
Thanks Nick Craver for answering this on StackOverflow.
Array initializers can be specified in field declarations (§17.4), local variable declarations (§15.5.1), and
array creation expressions (§14.5.10.2).
The array initializer can end in a comma, which makes some things way easier (boy, I wish I had this in other programming languages).
From Nick’s answer:
It has no special meaning, just the way the compiler works, it’s mainly for this reason:
[FlagsAttribute]
public enum DependencyPropertyOptions : byte
{
Default = 1,
ReadOnly = 2,
Optional = 4,
DelegateProperty = 32,
Metadata = 8,
NonSerialized = 16,
//EnumPropertyIWantToCommentOutEasily = 32
}
[/language]By comment request: This info comes straight out of the ECMA C# Specification (Page 363/Section 19.7)“Like Standard C++, C# allows a trailing comma at the end of an array-initializer. This syntax provides flexibility in adding or deleting members from such a list, and simplifies machine generation of such lists.”
–jeroen
via c# – .NET Enumeration allows comma in the last field – Stack Overflow.
Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C++, Delphi, Development, Java, JavaScript/ECMAScript, PHP, Software Development, VB.NET | 5 Comments »
Posted by jpluimers on 2012/12/04
WinForms does not automatically enable Ctrl-A as “Select All” action.
The below code snippet works when you bind it to the KeyDown event of a TextBox (actually the event is on Control).
The e.SuppressKeyPress = true suppresses the bell sound in a multiline TextBox, as e.Handled = true won’t.
private void textBox_KeyDown_HandleCtrlAToSelectAllText(object sender, KeyEventArgs e)
{
TextBox textBox = sender as TextBox;
if (null != textBox)
{
if (e.Control && e.KeyCode == Keys.A)
{
textBox.SelectAll();
e.SuppressKeyPress = true;
}
}
}
–jeroen
Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2012/11/28
I was involved in porting a Visual Studio 2003 VB.NET solution to the latest Visual Studio.
One of the things present was a binary (don’t ask) version of the VBPowerPack, which used to be available on GotDotNet.
Though you can link against .NET 1.1 assemblies from .NET 2.0 and up, I’d rather have source.
That allows me to fix things whenever something comes up (it probably does, as VBPowerPack was pre-Aero, so the controls in it might need some adjustments).
GotDotNet was hated by many people, and finally closed in 2007 by Microsoft in favour of CodePlex (don’t you just love the cloud?).
Luckily, people do archive stuff, so VB Helper has VBPowerPack.
The download is a simple MSI installer, that you can extract using something like this:
msiexec /a PathToMSIFile /qb TARGETDIR=DirectoryToExtractTo
–jeroen
via:
Posted in .NET, Development, Software Development, VB.NET, Visual Studio 11, Visual Studio 2002, Visual Studio 2003, Visual Studio 2005, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools | 1 Comment »
Posted by jpluimers on 2012/11/21
Often when comparing characters with a list of characters, that list does not consist of consts.
It if were, you could make a switch statement:
switch (item)
{
case '/':
case '\\':
case ';':
addSeparator(separatorsUsed, item);
break;
}
But reality is that you cannot do things like this:
switch (item)
{
case Path.AltDirectorySeparatorChar: // Error: A constant value is expected
case Path.DirectorySeparatorChar:
case Path.PathSeparator:
addSeparator(separatorsUsed, item);
break;
}
However, you can perform a small trick and use LINQ to write some pretty elegant code based on Contains.
char[] pathSeparators = { Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar, Path.PathSeparator };
// LINQ: http://stackoverflow.com/questions/1818611/how-to-check-if-a-char-in-a-char-array/1818635#1818635
if (pathSeparators.Contains(item))
addSeparator(separatorsUsed, item);
The LINQ logic has the logic backwards (you can think of it like “item in pathSeparators”, but it is far easier to read than this:
if ((item == Path.AltDirectorySeparatorChar) || (item == Path.DirectorySeparatorChar) || (item == Path.PathSeparator))
addSeparator(separatoseparatorsUsedrsInUse, item);
Full source of a demo application: Read the rest of this entry »
Posted in .NET, .NET 3.5, .NET 4.5, C#, C# 3.0, C# 4.0, C# 5.0, Development, LINQ, Software Development, Visual Studio 11, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools | 2 Comments »