" operators?" />
E
E
eliasum2021-08-20 14:29:11
C++ / C#
eliasum, 2021-08-20 14:29:11

How to rewrite a class without "?:" and "=>" operators?

How to rewrite the class below without the "?:" and "=>" operators and other "news" so that the code works under the .Net Framework 4.0 in VS2010?

class XmlAttributeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
          => value is IEnumerable<XmlNode> values
            ? values.OfType<XmlAttribute>().Select(xa => xa.Value)
            : value;

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
          => throw new NotImplementedException();
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Vokhmentsev, 2021-08-20
@eliasum

class XmlAttributeConverter : IValueConverter
{
  public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  {
    if (value is IEnumerable<XmlNode> values)
    {
      return values.OfType<XmlAttribute>().Select(xa => xa.Value);
    }

    return value;		
  }

  public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  {
    throw new NotImplementedException();
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question