Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » Howto » Downloads
 
Add your own
alternative version
Go to top

Fixing the IExtenderProvider in Visual Studio's ASP.NET designer

, 4 Jan 2005
An implementation of a custom CodeDomSerializer for repairing the IExtenderProvider in Visual Studio's ASP.NET designer.
namespace ASPExtenderSample
{
	#region [===== Using =====]
	using System;
	using System.ComponentModel;
	using System.Reflection;
	#endregion

	/// <summary>
	/// A helper class for the <see cref="ASPExtenderSerializer"/>. It provides access
	/// to the reflection methods required for the serializer.
	/// </summary>
	internal class ReflectionHelper 
	{
		#region [===== Public static methods =====]
		/// <summary>
		/// Returns the current value of a provided property for a specific component.
		/// </summary>
		/// <param name="provider">The provider which manages the <paramref name="property"/>.</param>
		/// <param name="property">The property to get the value for.</param>
		/// <param name="component">The component to get the value for.</param>
		/// <returns>The value of the <paramref name="property"/> for <paramref name="component"/>.</returns>
		public static object GetCurrentValue(IExtenderProvider provider, ProvidePropertyAttribute property, 
			IComponent component)
		{
			Type type = provider.GetType();
			MethodInfo method = type.GetMethod("Get" + property.PropertyName);
			return method.Invoke(provider, new object[]{component});
		}

		/// <summary>
		/// Returns a value indicating whether a provided property has a default value.
		/// </summary>
		/// <param name="provider">The provider which manages the <paramref name="property"/>.</param>
		/// <param name="property">The property to verify.</param>
		/// <returns><b>True</b> when the <paramref name="property"/> has a default value,
		/// otherwise <b>False</b>.</returns>
		public static bool HasDefaultValue(IExtenderProvider provider, ProvidePropertyAttribute property)
		{
			Type type = provider.GetType();
			MethodInfo method = type.GetMethod("Get" + property.PropertyName);
			return method.GetCustomAttributes(typeof(DefaultValueAttribute), true).Length != 0;
		}

		/// <summary>
		/// Returns the default value for a provided property.
		/// </summary>
		/// <param name="provider">The provider which manages the <paramref name="property"/>.</param>
		/// <param name="property">The property to get the default value for.</param>
		/// <returns>The default value of <paramref name="property"/> (which can be null),
		/// otherwise null.</returns>
		public static object GetDefaultValue(IExtenderProvider provider, ProvidePropertyAttribute property)
		{
			Type type = provider.GetType();
			MethodInfo method = type.GetMethod("Get" + property.PropertyName);
			DefaultValueAttribute[] attributes = (DefaultValueAttribute[])method.GetCustomAttributes(typeof(DefaultValueAttribute), true);
			return attributes.Length > 0 ? attributes[0].Value : null;
		}
		#endregion
	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Wouter van Vugt
Web Developer Code Counsel
Netherlands Netherlands
Wouter van Vugt is a Microsoft MVP with Office Open XML technologies and an independent consultant focusing on creating Office Business Applications (OBAs) with SharePoint, the Office 2007 system and related .NET technologies. Wouter is a frequent contributor to developer community sites such as OpenXmlDeveloper.org and MSDN and has published several white papers and articles as well a book available on line titled Open XML: the markup explained. Wouter is the founder of Code-Counsel, a Dutch company focusing on delivering cutting-edge technical content through a variety of channels. You can find out more about Wouter by reading his blog and visiting the Code-Counsel Web site.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 5 Jan 2005
Article Copyright 2005 by Wouter van Vugt
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid