I use WPF Catel. Faced a problem:

//обошенный класс унаследованный от ModelBase public sealed class TestType<T> : ModelBase { #region Constructor public TestType() { } #endregion #region Properties public ushort Val { get { return GetValue<ushort>(ValProperty); } set { SetValue(ValProperty, value); } } public static readonly PropertyData ValProperty = RegisterProperty("Val", typeof(ushort)); #endregion } 

// View Model where I use Model

  public class MainWindowViewModel : ViewModelBase { #region Properties [Model] public TestType<bool> Xxx { get { return GetValue<TestType<bool>>(XxxProperty); } set { SetValue(XxxProperty, value); } } public static readonly PropertyData XxxProperty = RegisterProperty("Xxx", typeof(TestType<bool>)); #endregion #region Commands private Command _editCommand; public Command EditCommand { get { return _editCommand ?? (_editCommand = new Command( () => { Xxx = new TestType<bool>(); }, () => true)); } } #endregion } 

when assigning an Xml serialization exception to the command body, when Xxx is marked with the [Model] attribute.

And resharper swears: static field in a generalized class

 public static readonly PropertyData XxxProperty 

If the TestType class is made ordinary, there will be no error. Make PropertyData not static fails swears. Please tell me how to be.

  • Excuse me, what is Catel ? This is some kind of internal problem of the ModelBase class, apparently. Where in your code Xml-serialization is unclear. And the message from the resharper has nothing to do with the problem (and most likely it is simply wrong). - VladD
  • Catel is a framework for working with WPF. I looked for the catel tag on the forum but did not find it, put the question in the WPF section. serialization occurs there by the internal mechanisms of the cathel when assigning (so that the rollback to the previous state works). I understand that the question is specific. but I don’t know where to ask him - Aldmi
  • @Aldmi: I see. The problem seems to be somewhere in the Catel configuration, because the error says about serialization. - VladD

1 answer 1

Why ReSharper scolds: he warns you that for each T in TestType<> will be a separate value of the ValProperty field. Often this is not what the programmer wants, because in non-generic classes the value of a static field is only one.

Why swears Catel: please provide the full error message. From the code it is not clear why you gave up the Model attribute on the property in MainWindowViewModel - what do you want to map to?

  • Why resharper swears, I understand, but why the properties of the cattle do not have a generic version for such cases? XmlException not processed. The "` ", hexadecimal value 0x60, cannot be used in names. I will map out the TestType properties, I just didn’t give all the code. Limited to a small piece so that it was clear that this particular code leads to an error - Aldmi
  • Everything revolves around the Model attribute on a generic class that has a mapping field not a generic, but it should be a Katelian property - Aldmi