/// <summary> /// Get a string representation of the enum value. /// </summary> /// <exception cref="SerializationException">Enum is not registered.</exception> private static object GetEnumValue(SerializationContext context, Type type, object value) { if (value == null) throw new ArgumentNullException("value"); var descriptor = context.GetEnumDescriptor(type); if (descriptor == null) { throw new SerializationException( string.Format( "Unable to resolve type '{0}'. Check if type was registered within the serializer.", type.FullName)); } if (!descriptor.Values.ContainsKey(value)) { throw new SerializationException( string.Format( "Invalid enumeration value '{0}'.", value)); } return descriptor.Values[value]; }