//----------------------------------------------------------------------- // // Copyright (c) Andrew Arnott. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.Messaging.Reflection { using System; /// /// A pair of conversion functions to map some type to a string and back again. /// internal struct ValueMapping { /// /// The mapping function that converts some custom type to a string. /// internal readonly Func ValueToString; /// /// The mapping function that converts a string to some custom type. /// internal readonly Func StringToValue; /// /// Initializes a new instance of the struct. /// /// The mapping function that converts some custom type to a string. /// The mapping function that converts a string to some custom type. internal ValueMapping(Func toString, Func toValue) { ErrorUtilities.VerifyArgumentNotNull(toString, "toString"); ErrorUtilities.VerifyArgumentNotNull(toValue, "toValue"); this.ValueToString = toString; this.StringToValue = toValue; } /// /// Initializes a new instance of the struct. /// /// The encoder. internal ValueMapping(IMessagePartEncoder encoder) { ErrorUtilities.VerifyArgumentNotNull(encoder, "encoder"); var nullEncoder = encoder as IMessagePartNullEncoder; string nullString = nullEncoder != null ? nullEncoder.EncodedNullValue : null; this.ValueToString = obj => (obj != null) ? encoder.Encode(obj) : nullString; this.StringToValue = str => (str != null) ? encoder.Decode(str) : null; } } }