/// <summary>
 /// Serializes a value depdening on its type.
 /// </summary>
 /// <param name="obj">An object.</param>
 /// <returns></returns>
 public static string SerializeValue(object obj)
 {
     try
     {
         if (obj is string)
         {
             return(SerializeString(obj as string));
         }
         else if (obj is string[])
         {
             // string + language
             string[] array = obj as string[];
             return(SerializeTranslatedString(array[0], array[1]));
         }
         else if (obj is Tuple <string, CultureInfo> )
         {
             // string + language
             Tuple <string, CultureInfo> array = obj as Tuple <string, CultureInfo>;
             return(SerializeTranslatedString(array.Item1, array.Item2.Name));
         }
         else if (obj is Tuple <string, string> )
         {
             // string + language
             Tuple <string, string> array = obj as Tuple <string, string>;
             return(SerializeTranslatedString(array.Item1, array.Item2));
         }
         else if (obj is Uri || typeof(Uri).IsSubclassOf(obj.GetType()))
         {
             return(SerializeUri(obj as Uri));
         }
         else if (obj.GetType().GetInterface("IResource") != null)
         {
             return(SerializeUri((obj as IResource).Uri));
         }
         else if (obj.GetType().GetInterface("IModel") != null)
         {
             return(SerializeUri((obj as IModel).Uri));
         }
         else
         {
             return(SerializeTypedLiteral(obj, XsdTypeMapper.GetXsdTypeUri(obj.GetType())));
         }
     }
     catch
     {
         string msg = string.Format("No serializer availabe for object of type {0}.", obj.GetType());
         throw new ArgumentException(msg);
     }
 }
 /// <summary>
 /// Serializes a typed literal.
 /// </summary>
 /// <param name="obj">A value.</param>
 /// <param name="typeUri">A type URI.</param>
 /// <returns></returns>
 public static string SerializeTypedLiteral(object obj, Uri typeUri)
 {
     return(string.Format("'{0}'^^<{1}>", XsdTypeMapper.SerializeObject(obj), typeUri));
 }