... Home Contact

Krzysztof Koźmic's blog

You're doing it wrong.


Show appreciation: My Amazon.com Wish List

Me@Twitter

    Currently reading

    Article Categories

    Archives

    Post Categories

    MyPersonal

    Syndication:

    .NET

    There are 19 entries for the tag .NET

    Framework Tips XII: Advanced .NET delegates

    All .NET delegates inherit (indirectly) from System.Delegate class (and directly from System.MulticastDelegate) which has a static CreateDelegate method. The method has two powerful characteristics that are not widely known. All delegate types are implemented by the runtime. What do I mean by that? Let’s have a look at how any delegate type looks at the IL level: All methods are runtime managed, meaning that, in a similar fashion you provide implementation for interface methods, runtime provides implementation for delegate methods. Take a look at the constructor. Regardless of delegate type it always has two arguments:...

    The most important part of .NET 4.0 – code contracts

    There’s been about a year since .NET 3.0 along with C# 3.0 became RTM. Clearly the most publicized feature of the release was LINQ. Is it the most widely used feature? I’d doubt so. Simply because scope of it’s usage is limited and people have yet to learn how to use it properly. Personally the things I’m using the most often are ‘var’ and a feature I’ve been really skeptical about – automatic properties. Now, few weeks after announcements of what is going to be present in the next wave of .NET, Visual Studio and the language, the dust...

    Multilingual .NET applications. Enter .NET localization

    Creating multilingual applications is a huge topic. There are whole books devoted to it, and if you’re serious about it, you should definitely read those, because what you see on surface, is only the tip of an iceberg. If you only want to play with localization or need a quick reference, hopefully this post will help. Fist thing is, .NET is really well thought of if it comes to localization, so if you know what you’re doing, it’s pretty painless to create application that will be easy to translate to other languages (localization is a LOT bigger topic...

    My $0.02 on internal sealed API vs public virtual discussion

    Accidently this post hit the wave of discussion on the blogosphere regarding Microsoft’s approach of keeping very big chunks of APIs internal, sealed, or otherwise unusable by users, and backward compatibility. To some extent I can agree with both sides, because as always, the truth is in the middle, and I believe we’re talking about the solution (keeping things non-public and non-extensible) instead of the actual problem (the way API is designed, that makes a lot of useless parts public, and useful parts non-visible). One ridiculous example I saw is the IlGenerator class. It’s...

    Slower than Reflection; meet StackTrace

    I was entertaining the idea of contextual components that would act differently depending on who called them. System.Diagnostics.StackTrace is the class that allows you to traverse the call stack, and see who called your method. There’s one catch though – it is painfully slow. And by painfully, I mean this: Those two methods are by no means comparable in regard of what they’re doing. They are mere examples of simple tasks: one involving Reflection, and one involving StackTrace. The fact that the difference in performance is nearly two orders of magnitude, should make you think twice...

    Framework Tips I: Clear StringBuilder

    StringBuilder is a class that allows you to manipulate strings in mutable manner. It has many methods allowing you to Append, Insert and Replace, portions of the string. However it does not contain Clear() method, that would allow you to clear the content of a StringBuilder.There is Remove(int,int) method, that allows you to do this, but it requires you to pass two parameters to achieve this. int startIndex = 0; stringBuilder.Remove(startIndex, stringBuilder.Length); There is however easier, and more elegant way to do this. Other than in case of most classes in the framework, StringBuilder's Length...

    Nullable<bool> GetHashCode() - bug or a feature?

    Today I stumbled upon a strange bug, that seems to be a feature of .net framework. I had a method that performed some action upon a instance of a class, lets say Customer, based on the hash value of that record. Seems plain and simple, however my unit test exhibited a strange behavior - in some cases, although Customer record had been updated, it acted as if it was not changed. Short investigation pointed to a field of type bool? (Nullable<bool>), that although its value was changed, returned the same hash code. The problem is, that generic struct Nulllable<T> implements...

    I'm really loving new C# 3.0 features

    The more I use new C# 3.0 syntax the more I love it. I basically still use .NET 2.0/3.0 and VS 2005 at work, but at home I'm migrating to Orcas. And I have to admit that more and more, when I'm at work I wish I could use new syntax. var keyword: it's as simple as it can be, but when you get used to writing: var filteredItem = filter(item); instead of:FilteredItem<MtfModificationLog> filteredItem = filter(item); it's really hard to go back. Initially I thought that using this new keyword would make code less readable. That I would have to...

    Extension Methods "Hello World" I: Introduction

    I decided that it's about time to familiarize myself with new features of .NET 3.5 and C# 3.0. And I don't mean see an overview, because I've read many times about what's new in it, and I have basic understanding of all those new goodies that new version of framework/language brings. What I mean by familiarize is understand thoroughly and that is what this "Hello World" series (hopefully) is (hopefully) about. I'm gonna start with extension methods as this is what I've started playing with already, and then... well we'll see :) Extension Methods are a completely new concept to OOP world (at least...

    How do You regionerate your code?

    I've been using Regionerate for some time, and I'm addicted to it. Literally when I have to write some code on a computer that doesn't have Regionerate installed I feel odd. This tool is simply pure honey and nuts. Only thing I would change is it's default keyboard mapping (ctrl+R for running it), because it collides with Visual Studio/ReSharpers "Refactor" shortcut. So every time I install it I have to go to VS settings and change it to something else (alt+3 at the moment). Main reason for this post however is not to praise Rauchy and his tool, but to...

    Fun with ?: operator

    First of all, take a look at the following code: private string _targetText; private int _maxLines; private int _maxSize;   public int Lines { get { if (_targetText ==...

    NDepend - take high level view at your projects

    In order to avoid accusation for doing crypto-advertisement, I honestly admit, that I have received for free professional licence for NDepend (worth EUR 299) from Patrick Smacchia (dev lead and inventor of the tool). It's kind of weird - I knew about the tool for some time, I even once downloaded its free version, but I got lost when I saw its interface and I didn't actually play with it much then and I ended up thinking that it's another crazy/fancy tool for PMs or whoever and I didn't really see how I might benefit from using it. Then...

    Compare paths from the end in C#

    Today at work, a colleague came to me with quite interesting problem. He needed to find out first common directory for two given paths starting from the end. For example, for given paths like: c:\documents and settings\some user\my files\projects\project1\initialFiles\somefiles\ and d:\ My Projects\project1\ChangedFiles\MyFiles\ It would return 'project1'. I was surprised to find out that neither System.IO.Path, nor System.IO.Directory allows you to that. Here's simple solution I created for him. public static string FindLastCommonParentFolder(string path1, string path2) { ...

    Updating Controls in Windows Forms

    How often do you find yourself writing code like this: Code Snippet string[] files = GetFiles(path); filesListView.BeginUpdate(); for (int i = 0; i < files.Length; i++) { //possibly something more ...

    Get to running application from ROT

    While cleaning old projects I found this one, that I wrote some time ago, and decided to post here, because it took me long time to figure it out, and although at the end it didn't work (to clarify things, not because there is something wrong with it, because if how that particular app registered its instances to ROT) I don't want to go through it again.   IBindCtx bindCtx; Dictionary<string, Namespace.Application> items = new Dictionary<string, Namespace.Application>();...

    My 3 cents about ALT.NET; do it Microsoft way vs do it the right way

    David Laribee coined the term ALT.NET. What it means, and why it's going to be the_hot_word? David basically explained it in 4 points: What does it mean to be to be ALT.NET? In short it signifies: You’re the type of developer who uses what works while keeping an eye out for a better way. You reach outside the mainstream to adopt the best of any community: Open Source, Agile, Java, Ruby, etc. You’re not content with the status quo. Things can always be better expressed, more elegant and simple, more mutable, higher quality, etc. You know tools are great, but...

    Krzysztof Cwalina's great lecture available to download

    You know who Krzysztof Cwalina is - right? The Framework Design guy. He recently gave a lecture on that topic at Microsoft Research center, and now he made it available for download. I haven't seen it whole yet (it's iver 3h long!) but i strongly recomend it. Get it here, and if you didn't already - subscribe to Krzysztof's blog: here.   Technorati tags: Krzysztof Cwalina, .NET, .NET framework, design, lecture, Microsoft

    Windows Live Writer and SubText incompatibility issues

    Microsoft released 2nd beta of Windows Live Writer yesterday. That's good, I used 1st beta to publish my posts and I tried to publish previous post with the new version but there seems to be some API incompatibility issue between WLW and SubText, since when I tried to publish it, it Subtext threw this exception: Server Error 0 Occurred Illegal Characters Found    at Subtext.Framework.Text.HtmlHelper.HasIllegalContent(String s)   at Subtext.Framework.Data.DatabaseObjectProvider.FormatEntry(Entry e, Boolean UseKeyWords)   at Subtext.Framework.Data.DatabaseObjectProvider.Create(Entry entry, Int32[] categoryIds)   at Subtext.Framework.Entries.Create(Entry entry)   at Subtext.Framework.XmlRpc.MetaWeblog.newPost(String blogid, String username, String password, Post post, Boolean publish) I guess I'll stick to beta 1 for now....

    How to embed custom control in ToolStrip

    ToolStrip is very useful container control, but it has it's default set of controls you can put onto it. What if you wanted to have, say DateTimePicker, or some totally custom control you have made? You can inherit it from ToolStripItem, override some methods and properties, but there is a much quicker way, if you don't need any custom behaviour. To illustrate this i created simple form with ToolStrip, and I embeded DateTimePicker into it, as you can se below (code follows) As you can see, all the magic that happens is thanks to ToolStripControlHost class. private void...