Tag | Generics Posts
Good things are hard to kill. One of the most useful predefined compiler macros in C/C++ were __FILE__ and __LINE__ which do expand to the compilation units file name and line number where this value is encountered by the compiler. After 4.5 versions of .NET we are on par with C/C++ again. It is of course not a simple compiler expandable macro it is an attribute but it does serve exactly the same purpose. Now we do get CallerLineNumberAttribute == __LINE__ CallerFilePathAttribute == __FILE__ CallerMemberNameAttribute ...
Myth 3: The source of all bad code is inept developers and stupid people When you review code is this what you assume? Shame on you. You are probably making assumptions in your code if you are assuming so much already. Bad code can be the result of any number of causes including but not limited to: using dated techniques (like boxing when generics are available) not following standards (“look how he does the spacing between arguments!” or “did he really just name that variable ‘bln_Hello_Cats’?”) ...
Few days ago I have received an invitation from Packt Publishing to review this book. I myself is a big fan of Generics and is very interested about it, so I've decided to give it a go. Thank you for letting me review this interesting book. .NET 4.0 Generics (Packt Publishing) is written by Sudipta Mukherjee. The book is primarily targeted to beginners and intermediate programmers who want to know what .NET Generics is all about and how it can help solved real world problems. The book covers the ...
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. In the last three weeks, we examined the Action family of delegates (and delegates in general), the Func family of delegates, and the EventHandler family of delegates and how they can be used to support generic, reusable algorithms and classes. This week I will ...
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. In the last two weeks, we examined the Action family of delegates (and delegates in general), and the Func family of delegates and how they can be used to support generic, reusable algorithms and classes. So this week, we are going to look at a handy pair of delegates ...
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. Back in one of my three original “Little Wonders” Trilogy of posts, I had listed generic delegates as one of the Little Wonders of .NET. Later, someone posted a comment saying said that they would love more detail on the generic delegates and their uses, since ...
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. Back in one of my three original “Little Wonders” Trilogy of posts, I had listed generic delegates as one of the Little Wonders of .NET. Later, someone posted a comment saying said that they would love more detail on the generic delegates and their uses, since ...
Technorati Tags: Scala,C# to Scala Introduction This post gives an overview of Scala from a C# developer’s perspective in light of efforts for a current .Net port coming closer to fruition. By closer I mean they have the compiler done but not the Visual Studio or SharpDevelop plug-in. From what I could find there is also no CLR based REPL available. You are also unable to call CLR code with generic signatures. While all of these issues are being worked on, to have a play I suggest using the JVM implementation ...
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can really help improve your code by making it easier to write and maintain. This week, we look at the System.Tuple class and the handy factory methods for creating a Tuple by inferring the types. What is a Tuple? The System.Tuple is a class that tends to inspire a reaction in one of two ways: love or hate. Simply put, a Tuple is a data structure that holds a specific number of items of a specific ...
Once again we consider some of the lesser known classes and keywords of C#. In the next few weeks, we will discuss the concurrent collections and how they have changed the face of concurrent programming. This week’s post will begin with a general introduction and discuss the ConcurrentStack<T> and ConcurrentQueue<T>. Then in the following post we’ll discuss the ConcurrentDictionary<T> and ConcurrentBag<T>. Finally, we shall close on the third post with a discussion of the ...
Back when I was primarily a C++ developer, I loved C++ templates. The power of writing very reusable generic classes brought the art of programming to a brand new level. Unfortunately, when .NET 1.0 came about, they didn’t have a template equivalent. With .NET 2.0 however, we finally got generics, which once again let us spread our wings and program more generically in the world of .NET However, C# generics behave in some ways very differently from their C++ template cousins. There is a handy clause, ...
ASP.NET applications can make use of the System.Web.Caching.Cache object to cache data and prevent repeated expensive calls to a database or other store. However, ideally an application should make use of caching at the point where data is retrieved from the database, which typically is inside a Business Objects or Model layer. One of the key features of using a UI pattern such as Model-View-Presenter (MVP) or Model-View-Controller (MVC) is that the Model and Presenter (or Controller) layers are ...
In this Issue: Michael Washington, Jeff Blankenburg, Richard Waddell, Eric Willeke, Gabor Dolhai, Ariel Ben Horesh(-2-, -3-), and Alex Golesh Above the Fold: Silverlight: "Silverlight AutoCompleteBox and MVVM" Eric Willeke WP7: "31 Days of Windows Phone | Day #24: Embedding Fonts" Jeff Blankenburg Blend: "Blend For Beginners: Grid to Canvas to StackPanel" Richard Waddell Shoutouts: Dave Campbell has another post up for finding alternate uses for on-board toys: A Set of WP7 flashlights for Free (and ...
I received (by chance, mostly) a Netduino last tuesday. Netduino is an open-source hardware project based on Arduino and the .Net Micro Framework. And it’s extremely cool. I’m a C# developer and I was always interested in electronics. This is an excellent tool to start to understand that incredible world. I was about to buy an Arduino when the Netduino fell on my lap, so I was really happy about it. Netduino has various disadvantages over Arduino (for starters, it’s more expensive, not all the shields ...
Merge Wpf and Silverlight to single framework · Merge both frameworks to use the same assemblies and controls (with optional functionality in separate assemblies) make a .net silverlight profile that would be a subset of .net client profile and used by partially trusted xaps. · Conditional compilation within Xaml - stopgap solution: for Silverlight/WPF differences in shared markup. · Support the direct hosting of Silverlight – stopgap solution: support the direct hosting of Silverlight in a WPF application ...
in and between operators if (x in (1, 2, 3)) if (x in 1:5) if (x between(1,5)) · Like Python - Without having to use extension methods Data Structure Improvements · Make BCL collections to be generic: all this ControlCollection, XmlAttributeCollection, SqlErrorCollection, StringCollection becomes Collection<Control>, Collection<XmlAttribute> and Collection<SqlError> · Tuple Packing and Unpacking - Like python: public Tuple<string, int, double> ReturnMyTuple() { return "Hello ...
This week is my final entry in my Little Wonders series (posts one and two are here and here). These are those little tips and tricks in .NET (and in particular C#) that may not seem like much, but can help make your code either more concise, maintainable, or performant. Thanks again for all your comments and suggestions on this series, it has been a lot of fun to write, and though I feel I could go on forever with lots more tips and tricks, this will be the last Little Wonders post for a while. ...
After taking a lot of time with C# fundamentals, I decided to go down a different road this week and talk about some of the differences in C# that can be troublesome to people who are used to C++ development but are learning C#. My first post on this blog months ago was just a simple piece on how I divorced C++ as my first-love language (here). This is not to say that C++ is not still a valuable language, in fact as far as object-oriented languages go C++ is still king of performance. That said, ...
Generics are nothing new and have been part of .NET for over 5 years. Reference types and value types are core concepts in the CLR type system and these concepts have been the same since .NET was released – they are also nothing new. However, when I ask about these concepts during interviews, I often get a wide range in quality of the answers to these questions. If you get asked about these topics in an interview, be prepared to give great answers! You don’t have to give a textbook perfect memorized ...
Technorati Tags: .NET,INotifyPropertyChanged... Parts 1 & 2 of this unintended trilogy: INotifyPropertyChanged with less typing using a Code Snippet INotifyPropertyChanged with less code using generics & reflection My previous post elicited a couple of good comments. Matt noted that my use of reflection to get the property name could be a problem in due to inlining in Release mode: http://stackoverflow.com/qu... http://www.hanselman.com/bl... ...
Technorati Tags: .NET,INotifyPropertyChanged... Kevin Grossnicklaus gave a nice presentation on M-V-VM User Interface Patterns in Silverlight and WPF at last night's St. Louis .NET User Group meeting. A key part of MVVM is implementation of the INotifyPropertyChanged interface to let views know that bound properties have changed. Here's a simplified version of a model class from the MSDN INotifyPropertyChanged documentation: public class DemoCustomer : INotifyPropertyChanged { private Guid _id ...
This is a case of things being more complicated that I thought they should be. Since it took a while to figure this one out, I thought it was worth explaining and putting all of the pieces to the answer in one spot. Let me set the stage. Architecturally, I have the notion of generic producers and consumers. These put items onto, and remove items from, a queue. This provides a generic, thread-safe mechanism to load balance the creation and processing of work items in our application. Part of the IProducer(Of ...
Part 1 After I explained my motivation for using YAML instead of XML for my data, I got a lot of people asking me what type of tooling is available in the .Net space for consuming YAML. In this post, I will discuss a nice tooling option as well as describe some small modifications to leverage the extremely powerful dynamic capabilities of C# 4.0. I will be referring to the following YAML file throughout this post Recipe: Title: Macaroni and Cheese Description: My favorite comfort food. Author: Brian ...
My last post was about a class for building test data objects in C#. This post describes the same tool, but implemented in Ruby. The C# version was written first but I originally came up with the solution in my head using Ruby, and then I translated it to C#. The Ruby version was easier to write and is easier to use thanks to Ruby’s dynamic nature making generics unnecessary. Here are my example domain classes: class Person attr_accessor :name, :age def initialize(name, age) @name = name @age = age ...
Normal 0 false false false EN-US X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans... ...
Often enough we have frameworks do heavy lifting for us. That's usually a good thing. But I always found it kind of sedating to let "the man" provide me with too much comfort. Especially when the framework or other SOUP library fails to perform exactly what you want. That usually leads to some grumpiness followed by some code-acrobatics to punch that square peg into a round hole – often negating the elegance and usefulness of the library call altogether. One task a framework often performs is binding. ...
My first thought – who needs another language? Are new languages the new rage? If I were to design a new language (I am not qualified, trust me), what would it address . . . It would be garbage collected (no brainer) It would run in a VM (actually, many different VMs ) It would also be statically typed (I think many would disagree these days) Threading would be a focus (with message passing as a language feature). Certainly include some aspects of functional programming languages It would have first ...
On Monday I presented at the St. Louis .NET User Group, and the topic was ‘What’s new in VS2010 and .NET 4.0 Framework’. Within the whirlwind look at all the new and cool stuff coming in the near future, the subject of Covariance and Contravariance support was discussed. Given the time constraint I only spent 3-4 minutes at it. I alluded to the group that the concept of Covariance/Contravariance is rather hard to understand, because it is not as intuitive as it could be; I just asked them to trust ...
in·ane (in-an') adj. in·an·er, in·an·est One that lacks sense or substance. The American Heritage® Dictionary of the English Language, Fourth Edition Copyright © 2009 by Houghton Mifflin Company. Published by Houghton Mifflin Company. All rights reserved. One of the first signs that code needs to be refactored is that it looks complex. Complex solutions are rather easy to come by, but are far less maintainable than their harder to write, easier to read brethren. Like any well-crafted sculpture, it ...
If you have ever wondered why your .net application has a slow startup performance you normally start watching with Process Explorer at your processes. But this will not always give you the full picture since it can loose some csc.exe calls because if you have a fast machine it will not get them. A more reliable tool is Procmon where you can look for process starts: Where do these compiler invocations come from? It turns out that XmlSerializer is to blame which generates a C# file in your TEMP folder, ...
I'd like to compare the java language to .net as I'm experiencing it. First of all, I'd like to point out that the differences are less than the similarities. Purely seen from a syntax point there really are no differences. Except of course if you're used to .net 3.5. This is irritating at first, but after a while you're just resigned to it. Take the simple properties we're so used to in .net Compare these two identical pieces of code: java: private int counter; public int getCounter(){ return counter; ...
Main difference is that casting to wrong type throw an exception and an “as” keyword just return null. So if I would like to search specified type in VisualTree I can use “as” keyword and check is object not null or I can use “is” keyword. But when I would like to take not reference object like generics KeyValuePair from object type I will have to use casting to unpack the value type. This is because value types do not inherit from object so they are not objects and cannot use keyword as.
Continuing in my series of “Adventures in MVVM”, I want to talk about a few different approaches to working with List Boxes with the MVVM pattern. What I am writing here is generally true of all controls that derive from Selector, including ListBox and ComboBox. This example was developed in Silverlight, but the same concepts also apply to WPF. The Problem You have a list box in your view, and you want your ViewModel to do something when an item in the ListBox is selected. You want to do this without ...
/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans... mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-... ...
I have been busily working away at building infrastructure for the Dare to Dream Difference Challenge. Since my last post, I have finished the hardware prototype, although I still need a cabinet. The project now consists of a Device Solutions Tahoe II development board, an XBee Series 2 module, an AR1010 FM Receiver, an LM4832N audio amplifier, and two 0.5 watt speakers (pictured here). Not pictured is the ZigBee base station. I have made a shift in the approach I was taking for the software. Originally, ...
This is part 1 of a two posts series about the property IsSynchronizedWithCurrentItem. In this post, we will see what it does in Windows Presentation Foundation. In the next post, we will see that this property is missing in Silverlight, and propose a way to simulate it. One of the features I really like in Windows Presentation Foundation is the ability to set a flag on various list controls (such as ListBox, ComboBox, etc...) deriving from the Selector class. This flag is named IsSynchronizedWithCurrentItem. ...
I've discovered what was causing problems with TestDriven.Net and it isn't ReSharper. I had recently refactored my test fixtures and now I have a few that make use of generics BaseTest<T>. I had run into a problem with TD.Net before regarding generics and had to rearrange my classes (I had two classes in one file) to get it to work. I don't remember the details and I am still having problems getting it to work now. Regardless, R# is off the hook. And as an added bonus, R# doesn't appear to ...
The .NET framework ships with an abstract KeyedCollection<TKey, TItem> class. Basically, all you have to do is implement the GetKeyForItem() method you can could look up any item either by ordinal or a customized key. For example, suppose you had a Person class like this: 1: public class Person 2: { 3: public Guid ID { get; set; } 4: public string FirstName { get; set; } 5: public string LastName { get; set; } 6: } And suppose you wanted to be able to lookup a Person in the collection either ...
Sometimes new features are added to a language which fundamentally change how we do things (e.g., when generics was added to .NET 2.0). However, there are other times when features are added to the language that are “syntax sugar” or “nice to have’s”. My outlook on those items has always been that “syntax sugar” is typically a good thing – if there is some feature that allows the code to be more expressive/readable then that is a great thing. Sure, the IL might not be any different behind the scenes ...
The next versions of C# and VB will have improved parity between them. From the consultant perspective, this is important because one can't always choose which language to use. Although a seasoned C# developer can program in VB as well, it seems that gotchas appear and you have to refer to the documentation to figure out how do something that you wouldn't even need to think about in your primary language. The goal of the Visual Studio Managed Languages team is to maintain the character of each language ...
1. Introduction This is a follow-up to the "An attribute based approach to business object validation" article in which i introduced the use attributes and reflection to validate business objects. I also promised to write another article on data converters and method based validators, and here it is. 2. Background In this article i will use an example to show how you can validate your business object using a method based attribute and how you can convert data assigned to properties when it is saved ...
If you are like me, you may be surprised to find that your colleagues don't know some fundamental things about Generics in .NET. I just began working on a new project at work and during the design phase I was assured that our company had a great API full of extensions for a commercial content management solution. This API, I was told, would revolutionize how I used the product and take a lot of burden off my team of developers (some of which had used the API on previous projects and thought it was ...
Generics in C# have been around for a while (the concept of generics has been around even longer) but there are still a lot of developers who don’t have a good understanding of what they are or how to use them. Looking at the direction C# 4.0 is taking, generics are becoming more and more important and if you don’t make them a natural part of your programming tool belt you are going to find yourself falling behind the curve. Karl Seguin at CodeBetter.com has an excellent post that explains generics ...
I had a case today where I needed -- well, wanted -- to implement a generic class that was a little... unusual. Essentially, I'm working on a queuing mechanism based on Joe Duffy's BlockingBoundedQueue(Of T). Mind you, unlike Joe's sample, mine is written in VB.NET. ;) Taking it a bit further, I created a wrapper that specifies the number of producers and consumers of queued objects, as well as the queue capacity. Since I'm going to be turning this over to a bunch of developers to play with, I also ...
Well the "brain-brush" series continues. One of my favourite binary tree question would be given a preorder and inorder traversal strings write a function to build the tree. Most of the rubbish text books provide non-programmatic solution to this and rest append it as a to-do. Today I will proceed step-by-step to solve this and that too with same ingredients - delegate, generics and C#2.0. Disclaimer still holds: "This is just a fundamental recapitulation of binary tree and data structure as a whole. ...
Microsoft has released Enterprise Library 4.1. It is a service release and includes the following: Unity interception mechanism and integration of the Policy Injection Application Block with the Unity Application Block Added support for generics in the Unity Application Block Added support for arrays in the Unity Application Block Performance improvements Usability improvements to the configuration tool Visual Studio 2008 Service Pack 1 support Bug fixes ...
3 XAML vocabularies: UI, Workflow, XPS. Used in mutliple runtimes: .NET 3,0, 3.5, Silverlight 1 and 2. Many tools too (Visual Studio, Expression Blend). XAML Specds were published earlier this week, 600 page volume schema for all variations of the language. Lots of file converters exist, from SVG, Flash, Illustrator, WMF, etc etc etc. The list is impressive! Next version will be extended to support more XAML-only code. For example, support for generics. Investments will be done to catch XAML errors ...
Presentation by Anders Hejlsberg. It is 10 years later since they started C# C# 1.0 was about introducing the general concept of managed code. C# 2.0 was about finishing C# 1.0 but didn't have time to do. C# 3.0 is really about radical new thinking in the language - LINQ. They learned a lot about functional programming through this exercise. Today is about C# 4.0. Some of the trends that have shaped their thinking on C# 4.0. Declarative Dynamic - resurgence of dynamic programming languages Concurrent ...
Microsoft Enterprise Library 4.1 has been released with some improvements and fixes. What's new Unity interception mechanism and integration of the Policy Injection Application Block with the Unity Application Block Added support for generics in the Unity Application Block Added support for arrays in the Unity Application Block Performance improvements Usability improvements to the configuration tool Visual Studio 2008 Service Pack 1 support Bug fixes Enterprise Library homepage Quick Starts ...
An interesting question arose today of how to read property values from the HttpContext class dynamically. It is easy to imagine why this would be useful. For example, you might want to store a number of property names in a configuration file, and retrieve these values on-the-fly, perhaps for logging purposes. The first thing to notice about the HttpContext class is that it manages its own instances. What I mean by this is the class contains a public static property named 'Current' which returns ...