Archive for the ‘.NET 1.x’ Category
Posted by jpluimers on 2014/01/29
In the .NET/C#: fun with enums and aliases part 1 you saw that an enumerated type can specify an underlying type.
The underlying type is limited to a strict set of built-in C# types: , so you cannot use a CTS type for it.
So you might think that you can only define enumeration values by integer constant like this:
namespace BeSharp
{
enum TwoState
{
False = 0,
True = 1,
}
enum ThreeState
{
False = 0,
True = 1,
Unknown = -1,
}
}
Well, you can do it like this too, since Operations between different enum types are allowed in another enum declaration: Read the rest of this entry »
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 2014/01/21
I remember doing this in DOS ages ago (in the Turbo Pascal 5 era) for exactly the same reason: flash the keyboard LEDs to indicate some event was happening, but I’ve yet to find back the source code.
Here is how to do it in Windows using either C# or C: Faking num lock, caps lock and scroll lock leds – About My Code.
–jeroen
via: c# – Way to turn on keyboard’s caps-lock light without actually turning on caps-lock? – Stack Overflow.
Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C++, Development, Pascal, Software Development, Turbo Pascal | Leave a Comment »
Posted by jpluimers on 2014/01/01
For a project, I needed to strip the potential Path.DirectorySeparatorChar and Path.AltDirectorySeparatorChar.
Where Path.Combine will combine two paths and insert the DirectorySeparatorChar, I could not find the opposite, so I wrote this little piece of code:
using System.IO;
namespace BeSharp.IO
{
public class PathHelper
{
public static string RemoveTrailingDirectorySeparators(string directory)
{
string result = directory.TrimEnd(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
return result;
}
}
}
–jeroen
via:
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 2013/12/26
My mental association with getting LogicalDrives was always the System.IO namespace, so I’ve always used Directory.GetLogicalDrives Method (System.IO) .
Recently I bumped into Environment.GetLogicalDrives Method (System), and discovered it has been available for the same time: since .NET 1.x.
I was not so much amazed that these methods return exactly the same data, but that they have identical code. Not just a single call to some common code: their code is the same, line by line. In .NET 4, they have the code below. Read the rest of this entry »
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 2013/12/25
StackOverflow user Joe (sorry, no last name) helped me big time by answering my question on Business logic shared by ASP.NET / WinForms: find the location of the assembly to access relative files to it.
Before showing the code at the bottom of this blog post, let me explain the question in more detail:
Basically I was in the midst of refactoring some ‘inherited’ business logic code that – before refactoring – for the ASP.NET side needs to be initialized with an absolute path, but on the WinForms / WPF side only with a relative path to a GetExecutingAssembly directory.
To ease xcopy deployment, I wanted all configuration settings to be relative. But I hadn’t found a common means for these platforms to obtain a directory usable as a root for accessing relative files.
That way I could put identical settings in both the Web.config and App.config, heck even generate them based on a common fragment, whithout having to hard-code absolute path names.
I knew about Assembly.GetExecutingAssembly, but in ASP.NET that location is not where the web site is (both IIS and the WebDevelopment server make use of temporary locations to store the assemblies).
ASP.NET does have Server.MapPath and HostingEnvironment.MapPath, but I didn’t want to make the business logic depend on ASP.NET.
Joe came up with this solution, which works dandy: Read the rest of this entry »
Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, ASP.NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, F#, Prism, Software Development, VB.NET, VB.NET 10.0, VB.NET 11.0, VB.NET 7.0, VB.NET 7.1, VB.NET 8.0, VB.NET 9.0, Web Development | Leave a Comment »
Posted by jpluimers on 2013/12/18
Thanks StackOverflow user splattne (Stefan Platnner) for explaining the differences between the various parameters you can pass to Server.MapPath, and giving some very clear examples.
You can also use it with HostingEnvironment.MapPath, which has the added benefit that it doesn’t require HttpContext (for more detail on it, see Working With HttpContext.Current).
–jeroen
via:
Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, ASP.NET, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2013/12/10
Some things you have done for ages, are already phrased so nicely, the only thing you can do is quote.
Thanks Dave Coulter:
You can attach the Visual Studio debugger to a process by:
Debug > Attach to Process > Attach Read the rest of this entry »
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, Visual Studio 11, Visual Studio 2002, Visual Studio 2003, Visual Studio 2005, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools | Leave a Comment »
Posted by jpluimers on 2013/11/27
WorPress did it again to me:
2013/10/08; Missed schedule
Anyway:
If you still have a coded base in the .NET Framework 1.1 / Visual Studio 2003, then you should note that after 20131008, the extended support has ended.
Though the introduction of both feels like yesterday to lots of us, they have been supported for more than 10 years. An era has ended. Time to move on to newer versions has passed long ago.
The next important date is about 2.5 years from now: 2016-04-12, when the support for the .NET Framework 2.0 and Visual Studio 2005 ends.
From the Microsoft Support Lifecycle: .NET Framework 1.1 and Microsoft Support Lifecycle: Visual Studio .NET 2003 pages (I formatted the dates into YYYY-MM-DD): Read the rest of this entry »
Posted in .NET, .NET 1.x, C#, C# 1.0, Development, Missed Schedule, SocialMedia, Software Development, Visual Studio 2003, Visual Studio and tools, WordPress | Leave a Comment »
Posted by jpluimers on 2013/10/22
Every once in a while, you will have to do is checks using reflection.
Basically there are two methods:
Thanks to Ani and Werner Beroux for explaining the difference in more detail on StackOverflow, I added some extra links:
To check for assignability, you can use the Type.IsAssignableFrom method:
typeof(SomeType).IsAssignableFrom(typeof(Derived))
This will work as you expect for
but not when you are looking for ‘assignability’ across explicit / implicit conversion operators.
To check for strict inheritance, you can use Type.IsSubclassOf:
typeof(Derived).IsSubclassOf(typeof(SomeType))
–jeroen
via: c# – How to check if a class inherits another class without instantiating it? – Stack Overflow.
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 2013/10/17
A while ago, I bumped into a situation where someone had tried to solve the problem below with a convoluted reflection based solution for this seemingly simple problem:
class A {}
class B : A {}
B b = new B();
if(b is A) // this should return false
And indeed the solution is simple: replace the “b is a” with this:
b.GetType() == typeof(A)
Thanks StackOverflow users ChaosPandion and John K.
–jeroen
via c# check for exact type – Stack Overflow.
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 »