Click here to Skip to main content
15,896,915 members
Articles / Web Development / ASP.NET

RSS 2.0 Framework

Rate me:
Please Sign up or sign in to vote.
4.92/5 (67 votes)
19 Jan 2013LGPL37 min read 508.9K   15.2K   361  
RSS 2.0 framework implements the RSS 2.0 specification in strongly typed classes. The framework enables you to create and consume valid RSS 2.0 feeds in your code in just a few minutes.
// Copyright � 2006 by Christoph Richner. All rights are reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//
// website http://www.raccoom.net, email support@raccoom.net, msn chrisdarebell@msn.com

using System;
using System.Drawing;
using System.Drawing.Design;
using System.ComponentModel;
using System.Reflection;
using System.Windows.Forms;

namespace Actions.Design
{
	/// <summary>
	/// The base class for the UITypeEditor for an index in an ImageList.
	/// </summary>
	public abstract class ImageIndexEditorBase : UITypeEditor
	{
		/// <summary>
		/// Indicates whether the specified context supports painting a representation of an object's value within the specified context.
		/// </summary>
		/// <param name="context">An ITypeDescriptorContext that can be used to gain additional context information.</param>
		/// <returns>true if PaintValue is implemented; otherwise, false.</returns>
		public override bool GetPaintValueSupported(ITypeDescriptorContext context)
		{
			return true;
		}
		/// <summary>
		/// Paints a representation of the value of an object using the specified PaintValueEventArgs.
		/// </summary>
		/// <param name="pe">A PaintValueEventArgs that indicates what to paint and where to paint it.</param>
		public override void PaintValue(PaintValueEventArgs pe)
		{
			if (!(pe.Value is int))
			{
				return;
			}
			Image img = GetImage(pe.Context, (int)pe.Value);
			if (img != null)
			{
				pe.Graphics.DrawImage(img, pe.Bounds);
			}
		}
		/// <summary>
		/// Get the image corresponding to the corresponding index. The imageList is determined firstly by looking at property of type ImageList among the instance properties,
		/// secondly by looking at the properties of the "Parent" property of the instance
		/// </summary>
		/// <param name="context">The context of the call</param>
		/// <param name="index">The index of the image</param>
		/// <returns>The corresponding image or null</returns>
		private Image GetImage(ITypeDescriptorContext context, int index)
		{
			ImageList		il = GetImageList(context);
			if (il == null || index < 0 || index >= il.Images.Count)
			{
				return null;
			}
			return il.Images[index];
		}
		/// <summary>
		/// Abstract method which allow to find the ImageList for the given context
		/// </summary>
		/// <param name="context">The context of the call</param>
		/// <returns>An ImageList</returns>
		protected abstract ImageList GetImageList(ITypeDescriptorContext context);
	}
	
	/// <summary>
	/// An UITypeEditor for an index in an ImageList. There is one in System.Windows.Form.Design but unfortunately it's a private class.
	/// </summary>
	public class ImageIndexEditor : ImageIndexEditorBase
	{
		/// <summary>
		/// Finds the ImageList for the given context by looking first at property of type ImageList among the instance properties,
		/// and if the search was unsuccessful by looking at the properties of the "Parent" property of the instance
		/// </summary>
		/// <param name="context">The context of the call</param>
		/// <returns>An ImageList</returns>
		protected override ImageList GetImageList(ITypeDescriptorContext context)
		{
			// try first to find a property of type ImageList among the instance properties
			ImageList		il = null;
			PropertyInfo[]	props = context.Instance.GetType().GetProperties();
			foreach(PropertyInfo prop in props)
			{
				if (prop.PropertyType == typeof(ImageList) && prop.CanRead)
				{
					il = (ImageList)prop.GetValue(context.Instance, null);
					break;
				}
			}
			// if not found, look for a "Parent" property and do the same search on the parent
			if (il == null)
			{
				PropertyInfo parentprop = context.Instance.GetType().GetProperty("Parent");
				if (parentprop != null)
				{
					object parent = parentprop.GetValue(context.Instance, null);
					if (parent != null)
					{
						props = parent.GetType().GetProperties();
						foreach(PropertyInfo prop in props)
						{
							if (prop.PropertyType == typeof(ImageList) && prop.CanRead)
							{
								il = (ImageList)prop.GetValue(parent, null);
								break;
							}
						}
					}
				}
			}
			return il;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer (Senior)
Switzerland Switzerland
My interest is in the future because I am going to spend the rest of my life there. (Charles Kettering)

Biography

  • 1996 - 1998 PC Board PPL, HTML, DHTML, Javascript and ASP
  • 1999 - 2001 coding Centura against Sql Database (SqlBase,MSSQL,Oracle)
  • 2002 - 2004 C# Windows Forms
  • 2005 - 2006 C# ASP.NET, Windows Forms
  • 2006 - 2009 C#, WCF, WF, WPF
  • 2010 - 2012 C#, Dynamics CRM, Sharepoint, Silverlight
  • 2013 - 2013 C#, WCF DS (OData), WF, WPF
  • 2014 - 2016 C#, Azure PaaS, Identity, OWIN, OData, Web Api
  • 2017 - now C#, aspnet.core, IdentityServer4, TypeScript & Angular @ Azure IaaS or PaaS

Interests

  • family & friends
  • chilaxing ,)
  • coding

Comments and Discussions