Codeine .Net RSS 2.0
# Sunday, 25 November 2007

The other day I ran into the need to access a nested property on an object with the actual name and path to the property stored in a string variable. For example I had a mail object and wanted to access "From.DisplayName" which was stored in a string. If I was access just the from I could have used something like this:

using System.Reflection;

PropertyInfo[] pi = myObject.GetType().GetProperties();

foreach (PropertyInfo item in pi)

{

if (item.Name = "From")

{

object o = item.GetValue(myObject, null);

}

}

 

In this example myObject is the mail object and we first get the type of it, and then get an array of the properties for that type. Finally we find the From property and get the value for that property on our object.

Unfortunately this doesn't work for nested properties and I could not find a built in way to do it so I built a recursive function to handle getting the property for me and returning it. I then packaged it into a handy .Net 3.5 extension method. Let me know if you know of a built in method to get a nested property, otherwise feel free to using the extension method I put together, though it probably needs a bit of refactoring before you put it into production.

namespace Common.ExtensionMethods

{

public static class TypeExtensionMethods

{

public static object GetNestedProperty(this Type t, Object o, String Property)

{

object myObject = null;

PropertyInfo[] pi = t.GetProperties();

 

 

 

if (Property.IndexOf(".") != -1)

{

 

foreach (PropertyInfo item in pi)

{

 

if (item.Name == Property.Substring(0, Property.IndexOf(".")))

{

object tmpObj = item.GetValue(o, null);

 

myObject = tmpObj.GetType().GetNestedProperty(tmpObj, Property.Substring(Property.IndexOf(".") + 1));

 

}

 

}

 

}

else

{

foreach (PropertyInfo item in pi)

{

if (item.Name == Property)

{

myObject = item.GetValue(o, null);

}

 

}

}

 

return myObject;

 

}

}

}

Sunday, 25 November 2007 10:03:26 (Central Standard Time, UTC-06:00)  #    Comments [1] - Trackback - Save to del.icio.us - Digg This! - Follow me on Twitter
Development | Extension Methods
# Sunday, 11 November 2007

Awhile back I got a little too aggressive with the mouse and accidently dragged my show desktop shortcut from the Quick Launch Bar onto the desktop. I tried to correct it by dragging it back onto the Quick Launch Bar, but of course this didn't work. What it did was create a shortcut on the Quick Launch Bar to the shortcut that was now on my desktop that then actually handled showing the desktop. Here's how to get things back to normal:

  1. If you happen to have completely lost the Show Desktop shortcut create a text file called "Show Desktop.scf" and add the following text to it:

     

    [Shell]
    Command=2
    IconFile=explorer.exe,3
    [Taskbar]
    Command=ToggleDesktop

     

  2. Finally open up the following folder "C:\Documents and Settings\{Your User Name}\Application Data\Microsoft\Internet Explorer\Quick Launch" and drag the file into the folder.
Sunday, 11 November 2007 17:27:38 (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback - Save to del.icio.us - Digg This! - Follow me on Twitter

# Saturday, 03 November 2007

    Now that Google has added IMAP to Google Apps and Gmail, see my previous post for more details, I have begun to switch over from my Hotmail account that I have been using for about ten years now, to using an email address at my domain hosted on Google Apps. Basically all I have been waiting for was the ability to access my Google Apps email using Outlook 2007. Google Apps has had a POP interface, but it is extremely horrible and downloads everything to your inbox, even the messages that you have sent. This requires you to setup mail filters in Outlook to get your messages where they should be which I have no urge of creating and maintaining just to get my emails into the folders where they should be at in the first place. About a month ago I had considered developing a service that pulled messages from Gmail and translated the file structure to a decent IMAP layout, but now Google has beat me there. The tagged style of messages in the Gmail/Google Apps Email web interface translates into folders on the client side. As shown in the screenshot below, the All Mail, Drafts, Sent Mail, Spam, Starred, and Trash folders are standard Gmail folders. The 1and1 and Admin folders are labels that I have created that show up as folder on the client side. Then I have my Inbox. One issue that I have noticed is that when I add a new label to the web interface I have to right click on my account in Outlook 2007 and select Update Folder List in order for the new folder to show up, but I assume the new folder would eventually show up on its own if I was patient.

 

    Of course, Google App Email/Gmail's web interface is fairly feature rich and handles things a bit differently then Outlook so there are some feature lost when using a client application and some features are represented differently in the client application. For instance, It Outlook 2007 you can flag an email, but in the web interface these emails will show up as starred.

Outlook 2007 view

Google Apps Email View

 

    Also in Google Apps Email/Gmail you have the ability to mark and email with multiple labels. For example in the below screenshot this test email is label, Inbox, 1and1, and Admin:

 

Google Apps Label View

    On the Outlook 2007 side this email also shows up in the Inbox folder, the 1and1 folder, and the Admin folder. If I create a new label in the web interface called Test, which creates a corresponding folder on my client side and copy the instance of the email in the 1and1 folder to the Test folder on the clients side this is reflected on the web interface as removing the 1and1 label from the email and adding the Test label to it. If I delete this email on the web interface side it will be removed from all folders on the client side and placed in the Trash folder. Moving an email to the trash folder on the client side will also move it to the trash folder on the web interface side.

    Hopefully this gives you a basic understanding of the interaction between Outlook and Google Apps Email. I will be happy when I finally get completely switched off of my Hotmail account, but at least for awhile it looks like I am going to have a bit of a split personality.

    

Saturday, 03 November 2007 10:43:42 (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback - Save to del.icio.us - Digg This! - Follow me on Twitter
Gmail | Google | Outlook 2007

Navigation
Archive
<2007 November>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2024
David A. Osborn
Sign In
Statistics
Total Posts: 70
This Year: 0
This Month: 0
This Week: 0
Comments: 33
Themes
Pick a theme:
All Content © 2024, David A. Osborn
DasBlog theme 'Business' created by Christoph De Baene (delarou)