summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Core/Messaging/Reflection/DefaultEncoderAttribute.cs
blob: adf0f33b13e7e0931b72fc42c61270c740677bac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//-----------------------------------------------------------------------
// <copyright file="DefaultEncoderAttribute.cs" company="Andrew Arnott">
//     Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.Messaging.Reflection {
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using Validation;

	/// <summary>
	/// Allows a custom class or struct to be serializable between itself and a string representation.
	/// </summary>
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
	internal sealed class DefaultEncoderAttribute : Attribute {
		/// <summary>
		/// Initializes a new instance of the <see cref="DefaultEncoderAttribute"/> class.
		/// </summary>
		/// <param name="converterType">The <see cref="IMessagePartEncoder"/> implementing type to use for serializing this type.</param>
		public DefaultEncoderAttribute(Type converterType) {
			Requires.NotNull(converterType, "converterType");
			Requires.That(typeof(IMessagePartEncoder).IsAssignableFrom(converterType), "Argument must be a type that implements {0}.", typeof(IMessagePartEncoder).Name);
			this.Encoder = (IMessagePartEncoder)Activator.CreateInstance(converterType);
		}

		/// <summary>
		/// Gets the default encoder to use for the declaring class.
		/// </summary>
		public IMessagePartEncoder Encoder { get; private set; }
	}
}