Tag | Generics Posts

I was sad to find out the "codingwithoutcomments" site was taken down. For the sake of a specific post from there, I went to waybackmachine.com and got that post, and I'm pasting it here.I have no rights on this article, I just think it's important to keep this online for people to read. -so if by doing so might be brake any law or offend any person, please let me know and I'll remove it as soon as I get it.Perpetually In Beta.Singleton I love you, but you're bringing me downwith 36 commentsIt was ...
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 ...
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 ...
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 ...
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. ...
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. Read the rest of this entry » ...
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).

Read the rest of this entry »

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 ...
For those Linux devs who don’t have something adamantly against Microsoft, Mono 2.0 has been released! From the release notes: Mono 2.0 is a portable and open source implementation of the .NET framework for Unix, Windows, MacOS and other operating systems. Release Date: October 6th, 2008 Major Highlights Mono 2.0 is a major milestone in the Mono project, and it supports the following features: Microsoft Compatible APIs ADO.NET 2.0 API for accessing databases. ASP.NET 2.0 API for developing Web-based ...
It is generally considered a good thing to use unit tests these days. Often it is necessary to test a method which takes some complex type. So in the unit testing one has to painstakingly manufacture such object, and pass it in. Before doing so, you would (should!) ensure the complex type itself produces an identity - that is to say that if you create an instance of type MyClass and assign / construct it with proper values your should "get back" what you gave it. This is especially true for object ...
F# is an awesome language. I'd choose to write F# code any day over any language if my work allows it. The way you are able to concisely and cleanly write code with it is what brought me over. Sure there is an initial overhead (if you we are an OO programmer) in learning all the functional constructs but in the end its all worth it. Even though you might not be able to use it at work (read : management only wants C#/VB.NET), the way you are writing OO code will definitely be improved. I for example ...
I came across an interesting blog post today entitled, "C# generics make me sad..." by Matt Sheppard. Matt has an issue with generic Lists, in that you can't easily convert from one to another even if one constraint is inherited from the other constraint. List<String> sl = new List<String>(); List<Object> ol = new List<Object>(); ol = sl; This will throw the error "Cannot implicitly convert type ‘System.Collections.Generic... to ‘System.Collections.Generic... ...
The Schedule for Code Camp 10 is now available via Chris Bowen's blog. I'll be presenting 4 topics over the weekend, I've listed them out below for your convenience. Make sure you double check the schedule when you check in to make sure there aren't any last minute changes! Date + Time Room Topic Sat 12:35pm Rhode Island Creating Terrain in XNA Sun 12:30pm Rhode Island Applied Generics : Radix Sort Sun 1:55pm MPR C SharePoint Branding Sun 3:20pm MPR A Integrating Silverlight into SharePoint See you ...
Generics are a great way of getting code reuse. However there are a few things that can make them difficult to work with. Generics are similar to C++ Templates in the way you define them, but are very different in the way they work. This series of articles is planned to explore Generics in detail by example. Most of the online references to Generics that I have found are always dealing with collections. We all know that collections are a great way to use generics. However, it's a bit tougher to spot ...
I was reviewing some code the other day that was violating one of our metrics and I saw something like this: internal class UtilityClass{ public static string SomeUtilityMethod(IList<... someStuff) The thing that struck me is this was an internal class and this was the only public method. So the only purpose this class serves is to perform one operation on this closed generic IList. To me it is more natural and far oop-ier to have that code be part of the collection itself. That may ...
I recently added a new page to my application that is very similar in behavior to a page I had already completed a couple months back. In fact, the similarities propagate down through the business and data layers as well. Because of this, I was able to introduce some base classes to limit duplication. In fact, I started all of this with a generic base test class. All of the base classes (with generics) were pretty straight forward. However, generics wouldn't help me when it came to the UI (aspx). ...
Before I get started on Generic Classes in .Net, I'd like to give credit to CopySourceAsHtml for my new formatting of code blocks in my blog. I made some of my own enhancements, but I'd still be using the boring black on yellow formatting without CSAH. To learn how to get it to work on VS2008, go here (be sure to read the comments if you are running on XP). We've all used generic classes without thinking much about it. I use List<T> extensively (perhaps abusively). I really only discovered ...