c# - Type casting Collections using Conversion Operators -


Change the user-defined conversion from the code given below, while the snippet # 2 does not. It seems that

what are my options? Clear operator as extension operator? anything else?

  Public stable clear operator observable collection & lt; ViewModel & gt; (Observation selection  model collection) {var viewModelCollection = new Observeable Collection & lt; ViewModel & gt; (); Select foreign currency (diverse models in the model) {see Model Collection.ad (see new modal () {model = model}); } Return viewModelCollection; }  

snippet # 2

  public steady clear operator ViewModel {model model} {new view model () {model = model}; }  

Thanks advance!

I recommend you to convert a collection using:

  var viewModelCollection = New Observation Collection & lt; ViewModel & gt; (ModelCollection.Cast & lt; ViewModel & gt; ());  

If you prefer Exstans you can define some (to avoid new ones in the previous code):

  Public stable supervisory collection & Lt; T & gt; ToObservableCollection & lt; T & gt; (This is IEnumerable & lt; T & gt; coll) {New Observeable Collection & lt; T & gt; (Coll); }  

Or, maybe to do everything in one shot:

  Public Stable Supervision Collection & lt; TNew & gt; Cast obsessive & lt; TNew, TOLD & gt; (This observation selection & lt; TOLD & gt; Mulcoll) {New Observe Collection & lt; TNew & gt; (OriginalColl.Cast & lt; TNew & gt; ()); }  

Clearly all previous codes, if you have defined the snippet # 2


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -