Kelary.Infrastructure/Converters/MethodToValueConverter.cs
/// <summary>
/// Converts class instance to value returned by its method.
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter">Method name (method should have no argumants).</param>
/// <param name="culture"></param>
/// <returns></returns>
Converts class instance to value returned by its method.
Converts class instance to value returned by its method .
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var methodName = parameter as string;
            if (value == null || methodName == null)
                return value;
            try
            {
                return value.GetType().InvokeMember(methodName, BindingFlags.OptionalParamBinding | BindingFlags.InvokeMethod, null, value, new Type[0]);
            }
            catch
            {
                return value;
            }
        }
public object Convert ( object value , Type targetType , object parameter , CultureInfo culture ) { var methodName = parameter as string ; if ( value == null || methodName == null ) return value ; try { return value . GetType ( ) . InvokeMember ( methodName , BindingFlags . OptionalParamBinding | BindingFlags . InvokeMethod , null , value , new Type [ 0 ] ) ; } catch { return value ; } }
Converts class instance to value returned by its method.
Converts class instance to value returned by its method .
// Method not found.
None
value
object
None
targetType
Type
None
parameter
object
Method name (method should have no argumants).
Method name ( method should have no argumants ) .
culture
CultureInfo
None