//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OpenId.Extensions.SimpleRegistration {
using System;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Reflection;
///
/// Indicates the gender of a user.
///
public enum Gender {
///
/// The user is male.
///
Male,
///
/// The user is female.
///
Female,
}
///
/// Encodes/decodes the Simple Registration Gender type to its string representation.
///
internal class GenderEncoder : IMessagePartEncoder {
#region IMessagePartEncoder Members
///
/// Encodes the specified value.
///
/// The value. Guaranteed to never be null.
///
/// The in string form, ready for message transport.
///
public string Encode(object value) {
var gender = (Gender?)value;
if (gender.HasValue) {
switch (gender.Value) {
case Gender.Male: return Constants.Genders.Male;
case Gender.Female: return Constants.Genders.Female;
}
}
return null;
}
///
/// Decodes the specified value.
///
/// The string value carried by the transport. Guaranteed to never be null, although it may be empty.
///
/// The deserialized form of the given string.
///
/// Thrown when the string value given cannot be decoded into the required object type.
public object Decode(string value) {
switch (value) {
case Constants.Genders.Male: return SimpleRegistration.Gender.Male;
case Constants.Genders.Female: return SimpleRegistration.Gender.Female;
default: throw new FormatException();
}
}
#endregion
}
}