コード例 #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="EntitySpec" />.</param>
 /// <returns>
 /// an instance of <see cref="EntitySpec" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public static object ConvertFrom(dynamic sourceValue)
 {
     if (null == sourceValue)
     {
         return(null);
     }
     try
     {
         EntitySpec.FromJsonString(typeof(string) == sourceValue.GetType() ? sourceValue : sourceValue.ToJsonString());
     }
     catch
     {
         // Unable to use JSON pattern
     }
     try
     {
         return(new EntitySpec
         {
             CategoryList = sourceValue.CategoryList,
             VmReference = VmReferenceTypeConverter.ConvertFrom(sourceValue.VmReference),
             VmSpec = VmTypeConverter.ConvertFrom(sourceValue.VmSpec),
         });
     }
     catch
     {
     }
     return(null);
 }
コード例 #2
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="VmIntentResource" />.</param>
 /// <returns>
 /// an instance of <see cref="VmIntentResource" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public static object ConvertFrom(dynamic sourceValue)
 {
     if (null == sourceValue)
     {
         return(null);
     }
     try
     {
         VmIntentResource.FromJsonString(typeof(string) == sourceValue.GetType() ? sourceValue : sourceValue.ToJsonString());
     }
     catch
     {
         // Unable to use JSON pattern
     }
     try
     {
         return(new VmIntentResource
         {
             ApiVersion = sourceValue.ApiVersion,
             Metadata = VmMetadataTypeConverter.ConvertFrom(sourceValue.Metadata),
             Spec = VmTypeConverter.ConvertFrom(sourceValue.Spec),
             Status = VmDefStatusTypeConverter.ConvertFrom(sourceValue.Status),
         });
     }
     catch
     {
     }
     return(null);
 }