I'm writing a Windows Runtime Component in C#. I want to implement the IEquatable interface in some of my types. I don't need to expose the Equals method to the consumers of the component, I just want my unit tests to be able to compare between instances. Implementing IEquatable is not allowed because it's a generic type. What would be the best alternative?
标签:
windows-runtime
相关问题
- Inheritance impossible in Windows Runtime Componen
- Replacing or recreating a file in Windows 8 RT kee
- Draw waveform from MP3 stream in C# on WinRT
- how to disable caching HTTP GET in metro app, I am
- Windows 8 app (html & Javascript) : alternate way
相关文章
- Show flyout using BottomAppBar
- Get English exception message instead of local lan
- How to remove an element from an IGrouping
- Exception when reading text from the file using Fi
- HttpUtility.HtmlDecode in WinRT
- Building Windows 8 Metro App on Windows 7 with Vis
- Loading Loose Xaml with custom controls on WinRT f
- How do I use INotifyPropertyChanged in WinRT?
According to https://msdn.microsoft.com/EN-US/library/bsc2ak47(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp
The .Net Framework supplies default implementation for ToString(), Equals(Object) and GetHashCode to WinRT types.
When the default EqualityComparer is used on a type that does not implement IEquatable it defaults to Equals(Object).
So to mimic IEquatable for a WinRT type you just need to override Object.Equals on your type. This requires you also override GetHashCode.
Here is an example class:
Unfortunately there is no mechanism for implementing deep comparison between two winrt types :(.