CSharpFeeds - All your C# feeds in one place.

Sponsors

Feed: Paulo Morgado : C#

Site: http://msmvps.com/blogs/paulomorgado/archive/tags/C_2300_/default.aspx Link: http://msmvps.com/blogs/paulomorgado/rss.aspx?Tags=C_2300_&AndTags=1

Wednesday, January 27, 2010

Playing With LINQ: Getting Interface Property Implementations

by Paulo Morgado via Paulo Morgado : C# on 1/27/2010 2:22:00 AM

Today, my friend Nuno was writing some code to get the PropertyInfos of a class implementation of an interface. Given this interface:public interface ISomeInterface { int IntProperty { get; set; } string StringProperty { get; } void Method(); } and this class:public class SomeClass : ISomeInterface { int ISomeInterface.IntProperty { get; set; } public int IntProperty { get; private set; } public string StringProperty { get; private set; } public void Method() { } } Nu ...

[ read more ]

Tuesday, January 19, 2010

How To Set Elements Of An Array Of A Private Type Using Visual Studio Shadows

by Paulo Morgado via Paulo Morgado : C# on 1/19/2010 12:26:00 AM

Visual Studio uses Publicize to create accessors public for private members and types of a type. But when you try to set elements of a private array of elements of a private type, things get complicated. Imagine this hypothetic class to test:public static class MyClass { private static readonly MyInnerClass[] myArray = new MyInnerClass[10]; public static bool IsEmpty() { foreach (var item in myArray) { if ((item != null) && (!string.IsNullOrEmpty( ...

[ read more ]

Tuesday, October 13, 2009

LINQ To SQL Tips & Tricks: String Operations

by Paulo Morgado via Paulo Morgado : C# on 10/13/2009 12:51:43 AM

LINQ brought developers a very user friendly and domain independent style of writing queries. The fact that the way queries are written is domain independent doesn’t mean that any query will compile the same way or even run the same way. You’ll always need to know how the provider will behave. LINQ To Objects, for example, will compile queries as a Func<> delegate and the query methods will return IEnumerable(T) implementations. On the other hand, LINQ To SQL will compile queries as ...

[ read more ]

Friday, September 18, 2009

PowerShell For The .NET Developer

by Paulo Morgado via Paulo Morgado : C# on 9/18/2009 12:03:12 AM

Some time ago I needed to have the validationKey of the machineKey element of an ASP.NET application changed and found out that ASP.NET doesn’t provide a command-line tool (or any other) to do this. Looking around I found several applications and code samples to do it, but to have a system administrator do this I needed to test and document the application and it was to much work for such task. I’ve always been a supporter of the idea of PowerShell but I never used it my self. Just because I a ...

[ read more ]

Sunday, May 17, 2009

LINQ With C# Book Is Finally Out

by Paulo Morgado via Paulo Morgado : C# on 5/17/2009 11:39:51 PM

It’s finally out! The LINQ Com C# (LINQ With C#) book that Luís and I wrote is out. Well, mostly Luís than I. This book, published by FCA, is targeted at anyone that already knows C# 2.0 and wants to know learn the new features introduced with C# 3.0 that made possible LINQ (Language INtegrated Query). The examples in the book are written in C#, but Visual Basic get be get from the book’s site. Title: LINQ Com C# Authors: L ...

[ read more ]

Wednesday, December 03, 2008

The Future Of C#

by Paulo Morgado via Paulo Morgado : C# on 12/3/2008 1:17:00 AM

If you were able to attend this session at PDC or Tech-Ed EMEA Developers, you were presented with a first class presentation of the future of C#, presented, respectively, by Anders Hejlsberg and Mads Torgersen. For the near future (.NET 4.0) C# will have: Dynamically Typed Objects Optional and Named Parameters Improved COM Interoperability Co- and Contra-variance A preview of the compiler as a service was shown, but that’s not for the .NET 4.0 / Visual Studio 2010 timeframe. Probably, not ...

[ read more ]

Thursday, August 28, 2008

Clone Detective For Visual Studio

by Paulo Morgado via Paulo Morgado : C# on 8/28/2008 10:41:36 PM

Clone Detective is a tool that integrates with Visual Studio and uses the ConQAT (Continuous Quality Assessment Toolkit) to analyze C# projects and search for duplicated source code. Watch the videos and see if this is the tool you were looking for. ...

[ read more ]

Monday, August 11, 2008

More On Another Way For Using The “using” Keyword

by Paulo Morgado via Paulo Morgado : C# on 8/11/2008 12:47:50 AM

In the past I presented another possible use for the using keyword: as hints on LINQ. I’ve been giving some thought about this lately and refined my proposal. var q = from person in personCollection using MyEnumerableExtensions group person by person.LastName into g using new MyOtherComparer() orderby g.Key using new MyComparer() select person; The above query would be converted to: var q = MyEnumerableExtensions.OrderBy<string, Person>( MyEnumerableEx ...

[ read more ]

Sunday, August 10, 2008

How About Property Assignment And Collection Adding Like Object And Collection Initializers In C#?

by Paulo Morgado via Paulo Morgado : C# on 8/10/2008 11:27:22 PM

C# 3.0 introduced object and collection initializers. It is now easier to initialize objects or collections: var person = new Person { FirstName = "Paulo", LastName = "Morgado" }; var persons = new List<Person> { new Person { FirstName = "Paulo", LastName = "Morgado" }, new Person { FirstName = "Luís", LastName = "Abreu" } }; var personDirectory = new Dictionary<string, Person> { { "Lisboa", new P ...

[ read more ]

Monday, August 04, 2008

C# And Visual Basic Generate Different Expression Trees

by Paulo Morgado via Paulo Morgado : C# on 8/4/2008 12:23:00 AM

(This was pointed out to me by Frans Bouma and explained by Jon Skeet) Imagine you have this set of classes:public class A { public virtual string P { get { return "A"; } } } public class B : A { } public class C : B { public override string P { get { return "C"; } } } And this class:public static class Reporter { public static void Report<T>(T target, Expression<Func<T, string>> expression) { Consol ...

[ read more ]

Tuesday, April 22, 2008

Stretching Type Inference

by Paulo Morgado via Paulo Morgado : C# on 4/22/2008 12:35:00 AM

Note: Code in italics is not actual C# 3.0 syntax. Local Variable Type Inference C# 3.0 brought us local variable type inference mainly because of LINQ. The output of a query can vary from an IEnumerable<T> or an IQueryable<T> to a single instance of T where T can even be a projection which means that its type is an anonymous type. Take the following query as an example:from p in persons select new { Name = p.FirstName + " " + p.LastName, Age = p.Age }; If persons is an IEn ...

[ read more ]

Sunday, October 07, 2007

VS REGEX: Commenting Generated Assert Instructions

by Paulo Morgado via Paulo Morgado : C# on 10/7/2007 10:56:00 PM

Visual Studio's Unit Test generator generates a call to Assert.Inconclusive but, usually generates a call to another method of the Assert class. I find that very annoying because, some times, this makes the test fail instead of being reported as inconclusive. To comment out these extra calls to Assert methods, the following regular expression can be used: Find what: {:b*}{Assert\.~(Inconclusive).*\n:b*Assert\.Inconclusive} Replace with: \1//\2 Check out the complete list. ...

[ read more ]

Sunday, July 08, 2007

TypeTypeConverter - The Type TypeConverter

by Paulo Morgado via Paulo Morgado : C# on 7/8/2007 11:31:35 PM

I've been searching high and low for a TypeConverter for Types and only found private or internal implementations. It wasn't a hard task, but I think that the .NET Framework should provide one out of the box. Here is the one I wrote: /// <summary> /// Provides a type converter to convert <see cref="T:System.Type"/> objects to and from various other representations. /// </summary> public class TypeTypeConverter : System.ComponentModel.TypeConverter { /// &l ...

[ read more ]

Monday, June 18, 2007

C# Class Member Prefixing Religion

by Paulo Morgado via Paulo Morgado : C# on 6/18/2007 11:59:04 PM

A discussion has started in Eric Gunnerson's blog around the subject of To m_ or no to m_, that is the question.... A lot has been said on this (here is my opinion), but Peter Ritchie has a well written post on this. ...

[ read more ]

Wednesday, May 23, 2007

My C# Naming Conventions For Partial Class Files

by Paulo Morgado via Paulo Morgado : C# on 5/23/2007 11:29:32 PM

Following up on a previous post, this time I'll give you my naming conventions for partial class files. There are two main reasons for me to break a class definition into more than one file. The main one is when I have inner classes and the other is when the file is getting too big. How should I name the files? The usual tendency is to use a “.” as separator. This looks nice until you came across something like this: public class MyComponent {     private class Activation &n ...

[ read more ]

Enterprise Library 3.1 Released

by Paulo Morgado via Paulo Morgado : C# on 5/23/2007 10:27:20 PM

You can download here. Before you get too excited, according to Tom Hollander, this is really just a maintenance release addressing a small number of issues discovered since the release of 3.0. Here is a summary of the main changes: Policy Injection Application Block The default Remoting Policy Injector can now be replaced with alternative interception mechanisms via configuration without modifying the application block code Call Handler attributes are now honored correctly when ...

[ read more ]

Sunday, May 20, 2007

Naming Conventions for C#

by Paulo Morgado via Paulo Morgado : C# on 5/20/2007 10:28:43 PM

I'm a firm supporter of coding conventions (at least of my coding conventions). Software factories [^] [^] [^] and other code generation tools have been taking care of writing the tedious (and, sometimes, ugly) code but, at some point, some code must be written and read by human developers. That's why (in my opinion) the way the code is written is as much important as the language it is written in. There are several resources about coding conventions for the .NET framework: Naming ...

[ read more ]

Monday, May 14, 2007

UPDATE: Extension methods

by Paulo Morgado via Paulo Morgado : C# on 5/14/2007 10:28:19 PM

Looks like I was way wrong in here and here. I had thought that from the top of my head because I tried to use Array.IndexOf as an extension method and was surprised to see that it wasn't an extension method. It presented a good opportunity to play around with extension methods, so I wrote a class to extend the Array class: public static class ArrayUtils {     public static int IndexOf<T>(this T[] array, T value)     {       &nbs ...

[ read more ]

Sunday, May 13, 2007

How about a keyword for qualifying static members?

by Paulo Morgado via Paulo Morgado : C# on 5/13/2007 10:30:25 PM

I like to always qualify all instance fields with the this keyword. this.someInstanceField; this.GetType(); I would like to do the same for static fields, but there's no keyword for that. I've been thinking about this for a while and I think I found a solution: the static keyword. typeof(); // no need for the static keyword static.someStaticField; ...

[ read more ]

Extension methods missing from System.Array in the .NET Framework 3.5 (Beta 1)

by Paulo Morgado via Paulo Morgado : C# on 5/13/2007 6:51:48 PM

UPDATE: Extension methods Extension methods are a feature of the new C# language specification (also available in Visual Basic [^] [^]): This new feature should be used in existing classes like the Array class by making the folowing methods extension methods: public static System.Collections.ObjectModel.ReadOnlyCollection<T> AsReadOnly<T>(this T[] array); public static int BinarySearch<T>(this T[] array, T value); public static int BinarySearch(this Array array, object value ...

[ read more ]

Extension methods missing from System.String in the .NET Framework 3.5 (Beta 1)

by Paulo Morgado via Paulo Morgado : C# on 5/13/2007 6:41:09 PM

UPDATE: Extension methods Extension methods are a feature of the new C# language specification (also available in Visual Basic [^] [^]): This new feature should be used in existing classes like the String class by making the folowing methods extension methods: public static int Compare(this string strA, string strB); public static int Compare(this string strA, string strB, bool ignoreCase); public static int Compare(this string strA, string strB, System.StringComparison comparisonType); public ...

[ read more ]

Thursday, April 26, 2007

WCF: Building an HTTP User Agent Message Inspector

by Paulo Morgado via Paulo Morgado : C# on 4/26/2007 11:50:50 PM

Yesterday I had to build a custom message encoder to be able to call a legacy POX service with iso-8859-1 encoding. It turned out that the service had another surprise to me: it needs an HTTP user-agent header. It's something quite simple to accomplish with WCF. All it's needed is to add the required header to the HTTP request message property of the request message. Something like this: HttpRequestMessageProperty httpRequestMessage = new HttpRequestMessageProperty(); httpRequ ...

[ read more ]

Sunday, April 15, 2007

Architecture Tools

by Paulo Morgado via Paulo Morgado : C# on 4/15/2007 11:14:30 PM

In his show about Scenario Based Architecture Validation, Ron Jacobs talks with Dragos Manolescu (Architecture Evaluation in Practice) about how difficult it is to evaluate and validate an architecture. There are a few tools that can help you validate the architecture of your application or framework, though. Here are two of them. Lattix LDM 3.0 This tool from Lattix uses Dependency Structure Matrix (DSM) to communicate the architecture, identify critical dependencies, and define rules ...

[ read more ]

Sunday, April 01, 2007

Adding Presenters to MasterPages in the Web Client Software Factory

by Paulo Morgado via Paulo Morgado : C# on 4/1/2007 10:59:13 PM

Master pages, in the Web Client Software Factory, act as equivalents to the Shell in the Smart Client Software Factory but, unlike their smart client counterpart, they don't benefit from dependency injection. I've just cooked up a quick way to add dependency injection to master pages in the Web Client Software Factory and, thus, add a Presenter (with the associated Controller). This can be done just by adding a few lines of code to the Microsoft.Practices.CompositeWeb.WebClie ...

[ read more ]

Sunday, March 25, 2007

Yet Another Way for Using the "using" Keyword

by Paulo Morgado via Paulo Morgado : C# on 3/25/2007 8:58:31 PM

There are two uses for the C# using keyword: The using statement: Defines a scope, outside of which an object or objects will be disposed. using (TransactionScope transactionScope = new TransactionScope()) {     // ... } The using directive: The using directive has two uses: To permit the use of types in a namespace so you do not have to qualify the use of a type in that namespace: using System.Text; To create an alias for a namespace or a type: using Text = System.Text; ...

[ read more ]

Saturday, February 17, 2007

Unit Testing and Mock Frameworks

by Paulo Morgado via Paulo Morgado : C# on 2/17/2007 11:51:15 PM

I'm not a big fan of Test Driven Development (TDD), but I love Unit Testing. But to be productive on unit testing I need a good framework for Mock Objects. I can't expect to be productive and have to build a lot of mock classes to test other classes. And, who tests the mock classes? Mock objects simulate the behavior of real objects when they are difficult or impossible to obtain. I've been testing a few mock frameworks and this is my opinion (*) on the ones I've tested. NMock I've bee ...

[ read more ]

Monday, February 05, 2007

What's wrong with ASP.NET provider model? - The RoleProvider

by Paulo Morgado via Paulo Morgado : C# on 2/5/2007 11:04:28 PM

Again, the lack of IIdentity in the API. With identities like the WindowsIdentity, the user's username (the name property) has no use for the system. The important part is the user's token. If you would follow the path (using Reflector) from the call to Roles.GetRolesForUser() until the reply from WindowsTokeRoleProvider.GetRolesForUser(string username), you would see the following steps: System.Web.Security.Roles.GetRolesForUser() gets the current user's username from the curren ...

[ read more ]

Saturday, November 04, 2006

An Hierarchical CAB WorkItem Activation Service

by Paulo Morgado via Paulo Morgado : C# on 11/4/2006 11:15:34 PM

The application I'm currently working on has a rather complex UI. It's something like two tabbed work spaces and an outlook-like work space, that make one workspace by itself, that can have several instances inside another tabbed workspace, that can have several instances inside another tabbed workspace. Imagine something like Visual Studio, inside a tab. Each work space is controlled by its own work item and the same goes to every smart part. With a UI like this, the work item activation s ...

[ read more ]

Sunday, October 29, 2006

Work Spaces and Smart Part Info Provider

by Paulo Morgado via Paulo Morgado : C# on 10/29/2006 10:57:33 PM

As I understand it, the MVP (Model/View/Presenter) design pattern states that all presentation decisions are the Presenter's responsibility. In the CAB world, this should include the Smart Part Info. But the IWorkspace interface only allows you to provide the Smart Part Info (a class that implements the ISmartPartInfo interface and each work space uses a specific one), or the the smart part (the View in the MVP design pattern) should know what information to provide to the work space it lives in ...

[ read more ]

Sunday, October 22, 2006

Enhancing CAB's ManagedObjectCollection

by Paulo Morgado via Paulo Morgado : C# on 10/22/2006 9:45:52 PM

For those who don't know, the ManagedObjectCollection registers its elements using the objects running type as part of the key. Recently, I had the need to add and retrieve a component to the WorkItem's Items collection independently of its running. I only wanted to retrieve the component (using a ComponentDependency) with a specified name. Needless to say that I couldn't, because I was trying to retrieve an object, and that was not the running type of the object ad ...

[ read more ]

Tuesday, October 17, 2006

WebBrowserControl for the .NET Framework 2.0

by Paulo Morgado via Paulo Morgado : C# on 10/17/2006 10:06:43 PM

Yesterday a CodePlex project was created for the WebBrowserControl for the .NET Framework 2.0. I have been meaning to start this project for a long time. Let's see how it goes. Share this post: email it! | bookmark it! | digg it! | live it! ...

[ read more ]

Tuesday, October 10, 2006

Using Remoting with CAB

by Paulo Morgado via Paulo Morgado : C# on 10/10/2006 11:37:52 PM

Anyone who has ttried to add a service implemented through Remoting to the WorkItem's services collection was sadly surprised that it can't be done. But why? When we use the following code: WorkItem.Services.Add<IServiceContract>(serviceInstance); It comes to something like this:if (!typeof(IServiceContract).IsAssignableFrom(serviceInstance.GetType()) throw new ArgumentException(); And how do we solve this problem? easy: generics. All we need to do is make some changes to the Se ...

[ read more ]

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us