diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2012-04-05 09:23:12 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-04-05 09:23:12 -0700 |
commit | 57a6ac092dc7f723381b5145b34ecff2eea3e724 (patch) | |
tree | 2c60cd84d7498a0dcacc3a15b209de625a60d52a /src/DotNetOpenAuth.Core/Messaging/Reflection/DefaultEncoderAttribute.cs | |
parent | 2fe0a3d03eac3d4a238347f023bb63fd579d1060 (diff) | |
download | DotNetOpenAuth-57a6ac092dc7f723381b5145b34ecff2eea3e724.zip DotNetOpenAuth-57a6ac092dc7f723381b5145b34ecff2eea3e724.tar.gz DotNetOpenAuth-57a6ac092dc7f723381b5145b34ecff2eea3e724.tar.bz2 |
Fixes InvalidCastExceptions for Identifier and Realm conversions
that can result from receiving a message before the static constructors for those types have executed.
This corrects the regression introduced in v4.0.0.
Fixes #109
Diffstat (limited to 'src/DotNetOpenAuth.Core/Messaging/Reflection/DefaultEncoderAttribute.cs')
-rw-r--r-- | src/DotNetOpenAuth.Core/Messaging/Reflection/DefaultEncoderAttribute.cs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.Core/Messaging/Reflection/DefaultEncoderAttribute.cs b/src/DotNetOpenAuth.Core/Messaging/Reflection/DefaultEncoderAttribute.cs new file mode 100644 index 0000000..d827972 --- /dev/null +++ b/src/DotNetOpenAuth.Core/Messaging/Reflection/DefaultEncoderAttribute.cs @@ -0,0 +1,33 @@ +//----------------------------------------------------------------------- +// <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; + + /// <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.True(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; } + } +} |