Ejemplo n.º 1
0
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the value to convert into an instance of <see cref="ImageMetadata" />.</param>
 /// <returns>
 /// an instance of <see cref="ImageMetadata" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public static object ConvertFrom(dynamic sourceValue)
 {
     if (null == sourceValue)
     {
         return(null);
     }
     try
     {
         ImageMetadata.FromJsonString(typeof(string) == sourceValue.GetType() ? sourceValue : sourceValue.ToJsonString());
     }
     catch
     {
         // Unable to use JSON pattern
     }
     try
     {
         return(new ImageMetadata
         {
             Name = sourceValue.Name,
             Categories = sourceValue.Categories,
             CreationTime = sourceValue.CreationTime,
             Kind = sourceValue.Kind,
             LastUpdateTime = sourceValue.LastUpdateTime,
             OwnerReference = UserReferenceTypeConverter.ConvertFrom(sourceValue.OwnerReference),
             ProjectReference = ProjectReferenceTypeConverter.ConvertFrom(sourceValue.ProjectReference),
             SpecHash = sourceValue.SpecHash,
             SpecVersion = sourceValue.SpecVersion,
             Uuid = sourceValue.Uuid,
         });
     }
     catch
     {
     }
     return(null);
 }