Archive for the ‘.NET’ Category
Posted by jpluimers on 2013/11/27
As of Visual Studio 2010 SP1 (I think it was there in the original non-SP1 version of VS2010), Microsoft has hidden the addition of classic ASCX webservices as they favour WCF over ASPX (there are quite a few differences).
It is easy to workaround though as Stack Overflow users User Cyberherbalist and User Alejandro Martin have shown, with a little bit post-editing from me: Read the rest of this entry »
Posted in .NET, .NET 4.0, .NET 4.5, ASP.NET, C#, C# 4.0, C# 5.0, Development, SOAP/WebServices, Software Development, Visual Studio 11, Visual Studio 2010, Visual Studio and tools | Leave a Comment »
Posted by jpluimers on 2013/11/26
For some remote monitoring, I needed to get information on UNC paths.
Though suggested, you cannot do this using the System.IO.DriveInfo class (not through the constructor, nor through the VB.NET FileSystem way) as that is about drives, not UNC paths. The System.IO.DriveInfo constructor clearly indicates it doesn’t work with UNC paths. And if you still try, this is the error you will get:
System.ArgumentException was unhandled
HResult=-2147024809
Message=Object must be a root directory ("C:\") or a drive letter ("C").
Source=mscorlib
StackTrace:
at System.IO.DriveInfo..ctor(String driveName)
Same for WMI: that only works when the UNC path has already been mapped to a drive letter.
You could do with adding a temporary drive letter but since there is nothing as permanent as a temporary…
P/Invoke
The actual solution is based on calling Windows API functions using P/Invoke. Read the rest of this entry »
Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, CSV, Development, Missed Schedule, SocialMedia, Software Development, WordPress | Leave a Comment »
Posted by jpluimers on 2013/11/12
You can pass anonymous types to a method, if that method has a generic parameter type. I regularly use this to Resolving a parameter name at runtime using the Generic Type Cache technique described by Rinat Abdullin.
The other way around however is impossible, as return types cannot, as Alexander M. Batishchev writes in his StackOverflow answer:
You can’t.
You can only return object, or container of objects, e.g. IEnumerable
Jared Par does a bit more elaboration:
You cannot type any method in C# to be the explicit type of an anonymous types. They cannot be “named” so to speak and hence cannot appear in metadata signatures.
If you really want to return a value which is an anonymous type there are 2 options
- Have the return type of the method be System.Object. You can then do evil casting hacks to get a typed value in another method. This is very fragile and I don’t recommend it.
- Use a generic method and a type inference trick to get the return type correct. This would require a very interesting signature definition for your approach.
Anonymous types were not really meant to be passed around in this fashion. At the point you need to pass them around between your functions in this manner, you’re better off explicitly defining a type.
Bummer (:
–jeroen
via:
Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .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 2013/11/07
Wow, I’ve been living under a stone (:
Just discovered the online Cyber-Dojo by Jon Jagger. It is an online manifestation of a Coding Dojo. Both have been there for years, and I think both are brilliant.
They take the concept of a Dojo as being a place to practice sports like martial arts in a pair or group setting with a series of Katas or practices.
Katas in a Dojo are a means for performing deliberate practice in order to learn new things. For instance, acquire new movement techniques, learn about your balance, gain strength, all in both a physical and mental way.
The aim of both is do more deliberate practice.
When performing Coding and Cyber Dojo, you should use Test Driven Development using pair programming and BabySteps. Those help you to slow down, as one of the Dojo Principles is for Katas to slow down. It reminds me of the “if you are in a hurry, sit down” mantra and is a key part of the Coding/Cyber Dojo Principles too.
The aim is to learn, and part of that is to first un-learn and open you to new thoughts. That’s why it is so cool that the Cyber-Dojo provides you with:
- a bunch of pre configured programming languages*,
- preformulated practices** (including a few cyber-dojo refactorings),
- a small boilter plate to get started.
You’d think they speed you up, but that is not their aim. Like a regular Dojo it gives you an pre-set environment and gives you piece of mind to get started.
The Cyber Dojo does without a Sensei, whose purpose in a Coding Dojo is to ask questions in order to guide the participants.
That’s why it is good to use the Cyber Dojo as part of a Coding Dojo: basically the Cyber Dojo provides a standardizes set of tools to quickly setup a Coding Dojo.
Cyber Dojo languages
(a prime number, so the table is a bit distorted)
| C |
Go |
PHP |
| C# |
Haskell |
Perl |
| C++ |
Java-Approval |
Python |
| Clojure |
Java-Cucumber |
Ruby |
| CoffeeScript |
Java-JUnit |
Ruby-Rspec |
| Erlang |
Javascript |
Cyber Dojo practices
Many of the practices come from rosettacode.org.
| 100 doors |
Harry Potter |
Print Diamond |
| Anagrams |
LCD Digits |
Recently Used List |
| Bowling Game |
Leap Years |
Reversi |
| Calc Stats |
Mine Field |
Roman Numerals |
| Count Coins |
Monty Hall |
Tennis |
| Diversion |
Number Names |
Unsplice |
| Fizz Buzz |
Phone Numbers |
Verbal |
| Game of Life |
Poker Hands |
Yahtzee |
| Gray Code |
Prime Factors |
Zeckendorf Number |
–jeroen
via:
Posted in .NET, Agile, C, C#, C++, Development, Java, JavaScript/ECMAScript, Perl, PHP, Scripting, Software Development, Unit Testing | 3 Comments »
Posted by jpluimers on 2013/11/05
For my link archive, thanks Alek Davis:
Just keep in mind that ID of the CPU is not always available.
By the way, what are you trying to accomplish? If you want to generate a unique key for a computer instance, check the Generating Unique Key (Finger Print) for a Computer for Licensing Purposes post by Sowkot Osman at Codeproject; it can give you some hints (also read comments).
–jeroen
via: .net – APIs in C# for grabbing CPU IDs and drive/volume serial – Stack Overflow.
Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .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 2013/10/29
Toon Krijthe posted an interesting question to SO.
Though 5 years old, I think it stilll is very valid one:
At my work, we have decided to stay with the ANSI characters for identifiers. Is there anybody out there using unicode identifiers and what are the experiences?
For all projects I work on (in various Languages like English, German, Dutch or other), I stick to ASCII characters (not even ANSI) for:
I also try to abstract the non-ASCII strings into places where I am sure that the encoding is preserved (for text files, I prefer UTF-8), or where these characters are properly escaped.
What is your take on this?
–jeroen
via: uniqueidentifier – What are the experiences with using unicode in identifiers – Stack Overflow.
Posted in .NET, Agile, AS/400 / iSeries / System i, C, C#, C++, COBOL, Continuous Integration, Delphi, Development, F#, Prism, Scripting, Software Development, VB.NET, Visual Studio and tools | 4 Comments »
Posted by jpluimers on 2013/10/23
Thanks StackOverflow users George Stocker for asking, Örjan Jämte and Sir Crispalot for answering.
Below is the SQL Server 2012 table, in which I added links to the various data types.
I also added two columns with linked references to the types from the C# data types, C# Keywords, Reference Tables for Types (C# Reference) and Data Type Summary (Visual Basic).
One of the things I need to check is against the LINQ SQL-CLR Type Mapping.
It is very important to keep in mind that in SQL, each combination of precision and digits gets you a different decimal type, and all of them are different from the .NET decimal type. See for instance the answers on these questions:
Read the rest of this entry »
Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, Algorithms, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Database Development, Development, Floating point handling, Software Development, SQL Server, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012 | 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 »