Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 49 additions & 41 deletions src/Foundation/NSSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,62 +32,56 @@
using System.Collections;
using System.Collections.Generic;

// Disable until we get around to enable + fix any issues.
#nullable disable
#nullable enable

namespace Foundation {

public partial class NSSet : IEnumerable<NSObject> {
/// <param name="objs">To be added.</param>
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
/// <summary>Creates a new <see cref="NSSet" /> from an array of <see cref="NSObject" /> instances.</summary>
/// <param name="objs">An array of <see cref="NSObject" /> instances to include in the set.</param>
public NSSet (params NSObject [] objs) : this (NSArray.FromNSObjects (objs))
{
}

/// <param name="objs">To be added.</param>
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
/// <summary>Creates a new <see cref="NSSet" /> from an array of objects.</summary>
/// <param name="objs">An array of objects to include in the set.</param>
public NSSet (params object [] objs) : this (NSArray.FromObjects (objs))
{
}

/// <summary>Creates a new <see cref="NSSet" /> from an array of strings.</summary>
/// <param name="strings">An array of strings.</param>
/// <summary>Creates a set from an array of strings.</summary>
/// <remarks>The C# strings are stored as NSString objects in the set.</remarks>
/// <remarks>The C# strings are stored as <see cref="NSString" /> objects in the set.</remarks>
public NSSet (params string [] strings) : this (NSArray.FromStrings (strings))
{
}

/// <typeparam name="T">Strongly typed version of the array that you want to get, must be a class that derives from <see cref="Foundation.NSObject" />.</typeparam>
/// <summary>Returns the contents of the set as a strongly typed array.</summary>
/// <returns>An array of type T with the contents of the set.</returns>
/// <remarks>
/// <para>
/// The following example shows how to get an array of UIFonts
/// </para>
/// <example>
/// <code lang="c#"><![CDATA[
/// <summary>Returns the contents of the set as a strongly typed array.</summary>
/// <typeparam name="T">Strongly typed version of the array that you want to get, must be a class that derives from <see cref="NSObject" />.</typeparam>
/// <returns>An array of type <typeparamref name="T" /> with the contents of the set.</returns>
/// <remarks>
/// <para>The following example shows how to get an array of UIFonts:</para>
/// <example>
/// <code lang="c#"><![CDATA[
/// var myColors = new NSSet (UIColor.Red, UIColor.Blue, UIColor.Yellow);
/// UIColor [] asArray = myColors.ToArray<UIColor> ();
/// ]]></code>
/// </example>
/// </remarks>
/// </example>
/// </remarks>
public T [] ToArray<T> () where T : class, INativeObject
{
IntPtr nsarr = _AllObjects ();
return NSArray.ArrayFromHandle<T> (nsarr);
}

/// <typeparam name="T">To be added.</typeparam>
/// <param name="values">To be added.</param>
/// <summary>To be added.</summary>
/// <returns>To be added.</returns>
/// <remarks>To be added.</remarks>
/// <summary>Creates a new <see cref="NSSet" /> from an array of strongly typed values.</summary>
/// <typeparam name="T">The type of values in the array, must be a class that derives from <see cref="NSObject" />.</typeparam>
/// <param name="values">An array of strongly typed values to include in the set.</param>
/// <returns>A new <see cref="NSSet" /> containing the specified values.</returns>
public static NSSet MakeNSObjectSet<T> (T [] values) where T : class, INativeObject
{
using (var a = NSArray.FromNSObjects (values))
return Runtime.GetNSObject<NSSet> (_SetWithArray (a.Handle));
return Runtime.GetNSObject<NSSet> (_SetWithArray (a.Handle))!;
}

#region IEnumerable<T>
Expand All @@ -104,37 +98,48 @@ public IEnumerator<NSObject> GetEnumerator ()
#endregion

#region IEnumerable
/// <summary>Enumerate over the NSObjects in the set.</summary>
/// <returns>
/// </returns>
/// <remarks>This returns an enumerator that returns the NSObject objects contained in the set. They are returned as System.Object objects.</remarks>
/// <summary>Enumerates over the <see cref="NSObject" /> instances in the set.</summary>
/// <returns>An enumerator that can be used to iterate through the set.</returns>
/// <remarks>This returns an enumerator that returns the <see cref="NSObject" /> objects contained in the set. They are returned as <see cref="System.Object" /> objects.</remarks>
IEnumerator IEnumerable.GetEnumerator ()
{
return ((IEnumerable<NSObject>) this).GetEnumerator ();
}
#endregion

public static NSSet operator + (NSSet first, NSSet second)
/// <summary>Adds two sets together, creating a new set that contains all elements from both sets.</summary>
/// <param name="first">The first set.</param>
/// <param name="second">The second set.</param>
/// <returns>A new <see cref="NSSet" /> containing all elements from both sets.</returns>
public static NSSet? operator + (NSSet? first, NSSet? second)
{
if (first is null)
return new NSSet (second);
return second is not null ? new NSSet (second) : null;
if (second is null)
return new NSSet (first);
return first.SetByAddingObjectsFromSet (second);
}

public static NSSet operator + (NSSet first, NSOrderedSet second)
/// <summary>Adds a set and an ordered set together, creating a new set that contains all elements from both.</summary>
/// <param name="first">The set.</param>
/// <param name="second">The ordered set.</param>
/// <returns>A new <see cref="NSSet" /> containing all elements from both the set and the ordered set.</returns>
public static NSSet? operator + (NSSet? first, NSOrderedSet? second)
{
if (first is null)
return new NSSet (second.AsSet ());
return second is not null ? new NSSet (second.AsSet ()) : null;
if (second is null)
return new NSSet (first);
var copy = new NSMutableSet (first);
copy.UnionSet (second.AsSet ());
return copy;
}

public static NSSet operator - (NSSet first, NSSet second)
/// <summary>Subtracts the elements of the second set from the first set.</summary>
/// <param name="first">The set to subtract from.</param>
/// <param name="second">The set whose elements should be removed.</param>
/// <returns>A new <see cref="NSSet" /> containing the elements in <paramref name="first" /> that are not in <paramref name="second" />, or <see langword="null" /> if <paramref name="first" /> is <see langword="null" />.</returns>
public static NSSet? operator - (NSSet? first, NSSet? second)
{
if (first is null)
return null;
Expand All @@ -145,7 +150,11 @@ IEnumerator IEnumerable.GetEnumerator ()
return copy;
}

public static NSSet operator - (NSSet first, NSOrderedSet second)
/// <summary>Subtracts the elements of an ordered set from a set.</summary>
/// <param name="first">The set to subtract from.</param>
/// <param name="second">The ordered set whose elements should be removed.</param>
/// <returns>A new <see cref="NSSet" /> containing the elements in <paramref name="first" /> that are not in <paramref name="second" />, or <see langword="null" /> if <paramref name="first" /> is <see langword="null" />.</returns>
public static NSSet? operator - (NSSet? first, NSOrderedSet? second)
{
if (first is null)
return null;
Expand All @@ -156,10 +165,9 @@ IEnumerator IEnumerable.GetEnumerator ()
return copy;
}

/// <param name="obj">To be added.</param>
/// <summary>To be added.</summary>
/// <returns>To be added.</returns>
/// <remarks>To be added.</remarks>
/// <summary>Determines whether the set contains the specified object.</summary>
/// <param name="obj">The object to locate in the set.</param>
/// <returns><see langword="true" /> if the set contains the specified object; otherwise, <see langword="false" />.</returns>
public bool Contains (object obj)
{
return Contains (NSObject.FromObject (obj));
Expand Down
4 changes: 0 additions & 4 deletions tests/cecil-tests/Documentation.KnownFailures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11993,10 +11993,6 @@ M:Foundation.NSRange.#ctor(System.IntPtr,System.IntPtr)
M:Foundation.NSRange.Equals(Foundation.NSRange)
M:Foundation.NSRange.Equals(System.Object)
M:Foundation.NSRange.GetHashCode
M:Foundation.NSSet.op_Addition(Foundation.NSSet,Foundation.NSOrderedSet)
M:Foundation.NSSet.op_Addition(Foundation.NSSet,Foundation.NSSet)
M:Foundation.NSSet.op_Subtraction(Foundation.NSSet,Foundation.NSOrderedSet)
M:Foundation.NSSet.op_Subtraction(Foundation.NSSet,Foundation.NSSet)
M:Foundation.NSSet`1.op_Addition(Foundation.NSSet{`0},Foundation.NSSet{`0})
M:Foundation.NSSet`1.op_Subtraction(Foundation.NSSet{`0},Foundation.NSSet{`0})
M:Foundation.NSStream.add_OnEvent(System.EventHandler{Foundation.NSStreamEventArgs})
Expand Down
Loading