Port the majority of the System.ComponentModel APIs into the open#12081
Port the majority of the System.ComponentModel APIs into the open#12081AlexGhiondea merged 2 commits intodotnet:masterfrom
Conversation
| "netstandard1.7": { | ||
| "imports": [ | ||
| "dotnet5.1" | ||
| "dotnet5.4" |
There was a problem hiding this comment.
"dotnet5.4 [](start = 7, length = 11)
I believe you can remove "imports" sections
| // <copyright file="Component.cs" company="Microsoft"> | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // </copyright> | ||
| //------------------------------------------------------------------------------ |
There was a problem hiding this comment.
I believe you should replace all comments of this sort with
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
There was a problem hiding this comment.
I rand the codeformatter on the TypeConverter project, but I missed the files I added to the Primitives folder.
There was a problem hiding this comment.
Argh -- the code formatter did not remove the existing copyright headers....
| //------------------------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // </copyright> | ||
| //------------------------------------------------------------------------------ |
| { | ||
| using System; | ||
|
|
||
| /// <devdoc> |
There was a problem hiding this comment.
probably search and replace devdoc for summary and remove para ?
| /// Specifies a set of technologies designer hosts should support. | ||
| /// </para> | ||
| /// </devdoc> | ||
| [System.Runtime.InteropServices.ComVisible(true)] |
There was a problem hiding this comment.
check with Wes, but I think we are stripping all ComVisible attributes.
| protected virtual object GetService(System.Type service) { throw null; } | ||
| public override string ToString() { throw null; } | ||
| } | ||
| // public partial class Component : System.IDisposable |
There was a problem hiding this comment.
// [](start = 4, length = 2)
?
There was a problem hiding this comment.
This has been pushed down into the Primitives.
| * An object that can rollback edits. | ||
| * | ||
| * Copyright (c) 1999 Microsoft Corporation | ||
| */ |
5340963 to
5b29529
Compare
|
Are you planning to include tests in this commit, or a subsequent one? I have a preference for the same commit unless there is a good reason (eg unblock others). |
|
I am planning to have them as part of the same PR, but probably in a separate commit to keep things nicer. |
|
|
||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Nit: Leading whitespace. Applies to many files in this PR.
There was a problem hiding this comment.
This is a by-product of removing the old style copyright headers. I will see if the CodeFormatter tool can fix this. If it cannot, I am going to leave it as-is.
There was a problem hiding this comment.
👎 we should fix them even if the codeformatter doesn't.
There was a problem hiding this comment.
@justinvp sorry if my previous comment came off wrong -- really appreciate your code reviews! :)
| /// Initializes a new instance of the <see cref='System.ComponentModel.AddingNewEventArgs'/> class, | ||
| /// with no new object defined. | ||
| /// </summary> | ||
| public AddingNewEventArgs() : base() |
There was a problem hiding this comment.
Nit: the : base() is unnecessary here and in the ctor below.
There was a problem hiding this comment.
Agreed. This and the other commend you added below are good candidates for cleaning up after this large chunk of code is ported into the open.
| /// one itself. | ||
| /// </summary> | ||
| [HostProtection(SharedState = true)] | ||
| public class AddingNewEventArgs : EventArgs |
There was a problem hiding this comment.
Nit: This class could be simplified...
public class AddingNewEventArgs : EventArgs
{
public AddingNewEventArgs()
{
}
public AddingNewEventArgs(object newObject)
{
NewObject = newObject;
}
public object NewObject { get; set; }
}There was a problem hiding this comment.
I am going to capture these and the related comments about improving the code into a separate issue that we can tackle after the code has been ported into the open.
|
|
||
|
|
||
| /* | ||
| */ |
There was a problem hiding this comment.
Nit: In addition to the leading whitespace, some files have these empty comments.
| return _bindable.GetHashCode(); | ||
| } | ||
|
|
||
| #if !SILVERLIGHT |
There was a problem hiding this comment.
Should the SILVERLIGHT ifdef be removed?
| using System.Security.Permissions; | ||
| using CodeAccessPermission = System.Security.CodeAccessPermission; | ||
|
|
||
| /// <include file='doc\BindingList.uex' path='docs/doc[@for="BindingList"]/*' /> |
There was a problem hiding this comment.
Should the <includes> be removed?
| private bool _raiseListChangedEvents = true; | ||
| private bool _raiseItemChangedEvents = false; | ||
|
|
||
| [NonSerialized()] |
There was a problem hiding this comment.
Nit: Could be [NonSerialized] (parens aren't needed).
There was a problem hiding this comment.
Will leave as-is for now. We can clean up all the code (including the other suggestions) once the port is complete!
There was a problem hiding this comment.
This was in a single file. Simple enough to change now.
| } | ||
| } | ||
|
|
||
| private static class CultureInfoMapper |
There was a problem hiding this comment.
This could be improved...
Benefits:
- Avoids intermediate allocations as items are added to the dictionary by specifying the capacity
- Avoids looking up the key twice by using
TryGetValue - Avoids manual lazy initialization
- Allows
s_cultureInfoNameMapto bereadonly
private static class CultureInfoMapper
{
// Dictionary of CultureInfo.DisplayName, CultureInfo.Name for cultures that have changed DisplayName over releases.
// This is to workaround an issue with CultureInfoConverter that serializes DisplayName (fixing it would introduce breaking changes).
private static readonly Dictionary<string, string> s_cultureInfoNameMap = CreateMap();
private static Dictionary<string, string> CreateMap()
{
const int Count = 274;
var result = new Dictionary<string, string>(Count)
{
{ "Afrikaans", "af" },
...
};
Debug.Assert(result.Count == Count);
return result;
}
public static string GetCultureInfoName(string cultureInfoDisplayName)
{
string name;
return s_cultureInfoNameMap.TryGetValue(cultureInfoDisplayName, out name) ?
name :
cultureInfoDisplayName;
}
}|
@justinvp Thanks for taking a look at this PR! |
stephentoub
left a comment
There was a problem hiding this comment.
I skimmed through and left a bunch of comments. Many are nits and can be addressed as a cleanup if you like. Some are a bit more concerning, e.g .why BackgroundWorker is in here. Overall, good job.
| { | ||
| return true; | ||
| } | ||
| } |
There was a problem hiding this comment.
Nit: you could make members like this more concise if you wanted to with expression-bodied members, e.g.
protected virtual bool CanRaiseEvents => true;| public class Component : /*TODO NETSTANDARD2.0 MarshalByRefObject, */IComponent | ||
| { | ||
| /// <summary> | ||
| /// <para>Static hask key for the Disposed event. This field is read-only.</para> |
There was a problem hiding this comment.
Could the <para> tags be removed?
There was a problem hiding this comment.
They could -- it looks like we were not consistent across this repo ... so we have other places with these tags.
I will capture these in a code-clean-up issue.
| { | ||
| get { return _site; } | ||
| set { _site = value; } | ||
| } |
There was a problem hiding this comment.
Nit: could just be:
public virtual ISite Site { get; set; }I'll only comment on each such pattern once; I'm sure there are other such cases later on.
| if (_events != null) | ||
| { | ||
| EventHandler handler = (EventHandler)_events[s_eventDisposed]; | ||
| if (handler != null) handler(this, EventArgs.Empty); |
There was a problem hiding this comment.
Nit: With C# 6, this pattern can now be simplified to just:
((EventHandler)_events[s_eventDisposed])?.Invoke(this, EventArgs.Empty);| { | ||
| ISite s = _site; | ||
| return s == null ? null : s.Container; | ||
| } |
There was a problem hiding this comment.
Nit: Could be simplified with ?.
public IContainer Container => _site?.Container;| { | ||
| string[] segments = licenseFile.Segments; | ||
| string licFileName = segments[segments.Length - 1]; | ||
| string key = licFileName.Substring(0, licFileName.LastIndexOf(".")); |
There was a problem hiding this comment.
What if there's no period in licFileName?
| try | ||
| { | ||
| WebClient webClient = new WebClient(); | ||
| webClient.Credentials = CredentialCache.DefaultCredentials; |
There was a problem hiding this comment.
We should test this and make sure it behaves as expected (e.g. the credentials are a nop) on Unix.
| [System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Name = "FullTrust")] | ||
| public sealed class ContextStack | ||
| { | ||
| private ArrayList _contextStack; |
There was a problem hiding this comment.
Same general question as earlier about replacing the non-generic collections with generic ones wherever possible.
| @@ -0,0 +1,70 @@ | |||
| D:\code\gitHub\alexghiondea\corefx\src\System.ComponentModel.TypeConverter\src\System\ComponentModel\ArrayConverter.cs | |||
There was a problem hiding this comment.
What is this file that has your username in it?
There was a problem hiding this comment.
Accidentally checked that in. Removed.
| { | ||
| internal const string SystemDrawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; | ||
| internal const string SystemDesign = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; | ||
| } No newline at end of file |
There was a problem hiding this comment.
What are these used for? These assemblies don't exist in core.
There was a problem hiding this comment.
Removed them from here. they are used inside DesignerAttribute and EditorAttributes. I moved the string literals directly there. We might want to remove them completely.
| @@ -0,0 +1,13 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
There was a problem hiding this comment.
We no longer need depprojs'.
| "dotnet5.8" | ||
| ] | ||
| }, | ||
| "netstandard1.0": |
There was a problem hiding this comment.
netstandard1.0 section is no longer needed.
weshaggard
left a comment
There was a problem hiding this comment.
Still lots of clean-up to do here.
| "System.Resources.ResourceManager": "4.0.0" | ||
| }, | ||
| "imports": [ | ||
| "dotnet5.1" |
| <Project Include="System.ComponentModel.Primitives.csproj"> | ||
| <TargetGroup>net45</TargetGroup> | ||
| </Project> | ||
| <Project Include="System.ComponentModel.Primitives.csproj"> |
There was a problem hiding this comment.
YOu can remove all the builds from here except for the default and the net463 build.
| <AssemblyName>System.ComponentModel.Primitives</AssemblyName> | ||
| <IsPartialFacadeAssembly Condition="'$(TargetGroup)'=='net45'">true</IsPartialFacadeAssembly> | ||
| <NuGetTargetMoniker Condition="'$(TargetGroup)' == ''">.NETStandard,Version=v1.0</NuGetTargetMoniker> | ||
| <AssemblyVersion Condition="'$(TargetGroup)'=='net45' or '$(TargetGroup)'=='netstandard1.0'">4.1.1.0</AssemblyVersion> |
There was a problem hiding this comment.
net45 can be removed from this project.
|
|
||
| #if !netstandard17 | ||
| private ComponentCollection() { } | ||
| #else |
There was a problem hiding this comment.
Do we even need the #ifdefs? I would just eliminate the netstandard1.0 builds.
| /// Creates a new event handler list. The parent component is used to check the component's | ||
| /// CanRaiseEvents property. | ||
| /// </summary> | ||
| [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] |
There was a problem hiding this comment.
looks like no because it is related to security demands which we don't have.
| "dotnet5.8" | ||
| ] | ||
| }, | ||
| "netstandard1.0": { |
There was a problem hiding this comment.
remove net45 and netstandard1.0
There was a problem hiding this comment.
please do remove these dead configurations from here otherwise we do more package restoring for no reason.
| public override System.ComponentModel.PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributes) { throw null; } | ||
| public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { throw null; } | ||
| } | ||
| public partial class Component : System.IDisposable |
There was a problem hiding this comment.
You need to leave a type-forward behind.
There was a problem hiding this comment.
I will add it as a manual type-forward to S.CM.P
|
|
||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
👎 we should fix them even if the codeformatter doesn't.
| <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> | ||
| <ItemGroup> | ||
| <ProjectReference Include="..\ref\4.1.0\System.ComponentModel.Primitives.depproj"> |
There was a problem hiding this comment.
Can you please have a read over my document that talks about how to version these libraries and make the necessary updates and/or leave comments on my PR (#12036) about followup questions.
ac8e806 to
e2ffe37
Compare
|
@dotnet-bot test this please |
| } | ||
| public partial class ComponentCollection | ||
| [System.ComponentModel.DesignerCategoryAttribute("Component")] | ||
| public partial class Component : /*TODO NETSTANDARD2.0 System.MarshalByRefObject,*/ System.ComponentModel.IComponent, System.IDisposable |
There was a problem hiding this comment.
Please make sure we have an issue tracking these MarshalByRefObject TODOs.
There was a problem hiding this comment.
There are a few follow-ups and they are all captured in issue #12212
| "netstandard1.7": { | ||
| "dependencies": | ||
| { | ||
| "System.Runtime": "4.3.0-beta-24522-03", |
There was a problem hiding this comment.
I really hope System.ComponentModel.Primitives doesn't actually depend on all these packages. Certainly the ref doesn't. Please trim this to the exact set of references that show up in the assembly reference table of the built binary.
| <ItemGroup Condition="'$(TargetGroup)'==''"> | ||
| <Compile Include="System\ComponentModel\Component.cs" /> | ||
| </ItemGroup> | ||
| <ItemGroup Condition="'$(TargetGroup)'=='net45' or '$(TargetGroup)'=='net463'"> |
There was a problem hiding this comment.
net45 condition isn't needed.
| namespace System.ComponentModel | ||
| { | ||
| public class ComponentCollection | ||
| using System.Collections; |
There was a problem hiding this comment.
using statements should be outside of namespaces.
| "System.Diagnostics.Tools": "4.3.0-beta-24522-03", | ||
| "System.Resources.ResourceManager": "4.3.0-beta-24522-03", | ||
| "System.Runtime": "4.3.0-beta-24522-03", | ||
| "System.Threading": "4.0.0" |
There was a problem hiding this comment.
Bump System.Threading package version up to the latest 4.3.0-beta-* version as well, otherwise you will be seeing downgrade warnings.
| "System.Threading": "4.0.0" | ||
| }, | ||
| "imports": [ | ||
| "dotnet5.8" |
| // ------------------------------------------------------------------------------ | ||
| // Changes to this file must follow the http://aka.ms/api-review process. | ||
| // ------------------------------------------------------------------------------ | ||
|
|
There was a problem hiding this comment.
most projects have just been putting these in the main .cs file instead of a separate .Forwards file.
There was a problem hiding this comment.
Moved into the main file.
| public override bool Equals(object obj) { throw null; } | ||
| public override int GetHashCode() { throw null; } | ||
| } | ||
| // [System.ComponentModel.DefaultEventAttribute("DoWork")] |
There was a problem hiding this comment.
We should remove these instead of commenting them out.
There was a problem hiding this comment.
Thought I got all of them but missed this one. Gone now.
| public System.ComponentModel.InheritanceLevel InheritanceLevel { get { throw null; } } | ||
| public override bool Equals(object value) { throw null; } | ||
| public override int GetHashCode() { throw null; } | ||
| //TODO NETSTANDARD2.0 - expose IsDefaultAttribute on Attribute public override bool IsDefaultAttribute() { throw null; } |
There was a problem hiding this comment.
Ensure we have a follow-up item for this.
| { | ||
| "dependencies": { | ||
| "System.Collections.NonGeneric": "4.3.0-beta-24522-03", | ||
| "System.Collections.Specialized": "4.3.0-beta-24522-03", |
There was a problem hiding this comment.
Please trim this to the exact set that is needed. I really hope we don't need things like System.Security.Permissions for example.
| <value>The object used to marshal the event handler calls issued when an interval has elapsed.</value> | ||
| </data> | ||
|
|
||
| <!-- To be moved --> |
There was a problem hiding this comment.
uhm.. here? Removed the comment
| using System.ComponentModel; | ||
| using System.Reflection; | ||
|
|
||
| namespace System |
There was a problem hiding this comment.
Ensure we have a follow-up item for removing all these stubs.
|
|
||
| namespace System.Resources | ||
| { | ||
| public partial interface IResourceReader : System.Collections.IEnumerable, System.IDisposable |
There was a problem hiding this comment.
@alexperovich be aware this is going to cause conflicts with your resource work.
There was a problem hiding this comment.
Why does this need to be here? Can it not just reference System.Resources.Reader?
There was a problem hiding this comment.
If that is available, it should absolutely reference that!
| "System.IO": "4.3.0-beta-24522-03", | ||
| "System.IO.FileSystem": "4.3.0-beta-24522-03", | ||
| "System.Linq": "4.3.0-beta-24522-03", | ||
| "System.Net.WebClient": "4.3.0-beta-24522-03", |
There was a problem hiding this comment.
We should file a follow-up item about breaking this dependency on WebClient, especially if it is tied to the license stuff which we aren't likely to fully support anyway.
weshaggard
left a comment
There was a problem hiding this comment.
I've added a bunch of clean-up and follow-up comments but I don't see anything that is actually broken. Please be sure to follow-up on the clean-up.
e2ffe37 to
c86453e
Compare
This change allows types higher in the stack to use the type. The build is also adjusted to allow for building and testing against netstandard1.7
…tModel.TypeConverter.
c86453e to
09d2d1b
Compare
Port the majority of the System.ComponentModel APIs into the open Commit migrated from dotnet/corefx@f94dd87
This is the initial PR for this work.
What does this change contain:
There are a couple of things missing:
/cc @weshaggard @danmosemsft