Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReactiveCollection should be CLS compilant (partial patch attached) #40

Closed
ghost opened this issue Dec 13, 2011 · 5 comments
Closed

ReactiveCollection should be CLS compilant (partial patch attached) #40

ghost opened this issue Dec 13, 2011 · 5 comments

Comments

@ghost
Copy link

ghost commented Dec 13, 2011

Adding "[assembly: CLSCompliant(true)]" to the Reactive UI results in an number of varnings about ReactiveCollection not beeing CLS compilat. The varnings are attached below and can easily be resolved.

1; Add [assembly: CLSCompliant(true)] to the AssemblyInfo.cs for all the projects
2; Update ReactiveCollection to become CLS compatible.
A patch is provided changing the offending member variables from protected to private,
it they really should be protected then they should instead be renamed (ex _ItemsAdded can be renamed to itemsAdded)

------------------------------------------------------ Varnings ------------------------------------------------------
ReactiveUI\ReactiveUI\ReactiveCollection.cs(157,34): warning CS3008: Identifier 'ReactiveUI.ReactiveCollection._ItemsAdded' is not CLS-compliant
ReactiveUI\ReactiveUI\ReactiveCollection.cs(169,31): warning CS3008: Identifier 'ReactiveUI.ReactiveCollection._BeforeItemsAdded' is not CLS-compliant
ReactiveUI\ReactiveUI\ReactiveCollection.cs(179,34): warning CS3008: Identifier 'ReactiveUI.ReactiveCollection._ItemsRemoved' is not CLS-compliant
ReactiveUI\ReactiveUI\ReactiveCollection.cs(190,31): warning CS3008: Identifier 'ReactiveUI.ReactiveCollection._BeforeItemsRemoved' is not CLS-compliant
ReactiveUI\ReactiveUI\ReactiveCollection.cs(204,36): warning CS3008: Identifier 'ReactiveUI.ReactiveCollection._CollectionCountChanging' is not CLS-compliant
ReactiveUI\ReactiveUI\ReactiveCollection.cs(215,36): warning CS3008: Identifier 'ReactiveUI.ReactiveCollection._CollectionCountChanged' is not CLS-compliant
ReactiveUI\ReactiveUI\ReactiveCollection.cs(226,56): warning CS3008: Identifier 'ReactiveUI.ReactiveCollection._ItemChanging' is not CLS-compliant
ReactiveUI\ReactiveUI\ReactiveCollection.cs(241,56): warning CS3008: Identifier 'ReactiveUI.ReactiveCollection._ItemChanged' is not CLS-compliant
ReactiveUI\ReactiveUI\ReactiveCollection.cs(255,64): warning CS3008: Identifier 'ReactiveUI.ReactiveCollection._Changing' is not CLS-compliant
ReactiveUI\ReactiveUI\ReactiveCollection.cs(266,64): warning CS3008: Identifier 'ReactiveUI.ReactiveCollection._Changed' is not CLS-compliant

------------------------------------------------------ Patch begin ------------------------------------------------------

Index: ReactiveCollection.cs

--- ReactiveCollection.cs (revision 378)
+++ ReactiveCollection.cs (working copy)
@@ -154,7 +154,7 @@
}

     [IgnoreDataMember]
  •    protected IObservable<T> _ItemsAdded;
    
  •    private IObservable<T> _ItemsAdded;
    
     /// <summary>
     /// Fires when items are added to the collection, once per item added.
    

    @@ -166,7 +166,7 @@
    }

     [IgnoreDataMember]
    
  •    protected ISubject<T> _BeforeItemsAdded;
    
  •    private ISubject<T> _BeforeItemsAdded;
    
     /// <summary>
     /// Fires before an item is going to be added to the collection.
    

    @@ -176,7 +176,7 @@
    }

     [IgnoreDataMember]
    
  •    protected IObservable<T> _ItemsRemoved;
    
  •    private IObservable<T> _ItemsRemoved;
    
     /// <summary>
     /// Fires once an item has been removed from a collection, providing the
    

    @@ -187,7 +187,7 @@
    }

     [IgnoreDataMember]
    
  •    protected ISubject<T> _BeforeItemsRemoved;
    
  •    private ISubject<T> _BeforeItemsRemoved;
    
     /// <summary>
     /// Fires before an item will be removed from a collection, providing
    

    @@ -198,10 +198,10 @@
    }

     [IgnoreDataMember]
    
  •    protected Subject<int> aboutToClear;
    
  •    private Subject<int> aboutToClear;
    
     [IgnoreDataMember]
    
  •    protected IObservable<int> _CollectionCountChanging;
    
  •    private IObservable<int> _CollectionCountChanging;
    
     /// <summary>
     /// Fires before a collection is about to change, providing the previous
    

    @@ -212,7 +212,7 @@
    }

     [IgnoreDataMember]
    
  •    protected IObservable<int> _CollectionCountChanged;
    
  •    private IObservable<int> _CollectionCountChanged;
    
     /// <summary>
     /// Fires whenever the number of items in a collection has changed,
    

    @@ -223,7 +223,7 @@
    }

     [IgnoreDataMember]
    
  •    protected ISubject<IObservedChange<T, object>> _ItemChanging;
    
  •    private ISubject<IObservedChange<T, object>> _ItemChanging;
    
     /// <summary>
     /// Provides Item Changed notifications for any item in collection that
    

    @@ -238,7 +238,7 @@
    }

     [IgnoreDataMember]
    
  •    protected ISubject<IObservedChange<T, object>> _ItemChanged;
    
  •    private ISubject<IObservedChange<T, object>> _ItemChanged;
    
     /// <summary>
     /// Provides Item Changing notifications for any item in collection that
    

    @@ -252,7 +252,7 @@
    }

     [IgnoreDataMember]
    
  •    protected IObservable<IObservedChange<object, object>> _Changing;
    
  •    private IObservable<IObservedChange<object, object>> _Changing;
    
     /// <summary>
     /// Fires when anything in the collection or any of its items (if Change
    

    @@ -263,7 +263,7 @@
    }

     [IgnoreDataMember]
    
  •    protected IObservable<IObservedChange<object, object>> _Changed;
    
  •    private IObservable<IObservedChange<object, object>> _Changed;
    
     /// <summary>
     /// Fires when anything in the collection or any of its items (if Change
    

    ------------------------------------------------------ Patch end ------------------------------------------------------

@anaisbetts
Copy link
Member

What is the practical benefit to being CLSCompliant (i.e. what scenarios are currently impossible but are now enabled with this?)

@ghost
Copy link
Author

ghost commented Jan 23, 2012

If the library is CLS compilant you can be sure that it is usable by all .NET languages such as VB, F# etc (in short being CLS compilant set some constraints on the naming externally accessible (public/protected) functions and variables).

In this specific instance protected members variables starts with underscore which is not possible all .Net compatible languages.

@anaisbetts
Copy link
Member

Which languages don't support this? Removing protected member variables that start with underscore is a breaking change.

@ghost
Copy link
Author

ghost commented Jan 24, 2012

Regarding which languages don't support leading underscore I have seen some examples earlier but right now I can only come up with C++ where leading underscore is reserved.
"Use of two sequential underscore characters ( __ ) at the
beginning of an identifier, or a single leading underscore
followed by a capital letter, is reserved for C++ implementations
in all scopes."

I would still argue for at least putting CLSCompilant(true) at the assembly level so that other isssues such as names that differ only by case (which won't work with VB) is not introduced.

To preserve backwardscompability you could do a rename on the variables and then create propteries.
One property (which is annotated as depreciated and CLSCompilant(false)) with the old name and another version with a new name such as Changed. By not exposing member variables directly but though properties you also adhere to OO best practices.

Ex:
Old:
protected IObservable<IObservedChange<object, object>> _Changed;
New:

[Obsolete("use Changed instead")]
[CLSCompilant(false)]
protected IObservable<IObservedChange<object, object>> _Changed { get {return _changed;} set {_changed = value;} }
protected IObservable<IObservedChange<object, object>> Changed { get {return _changed;} set {_changed = value;} }
private IObservable<IObservedChange<object, object>> _changed;

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant