Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Adding System.ComponentModel.Composition #24921

Merged
merged 66 commits into from
Nov 10, 2017

Conversation

maryamariyan
Copy link
Member

Ports MEF1 sources

cc: @danmosemsft @safern

@maryamariyan maryamariyan changed the title Adding System.ComponentModel.Composition APIs Adding System.ComponentModel.Composition Oct 27, 2017
@danmoseley
Copy link
Member

@@ -0,0 +1,43 @@
// -----------------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

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

Please replace all these headers with the usual 3 line license comment in all cs and resx files.

field.SetValue(instance, value);
}

#if FEATURE_CAS_APTCA
Copy link
Member

Choose a reason for hiding this comment

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

Delete all blocks with this define. We will never define it.

Copy link
Member

Choose a reason for hiding this comment

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

and retain code in the #else obviously

Copy link
Member

Choose a reason for hiding this comment

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

Well, you might be able to delete that too, if it's not publicly exposed

Copy link
Member

Choose a reason for hiding this comment

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

Confirmed, delete these and calls to them:

        public static void DemandMemberAccessIfNeeded(MethodInfo method) { }
 +        private static void DemandMemberAccessIfNeeded(ConstructorInfo constructor) { }
 +        private static void DemandMemberAccessIfNeeded(FieldInfo field) { }
 +        public static void DemandMemberAccessIfNeeded(Type type) { }


public SerializableCompositionElement(string displayName, ICompositionElement origin)
{
#if FEATURE_SERIALIZATION
Copy link
Member

Choose a reason for hiding this comment

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

We don't need FEATURE_SERIALIZATION blocks except as needed for serializing exceptions (so, keep any in exceptions, delete the rest, and see if that compiles)
Suggest you do this as a follow up PR as it needs tests also.

#endif //FEATURE_REFLECTIONCONTEXT && FEATURE_REFLECTIONFILEIO


//#if FEATURE_REFLECTIONFILEIO
Copy link
Member

Choose a reason for hiding this comment

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

All these commented out defines can be removed (retaining the content) ie search for ^//#.*\n

@danmoseley
Copy link
Member

Not sure what to do with these

#if FEATURE_REFLECTIONONLY
#if FEATURE_REFLECTIONCONTEXT

ask @weshaggard whether we should keep the code and drop the define, or drop the code and the define. Either way we don't need the define...

@danmoseley
Copy link
Member

  • @safern just for the configurations, but taht could be a follow up change.

@danmoseley
Copy link
Member

danmoseley commented Oct 27, 2017

You can remove all [SuppressMessage("Microsoft.Contracts",... and using System.Diagnostics.Contracts; as we don't use them. Also anything in the define CONTRACTS_FULL

@danmoseley
Copy link
Member

Ideally cases like this Requires.NotNull(element, "element"); would be Requires.NotNull(element, nameof(element)); .. some regular expression practice for you there

@danmoseley
Copy link
Member

Also ask Wes about #if !MEF_FEATURE_INITIALIZATION

{
internal sealed class Lock : IDisposable
{
#if (FEATURE_SLIMLOCK)
Copy link
Member

Choose a reason for hiding this comment

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

delete the #if and retain the code .. we have Slim locks.

Copy link
Member

Choose a reason for hiding this comment

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

so remove code in the #else

{
get { return _errors; }
}

Copy link
Member

Choose a reason for hiding this comment

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

nit, use regex to replace double blank lines with single

{
internal static class ContractNameServices
{
const char NamespaceSeparator = '.';
Copy link
Member

Choose a reason for hiding this comment

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

all fields should have access modifiers, please add private to these

namespace Microsoft.Internal
{
// This class contains utility methods that mimic the mscorlib internal System.Runtime.Versioning.BinaryCompatibility type.
internal sealed class BinaryCompatibility
Copy link
Member

Choose a reason for hiding this comment

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

Nit: source file name has a mispelling.


public static bool TargetsAtLeast_Desktop_V4_5 { get; private set; }

[SecuritySafeCritical]
Copy link
Member

Choose a reason for hiding this comment

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

Remove all SecuritySafeCritical annotations

public static bool TargetsAtLeast_Desktop_V4_5 { get; private set; }

[SecuritySafeCritical]
static string GetTargetFrameworkNameFromEntryAssembly()
Copy link
Member

Choose a reason for hiding this comment

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

missing 'private'

internal static class CompositionTraceSource
{
#if FEATURE_TRACING
private static readonly TraceSourceTraceWriter Source = new TraceSourceTraceWriter();
Copy link
Member

Choose a reason for hiding this comment

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

@weshaggard on .NET Core we have TraceSource so I assume we should flip this define so that TraceSourceTraceWriter is the default?

Or just delete DebuggerTraceWriter ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes we can flip to just TraceSource.

using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Reflection;

namespace Microsoft.Internal
{
internal static class Requires
internal static partial class Requires
{
[DebuggerStepThrough]
[ContractArgumentValidator]
Copy link
Member

Choose a reason for hiding this comment

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

You can remove all [ContractArgumentValidator] attributes as we don't use contracts. Keep the code though, unless it's dead.


namespace System.ComponentModel.Composition.ReflectionModel
{
// This
Copy link
Member

Choose a reason for hiding this comment

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

remove bad ocmment

@weshaggard
Copy link
Member

#if FEATURE_REFLECTIONONLY
#if FEATURE_REFLECTIONCONTEXT
ask @weshaggard whether we should keep the code and drop the define, or drop the code and the define. Either way we don't need the define...

While I don't think ReflectionOnly or ReflectionContext are super interesting they exist in .NET Standard 2.0 so I would just drop the defines and keep the code.

}

var frameworkName = new FrameworkName(targetFrameworkName);
TargetsAtLeast_Desktop_V4_5 = (frameworkName.Version >= BinaryCompatibility.Framework45);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this check even relevant on .NET Core?

Copy link
Member

Choose a reason for hiding this comment

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

Good catch yes this can surely be hard coded to 'true' and delete this file entirely.

<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netcoreapp2.0;
Copy link
Member

@safern safern Oct 28, 2017

Choose a reason for hiding this comment

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

Please move netcoreapp2.0 into a PackageConfiguration and then include that property into the build configurations. Also into BuildConfigurations we need to add netcoreapp for the vertical build from source.

I will look something like:

<PropertyGroup>
  <PackageConfigurations>
     netcoreapp2.0;
  </PackageConfigurations>
  <BuildConfigurations>
     $(PackageConfigurations);
     netcoreapp;
     uap;
  </BuildConfigurations>
</PropertyGroup>

This way its easier to understand why we have netcoreapp2.0 there.

}

public int Count
{
Copy link
Member

Choose a reason for hiding this comment

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

Nit => all this can be made one liner methods, since they only have a getter it would look much cleaner. Something like:

public int Count => return Assumes.NotReachable<int>();

However I think @danmosemsft mentioned something about "Assumes" so first go through that feedback.


public static IEnumerable<T> ConcatAllowingNull<T>(this IEnumerable<T> source, IEnumerable<T> second)
{
if (second == null || !second.FastAny())
Copy link
Member

Choose a reason for hiding this comment

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

All this ifs can be simplified to !second?.FastAny() maybe in another pass as we want to have the compat package soon.

{
case 0:
return EnumerableCardinality.Zero;

Copy link
Member

Choose a reason for hiding this comment

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

nit: extra lines in between cases.

@safern
Copy link
Member

safern commented Nov 7, 2017

Netfx failure is hitting: https://github.com/dotnet/corefx/issues/24903 we should disable those tests with ActiveIssue for netfx.

@safern
Copy link
Member

safern commented Nov 8, 2017

There are more projects with netfx tests that you need to disable:

15:23:03 D:\j\workspace\windows-TGrou---2a8f9c29\Tools\tests.targets(484,5): warning :    System.Composition.Tests  Total: 137, Errors: 0, Failed: 124, Skipped: 0, Time: 0.750s [D:\j\workspace\windows-TGrou---2a8f9c29\src\System.Composition\tests\System.Composition.Tests.csproj]
15:23:03 D:\j\workspace\windows-TGrou---2a8f9c29\Tools\tests.targets(484,5): warning MSB3073: The command "D:\j\workspace\windows-TGrou---2a8f9c29\bin/tests/System.Composition.Tests/netfx-Windows_NT-Release-x86//RunTests.cmd D:\j\workspace\windows-TGrou---2a8f9c29\bin/testhost/netfx-Windows_NT-Release-x86/" exited with code 1. [D:\j\workspace\windows-TGrou---2a8f9c29\src\System.Composition\tests\System.Composition.Tests.csproj]
15:23:03 D:\j\workspace\windows-TGrou---2a8f9c29\Tools\tests.targets(484,5): warning :    System.Composition.Hosting.Tests  Total: 76, Errors: 0, Failed: 30, Skipped: 0, Time: 0.776s [D:\j\workspace\windows-TGrou---2a8f9c29\src\System.Composition.Hosting\tests\System.Composition.Hosting.Tests.csproj]
15:23:03 D:\j\workspace\windows-TGrou---2a8f9c29\Tools\tests.targets(484,5): warning MSB3073: The command "D:\j\workspace\windows-TGrou---2a8f9c29\bin/tests/System.Composition.Hosting.Tests/netfx-Windows_NT-Release-x86//RunTests.cmd D:\j\workspace\windows-TGrou---2a8f9c29\bin/testhost/netfx-Windows_NT-Release-x86/" exited with code 1. [D:\j\workspace\windows-TGrou---2a8f9c29\src\System.Composition.Hosting\tests\System.Composition.Hosting.Tests.csproj]
15:23:03 D:\j\workspace\windows-TGrou---2a8f9c29\Tools\tests.targets(484,5): warning :    System.Runtime.Tests  Total: 11717, Errors: 0, Failed: 10, Skipped: 0, Time: 15.954s [D:\j\workspace\windows-TGrou---2a8f9c29\src\System.Runtime\tests\System.Runtime.Tests.csproj]
15:23:03 D:\j\workspace\windows-TGrou---2a8f9c29\Tools\tests.targets(484,5): warning MSB3073: The command "D:\j\workspace\windows-TGrou---2a8f9c29\bin/tests/System.Runtime.Tests/netfx-Windows_NT-Release-x86//RunTests.cmd D:\j\workspace\windows-TGrou---2a8f9c29\bin/testhost/netfx-Windows_NT-Release-x86/" exited with code 1. [D:\j\workspace\windows-TGrou---2a8f9c29\src\System.Runtime\tests\System.Runtime.Tests.csproj]
15:23:03 D:\j\workspace\windows-TGrou---2a8f9c29\Tools\tests.targets(492,5): error : One or more tests failed while running tests from 'System.Composition.Tests' please check D:\j\workspace\windows-TGrou---2a8f9c29\bin/tests/System.Composition.Tests/netfx-Windows_NT-Release-x86/testResults.xml for details! [D:\j\workspace\windows-TGrou---2a8f9c29\src\System.Composition\tests\System.Composition.Tests.csproj]
15:23:03 D:\j\workspace\windows-TGrou---2a8f9c29\Tools\tests.targets(492,5): error : One or more tests failed while running tests from 'System.Composition.Hosting.Tests' please check D:\j\workspace\windows-TGrou---2a8f9c29\bin/tests/System.Composition.Hosting.Tests/netfx-Windows_NT-Release-x86/testResults.xml for details! [D:\j\workspace\windows-TGrou---2a8f9c29\src\System.Composition.Hosting\tests\System.Composition.Hosting.Tests.csproj]
15:23:03 D:\j\workspace\windows-TGrou---2a8f9c29\Tools\tests.targets(492,5): error : One or more tests failed while running tests from 'System.Runtime.Tests' please check D:\j\workspace\windows-TGrou---2a8f9c29\bin/tests/System.Runtime.Tests/netfx-Windows_NT-Release-x86/testResults.xml for details! [D:\j\workspace\windows-TGrou---2a8f9c29\src\System.Runtime\tests\System.Runtime.Tests.csproj]

@maryamariyan
Copy link
Member Author

@dotnet/dnceng my PR build is succeeding but build is failing afterwards

@mmitche
Copy link
Member

mmitche commented Nov 9, 2017

@donet-bot test this please


}

private static List<T> FastAppendToListAllowNulls<T>(
Copy link
Member

Choose a reason for hiding this comment

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

nit: indention.

}
}

private static void LoadNull(this ILGenerator ilGenerator)
Copy link
Member

Choose a reason for hiding this comment

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

indention.

private static void LoadInt(this ILGenerator ilGenerator, int value)
{
Assumes.NotNull(ilGenerator);
ilGenerator.Emit(OpCodes.Ldc_I4, value);
Copy link
Member

Choose a reason for hiding this comment

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

indention.

}
}

public static IEnumerable<FieldInfo> GetAllFields(this Type type)
Copy link
Member

Choose a reason for hiding this comment

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

indention.

<BuildConfigurations>
netcoreapp;
uap;
</BuildConfigurations>
Copy link
Member

Choose a reason for hiding this comment

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

I assume we plan to enable netfx testing at some point? Do we have a tracking issue for that?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it will be as part of: https://github.com/dotnet/corefx/issues/24903 as that is why we can't add netfx testing because we're testing against the netstandard turd assembly.

Copy link
Member

@weshaggard weshaggard left a comment

Choose a reason for hiding this comment

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

A few minor clean-up comments, but otherwise looks good.

Thanks the work in porting this @maryamariyan

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp2.0-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp2.0-Release|AnyCPU'" />
Copy link
Member

Choose a reason for hiding this comment

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

Could you add the netstandard configuration in the csproj as well? This for VS to understand the build configurations.

Copy link
Member

@safern safern left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @maryamariyan

@maryamariyan maryamariyan merged commit 6bac408 into dotnet:master Nov 10, 2017
@maryamariyan maryamariyan deleted the port.mef1.src-ref branch March 6, 2018 00:51
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Adding System.ComponentModel.Composition

- Ports MEF1 sources
- Removes extra lines
- Removes all [ContractArgumentValidator] attributes
- Replaces old header formats with the usual 3 line license comment in all cs and resx files
- Removing code block on true condition of FEATURE_CAS_APTCA
- Slight update to sln file
- Deleting calls to DemandMemberAccessIfNeeded apis
- Simplifies BinaryCompatibility class
- Changes Requires.NotNull(element, "element"); to Requires.NotNull(element, typeof(element));
- Removes commented out ifdefs and removing suppressmessage Microsoft.Contracts
- Adding private access modifier to unspecified consts and other missing fields
- Fixing configuration for netcoreapp
- Defines constant FEATURE_TRACING
- Removes SecuritySafeCritical annotation
- Removes SLIM_LOCK
- Removes FEATURE_REFLECTIONONLY, keeping the code it wraps.
- Removes FEATURE_REFLECTIONCONTEXT, keeping the code it wraps.
- Removes code in the if block of CONTRACTS_FULL
- Removes the BinaryCompatibility class and the TargetsAtLeast_Desktop_V4_5 flag, since it is always true.
- Removes FEATURE_ADVANCEDREFLECTION, keeping the code it wraps.
- Removes MEF_FEATURE_INITIALIZATION, keeping the code it wraps
- Removes FEATURE_REFLECTIONFILEIO, keeping the code it wraps.
- Change the src project settings to not run apicompat
- Adding comment reasoning why we skipped apicompat. also adding netcoreapp config
- Updating configuration and removing ApiCompatBaseline file
- Update src project
- Simplifying Configurations.props files
- Removes blank line on csproj and adding Condition to not include compile items when not netstandard
- Removes S.CM.C netfx reference from netfxreference.props
- Removes index entry in packageIndex
- Suppress S.CM.C error
- Adds missing ApplicationCatalog. Removing ifdef conditions, Adding APIs to ref
- Code formatting for whitespaces on AssemblyCatalog.cs file
- Removes uap entry from the inbox list for this S.CM.C in packageindex.json
- Disable the tests in netfx which are hitting issue 24903
- Fixing tests in System.ComponentModel.Composition
- Formatting whitespace and indentation
- Removing this keyword
- Removing blank line between switch case lines
- Adding the netstandard configuration in the csproj for VS to understand the build configurations


Commit migrated from dotnet/corefx@6bac408
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants