RestImageResize/UniversalImageTransformationParser.cs
/// <summary>
/// Tries to parse transformation instance by name and properties string. 
/// </summary>
/// <param name="serializedProperties">The serialized transformation properties string.</param>
/// <param name="transformation">The transformation instance.</param>
/// <returns>
/// <c>true</c> if transformation is successfully parsed, otherwise - <c>False</c>
/// </returns>
Tries to parse transformation instance by name and properties string.
Tries to parse transformation instance by name and properties string .
public virtual bool TryParse(string serializedProperties, out IImageTransformation transformation)
        {
            transformation = null;
            try
            {
                var propertiesDictionary = ImageTransformation2.PropertiesSerializer.TryDeserialize(serializedProperties);
                if (propertiesDictionary == null)
                {
                    Logger.Log(LogEntrySeverity.Warning, $"Nothing to parse: '{serializedProperties}'");
                    return false;
                }
                var type = TransformationRegistry.TryGetByTransformationName(propertiesDictionary["transform"]);
                if (type != null && typeof (IImageTransformation).IsAssignableFrom(type))
                {
                    var ctor = type.GetConstructor(new[] {typeof (IDictionary<string, string>)});
                    if (ctor != null)
                    {
                        object instance = ctor.Invoke(new object[] {propertiesDictionary});
                        transformation = (IImageTransformation) instance;
                        return true;
                    }
                }
            }
            catch(Exception ex)
            {
                Logger.Log(LogEntrySeverity.Warning, $"Error parsing string '{serializedProperties}': {ex}");
                return false;
            }
            Logger.Log(LogEntrySeverity.Warning, $"Properties parsed, but transform is not created: '{serializedProperties}'");
            return false;
        }
public virtual bool TryParse ( string serializedProperties , out IImageTransformation transformation ) { transformation = null ; try { var propertiesDictionary = ImageTransformation2 . PropertiesSerializer . TryDeserialize ( serializedProperties ) ; if ( propertiesDictionary == null ) { Logger . Log ( LogEntrySeverity . Warning , $" Nothing to parse: ' { serializedProperties } ' " ) ; return false ; } var type = TransformationRegistry . TryGetByTransformationName ( propertiesDictionary [ " " ] ) ; if ( type != null && typeof ( IImageTransformation ) . IsAssignableFrom ( type ) ) { var ctor = type . GetConstructor ( new [ ] { typeof ( IDictionary < string , string > ) } ) ; if ( ctor != null ) { object instance = ctor . Invoke ( new object [ ] { propertiesDictionary } ) ; transformation = ( IImageTransformation ) instance ; return true ; } } } catch ( Exception ex ) { Logger . Log ( LogEntrySeverity . Warning , $" Error parsing string ' { serializedProperties } ':  { ex } " ) ; return false ; } Logger . Log ( LogEntrySeverity . Warning , $" Properties parsed, but transform is not created: ' { serializedProperties } ' " ) ; return false ; }
Tries to parse transformation instance by name and properties string.
Tries to parse transformation instance by name and properties string .
None
serializedProperties
string
The serialized transformation properties string.
The serialized transformation properties string .
IImageTransformation
out
transformation
The transformation instance.
The transformation instance .