Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ protected NameObjectCollectionBase(int capacity) { }
protected NameObjectCollectionBase(int capacity, System.Collections.IEqualityComparer? equalityComparer) { }
[System.ObsoleteAttribute("Please use NameObjectCollectionBase(Int32, IEqualityComparer) instead.")]
protected NameObjectCollectionBase(int capacity, System.Collections.IHashCodeProvider? hashProvider, System.Collections.IComparer? comparer) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
protected NameObjectCollectionBase(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public virtual int Count { get { throw null; } }
protected bool IsReadOnly { get { throw null; } set { } }
Expand All @@ -115,7 +116,9 @@ protected void BaseRemoveAt(int index) { }
protected void BaseSet(int index, object? value) { }
protected void BaseSet(string? name, object? value) { }
public virtual System.Collections.IEnumerator GetEnumerator() { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public virtual void OnDeserialization(object? sender) { }
void System.Collections.ICollection.CopyTo(System.Array array, int index) { }
public partial class KeysCollection : System.Collections.ICollection, System.Collections.IEnumerable
Expand All @@ -142,6 +145,7 @@ public NameValueCollection(int capacity, System.Collections.IEqualityComparer? e
[System.ObsoleteAttribute("Please use NameValueCollection(Int32, IEqualityComparer) instead.")]
public NameValueCollection(int capacity, System.Collections.IHashCodeProvider? hashProvider, System.Collections.IComparer? comparer) { }
public NameValueCollection(int capacity, System.Collections.Specialized.NameValueCollection col) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
protected NameValueCollection(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public virtual string?[] AllKeys { get { throw null; } }
public string? this[int index] { get { throw null; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.Serialization;
using System.Runtime.Versioning;

namespace System.Collections.Specialized
{
Expand Down Expand Up @@ -77,16 +78,19 @@ protected NameObjectCollectionBase(int capacity)
Reset(capacity);
}

[UnsupportedOSPlatform("browser")]
protected NameObjectCollectionBase(SerializationInfo info, StreamingContext context)
{
throw new PlatformNotSupportedException();
}

[UnsupportedOSPlatform("browser")]
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
throw new PlatformNotSupportedException();
}

[UnsupportedOSPlatform("browser")]
public virtual void OnDeserialization(object? sender)
{
throw new PlatformNotSupportedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Text;
using System.Runtime.Versioning;

namespace System.Collections.Specialized
{
Expand Down Expand Up @@ -94,6 +95,7 @@ public NameValueCollection(int capacity, IHashCodeProvider? hashProvider, ICompa
{
}

[UnsupportedOSPlatform("browser")]
protected NameValueCollection(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Collections/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
</PropertyGroup>
</Project>
4 changes: 4 additions & 0 deletions src/libraries/System.Collections/ref/System.Collections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ public partial struct Enumerator : System.Collections.Generic.IEnumerator<T>, Sy
public void Dispose() { }
public bool MoveNext() { throw null; }
void System.Collections.IEnumerator.Reset() { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
void System.Runtime.Serialization.IDeserializationCallback.OnDeserialization(object? sender) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
}
}
Expand Down Expand Up @@ -632,7 +634,9 @@ public partial struct Enumerator : System.Collections.Generic.IEnumerator<T>, Sy
public void Dispose() { }
public bool MoveNext() { throw null; }
void System.Collections.IEnumerator.Reset() { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
void System.Runtime.Serialization.IDeserializationCallback.OnDeserialization(object? sender) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
using System.Runtime.Versioning;

namespace System.Collections.Generic
{
Expand Down Expand Up @@ -596,11 +597,13 @@ public void Dispose()
{
}

[UnsupportedOSPlatform("browser")]
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
throw new PlatformNotSupportedException();
}

[UnsupportedOSPlatform("browser")]
void IDeserializationCallback.OnDeserialization(object? sender)
{
throw new PlatformNotSupportedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
using Interlocked = System.Threading.Interlocked;
using System.Runtime.Versioning;

namespace System.Collections.Generic
{
Expand Down Expand Up @@ -1922,11 +1923,13 @@ internal Enumerator(SortedSet<T> set, bool reverse)
Initialize();
}

[UnsupportedOSPlatform("browser")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This throws everywhere. Why mark it as unsupported for browser only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good question, thanks. I'm not sure if there is something like [UnsupportedOSPlatform("all")] to mark it for all the possible platforms. So in this case I've done it only for the related part.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc: @jeffhandley @adamsitnik did we consider an "all" value for the analyzer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would [Obsolete] be more appropriate for something not supported anywhere?

This makes me feel uneasy saying it, but I think you could pull off "not supported anywhere" by using [SupportedOSPlatform("none")]; I don't think I would endorse it though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would start with some better examples than this one.

The binary serialization methods touched in this PR are on interfaces and/or not meant to be directly called by user code. It means that the annotations on them are not going to make any difference in user experience. I think that the right action for these specific methods may be to do nothing and leave them alone.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree these ones we should not annotate them at all. I was just wondering if we should support an annotation for "ALL" platforms.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just wondering if we should support an annotation for "ALL" platforms.

I'll follow up on that off this issue

void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
throw new PlatformNotSupportedException();
}

[UnsupportedOSPlatform("browser")]
void IDeserializationCallback.OnDeserialization(object? sender)
{
throw new PlatformNotSupportedException();
Expand Down