You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
92
external/corefx/src/System.Composition/System.Composition.sln
vendored
Normal file
92
external/corefx/src/System.Composition/System.Composition.sln
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.23107.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Composition.TypedParts", "..\System.Composition.TypedParts\src\System.Composition.TypedParts.csproj", "{B4B5E15C-E6B9-48EA-94C2-F067484D4D3E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Composition.AttributedModel", "..\System.Composition.AttributedModel\src\System.Composition.AttributedModel.csproj", "{C6257381-C624-494A-A9D9-5586E60856EA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Composition.Hosting", "..\System.Composition.Hosting\src\System.Composition.Hosting.csproj", "{2B8FECC6-34A1-48FE-BA75-99572D2D6DB2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Composition.Runtime", "..\System.Composition.Runtime\src\System.Composition.Runtime.csproj", "{2711DFD2-8541-4628-BC53-EB784A14CDCF}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Composition.Convention", "..\System.Composition.Convention\src\System.Composition.Convention.csproj", "{E6592FAD-10B5-4B56-9287-D72DD136992F}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B99B3931-53D0-490B-B27D-7247715EA621}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{5996586D-AAD0-4D69-A96C-D81A3816AD0B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Composition.Convention.Tests", "..\System.Composition.Convention\tests\System.Composition.Convention.Tests.csproj", "{853BB14F-8A5B-42B4-A053-21DE1AEBB335}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Composition.Demos.ExtendedCollectionImports", "demos\Microsoft.Composition.Demos.ExtendedCollectionImports\Microsoft.Composition.Demos.ExtendedCollectionImports.csproj", "{44C7E52C-3873-4C64-875C-8A23A8376D60}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Composition.ThroughputHarness", "perftests\Microsoft.Composition.ThroughputHarness.csproj", "{E3E3DA53-B8AC-46B6-8AAB-EBF751A2D0C3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestLibrary", "scenarios\TestLibrary\TestLibrary.csproj", "{DA6841A5-0344-4CC7-98B0-89CBEE18DEE3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Composition.Tests", "tests\System.Composition.Tests.csproj", "{4852A19F-C05C-478D-BFA0-59FD03DE0E3F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{B4B5E15C-E6B9-48EA-94C2-F067484D4D3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B4B5E15C-E6B9-48EA-94C2-F067484D4D3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B4B5E15C-E6B9-48EA-94C2-F067484D4D3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B4B5E15C-E6B9-48EA-94C2-F067484D4D3E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C6257381-C624-494A-A9D9-5586E60856EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C6257381-C624-494A-A9D9-5586E60856EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C6257381-C624-494A-A9D9-5586E60856EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C6257381-C624-494A-A9D9-5586E60856EA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2B8FECC6-34A1-48FE-BA75-99572D2D6DB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2B8FECC6-34A1-48FE-BA75-99572D2D6DB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2B8FECC6-34A1-48FE-BA75-99572D2D6DB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2B8FECC6-34A1-48FE-BA75-99572D2D6DB2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2711DFD2-8541-4628-BC53-EB784A14CDCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2711DFD2-8541-4628-BC53-EB784A14CDCF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2711DFD2-8541-4628-BC53-EB784A14CDCF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2711DFD2-8541-4628-BC53-EB784A14CDCF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E6592FAD-10B5-4B56-9287-D72DD136992F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E6592FAD-10B5-4B56-9287-D72DD136992F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E6592FAD-10B5-4B56-9287-D72DD136992F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E6592FAD-10B5-4B56-9287-D72DD136992F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{853BB14F-8A5B-42B4-A053-21DE1AEBB335}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{853BB14F-8A5B-42B4-A053-21DE1AEBB335}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{853BB14F-8A5B-42B4-A053-21DE1AEBB335}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{853BB14F-8A5B-42B4-A053-21DE1AEBB335}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{44C7E52C-3873-4C64-875C-8A23A8376D60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{44C7E52C-3873-4C64-875C-8A23A8376D60}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{44C7E52C-3873-4C64-875C-8A23A8376D60}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{44C7E52C-3873-4C64-875C-8A23A8376D60}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E3E3DA53-B8AC-46B6-8AAB-EBF751A2D0C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E3E3DA53-B8AC-46B6-8AAB-EBF751A2D0C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E3E3DA53-B8AC-46B6-8AAB-EBF751A2D0C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E3E3DA53-B8AC-46B6-8AAB-EBF751A2D0C3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DA6841A5-0344-4CC7-98B0-89CBEE18DEE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DA6841A5-0344-4CC7-98B0-89CBEE18DEE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DA6841A5-0344-4CC7-98B0-89CBEE18DEE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DA6841A5-0344-4CC7-98B0-89CBEE18DEE3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4852A19F-C05C-478D-BFA0-59FD03DE0E3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4852A19F-C05C-478D-BFA0-59FD03DE0E3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4852A19F-C05C-478D-BFA0-59FD03DE0E3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4852A19F-C05C-478D-BFA0-59FD03DE0E3F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{B4B5E15C-E6B9-48EA-94C2-F067484D4D3E} = {B99B3931-53D0-490B-B27D-7247715EA621}
|
||||
{C6257381-C624-494A-A9D9-5586E60856EA} = {B99B3931-53D0-490B-B27D-7247715EA621}
|
||||
{2B8FECC6-34A1-48FE-BA75-99572D2D6DB2} = {B99B3931-53D0-490B-B27D-7247715EA621}
|
||||
{2711DFD2-8541-4628-BC53-EB784A14CDCF} = {B99B3931-53D0-490B-B27D-7247715EA621}
|
||||
{E6592FAD-10B5-4B56-9287-D72DD136992F} = {B99B3931-53D0-490B-B27D-7247715EA621}
|
||||
{853BB14F-8A5B-42B4-A053-21DE1AEBB335} = {5996586D-AAD0-4D69-A96C-D81A3816AD0B}
|
||||
{44C7E52C-3873-4C64-875C-8A23A8376D60} = {5996586D-AAD0-4D69-A96C-D81A3816AD0B}
|
||||
{E3E3DA53-B8AC-46B6-8AAB-EBF751A2D0C3} = {5996586D-AAD0-4D69-A96C-D81A3816AD0B}
|
||||
{DA6841A5-0344-4CC7-98B0-89CBEE18DEE3} = {5996586D-AAD0-4D69-A96C-D81A3816AD0B}
|
||||
{4852A19F-C05C-478D-BFA0-59FD03DE0E3F} = {5996586D-AAD0-4D69-A96C-D81A3816AD0B}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,5 @@
|
||||
// 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.
|
||||
|
||||
[assembly: System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAssembly]
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
netstandard1.3;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,99 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Composition.Hosting;
|
||||
using System.Composition.Hosting.Core;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.Composition.Demos.ExtendedCollectionImports.Util;
|
||||
|
||||
namespace Microsoft.Composition.Demos.ExtendedCollectionImports.Dictionaries
|
||||
{
|
||||
public class DictionaryExportDescriptorProvider : ExportDescriptorProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Identifies the metadata used as key for a dictionary import.
|
||||
/// </summary>
|
||||
private const string KeyByMetadataImportMetadataConstraintName = "KeyMetadataName";
|
||||
|
||||
private static readonly MethodInfo s_getDictionaryDefinitionsMethod = typeof(DictionaryExportDescriptorProvider).GetTypeInfo().GetDeclaredMethod("GetDictionaryDefinition");
|
||||
|
||||
public override IEnumerable<ExportDescriptorPromise> GetExportDescriptors(CompositionContract contract, DependencyAccessor descriptorAccessor)
|
||||
{
|
||||
if (!(contract.ContractType.IsConstructedGenericType && contract.ContractType.GetGenericTypeDefinition() == typeof(IDictionary<,>)))
|
||||
return NoExportDescriptors;
|
||||
|
||||
CompositionContract unwrapped;
|
||||
string keyByMetadataName;
|
||||
if (!contract.TryUnwrapMetadataConstraint(KeyByMetadataImportMetadataConstraintName, out keyByMetadataName, out unwrapped))
|
||||
return NoExportDescriptors;
|
||||
|
||||
var args = contract.ContractType.GenericTypeArguments;
|
||||
var keyType = args[0];
|
||||
var valueType = args[1];
|
||||
|
||||
var valueContract = unwrapped.ChangeType(valueType);
|
||||
|
||||
var gdd = s_getDictionaryDefinitionsMethod.MakeGenericMethod(keyType, valueType);
|
||||
|
||||
return new[] { (ExportDescriptorPromise)gdd.Invoke(null, new object[] { contract, valueContract, descriptorAccessor, keyByMetadataName }) };
|
||||
}
|
||||
|
||||
private static ExportDescriptorPromise GetDictionaryDefinition<TKey, TValue>(CompositionContract dictionaryContract, CompositionContract valueContract, DependencyAccessor definitionAccessor, string keyByMetadataName)
|
||||
{
|
||||
return new ExportDescriptorPromise(
|
||||
dictionaryContract,
|
||||
typeof(IDictionary<TKey, TValue>).Name,
|
||||
false,
|
||||
() => definitionAccessor.ResolveDependencies("value", valueContract, true),
|
||||
deps =>
|
||||
{
|
||||
var items = deps.Select(d => Tuple.Create(d.Target.Origin, d.Target.GetDescriptor())).ToArray();
|
||||
var isValidated = false;
|
||||
return ExportDescriptor.Create((c, o) =>
|
||||
{
|
||||
if (!isValidated)
|
||||
{
|
||||
Validate<TKey>(items, keyByMetadataName);
|
||||
isValidated = true;
|
||||
}
|
||||
|
||||
return items.ToDictionary(
|
||||
item => (TKey)item.Item2.Metadata[keyByMetadataName],
|
||||
item => (TValue)item.Item2.Activator(c, o));
|
||||
},
|
||||
NoMetadata);
|
||||
});
|
||||
}
|
||||
|
||||
private static void Validate<TKey>(Tuple<string, ExportDescriptor>[] partsWithMatchedDescriptors, string keyByMetadataName)
|
||||
{
|
||||
var missing = partsWithMatchedDescriptors.Where(p => !p.Item2.Metadata.ContainsKey(keyByMetadataName)).ToArray();
|
||||
if (missing.Length != 0)
|
||||
{
|
||||
var problems = Formatters.ReadableQuotedList(missing.Select(p => p.Item1));
|
||||
var message = string.Format("The metadata '{0}' cannot be used as a dictionary import key because it is missing from exports on part(s) {1}.", keyByMetadataName, problems);
|
||||
throw new CompositionFailedException(message);
|
||||
}
|
||||
|
||||
var wrongType = partsWithMatchedDescriptors.Where(p => !(p.Item2.Metadata[keyByMetadataName] is TKey)).ToArray();
|
||||
if (wrongType.Length != 0)
|
||||
{
|
||||
var problems = Formatters.ReadableQuotedList(wrongType.Select(p => p.Item1));
|
||||
var message = string.Format("The metadata '{0}' cannot be used as a dictionary import key of type '{1}' because the value(s) supplied by {2} are of the wrong type.", keyByMetadataName, typeof(TKey).Name, problems);
|
||||
throw new CompositionFailedException(message);
|
||||
}
|
||||
|
||||
var firstDuplicated = partsWithMatchedDescriptors.GroupBy(p => (TKey)p.Item2.Metadata[keyByMetadataName]).Where(g => g.Count() > 1).FirstOrDefault();
|
||||
if (firstDuplicated != null)
|
||||
{
|
||||
var problems = Formatters.ReadableQuotedList(firstDuplicated.Select(p => p.Item1));
|
||||
var message = string.Format("The metadata '{0}' cannot be used as a dictionary import key because the value '{1}' is associated with exports from parts {2}.", keyByMetadataName, firstDuplicated.Key, problems);
|
||||
throw new CompositionFailedException(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Composition;
|
||||
|
||||
namespace Microsoft.Composition.Demos.ExtendedCollectionImports
|
||||
{
|
||||
/// <summary>
|
||||
/// Used in conjunction with an import of type <see cref="IDictionary{TKey,TValue}"/>,
|
||||
/// specifies the metadata item associated with each value that will be used as the
|
||||
/// key within the dictionary.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// The exporters provide a metadata item, here "HandledState":
|
||||
/// <code>
|
||||
/// [Export(typeof(ModemStateImplementation)),
|
||||
/// ExportMetadata("HandledState", ModemState.On)]
|
||||
/// public class OnState : ModemStateImplementation
|
||||
/// {
|
||||
/// </code>
|
||||
/// The importer requests that its imports are keyed according to the same metadata item.
|
||||
/// <code>
|
||||
/// [ImportingConstructor]
|
||||
/// public Modem(
|
||||
/// [KeyByMetadata("HandledState")]
|
||||
/// IDictionary<ModemState, Lazy<ModemStateImplementation>> states)
|
||||
/// {
|
||||
/// </code>
|
||||
/// </example>
|
||||
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)]
|
||||
[MetadataAttribute]
|
||||
public sealed class KeyByMetadataAttribute : Attribute
|
||||
{
|
||||
private readonly string _metadataKey;
|
||||
|
||||
private const string KeyByMetadataImportMetadataConstraintName = "KeyMetadataName";
|
||||
|
||||
/// <summary>
|
||||
/// Construct a <see cref="KeyByMetadataAttribute"/> for the specified metadata name.
|
||||
/// </summary>
|
||||
/// <param name="keyMetadataName">The name of the metadata item to use as the key of the dictionary.</param>
|
||||
public KeyByMetadataAttribute(string keyMetadataName)
|
||||
{
|
||||
_metadataKey = keyMetadataName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The name of the metadata item to use as the key of the dictionary.
|
||||
/// </summary>
|
||||
public string KeyMetadataName { get { return _metadataKey; } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{44C7E52C-3873-4C64-875C-8A23A8376D60}</ProjectGuid>
|
||||
<NoWarn>0436</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard1.3-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard1.3-Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="Dictionaries\DictionaryExportDescriptorProvider.cs" />
|
||||
<Compile Include="Util\Formatters.cs" />
|
||||
<Compile Include="OrderedImportManyAttribute.cs" />
|
||||
<Compile Include="OrderedCollections\OrderedImportManyExportDescriptorProvider.cs" />
|
||||
<Compile Include="KeyByMetadataAttribute.cs" />
|
||||
<Compile Include="$(CommonPath)\System\Diagnostics\CodeAnalysis\ExcludeFromCodeCoverageAssemblyAttribute.cs">
|
||||
<Link>Common\System\Diagnostics\CodeAnalysis\ExcludeFromCodeCoverageAssemblyAttribute.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,79 @@
|
||||
// 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.
|
||||
|
||||
using System.Reflection;
|
||||
using System.Composition.Hosting.Core;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using Microsoft.Composition.Demos.ExtendedCollectionImports.Util;
|
||||
using System.Composition.Hosting;
|
||||
|
||||
namespace Microsoft.Composition.Demos.ExtendedCollectionImports.OrderedCollections
|
||||
{
|
||||
public class OrderedImportManyExportDescriptorProvider : ExportDescriptorProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Identifies the metadata used to order a "many" import.
|
||||
/// </summary>
|
||||
private const string OrderByMetadataImportMetadataConstraintName = "OrderMetadataName";
|
||||
|
||||
private static readonly MethodInfo s_getImportManyDefinitionMethod = typeof(OrderedImportManyExportDescriptorProvider).GetTypeInfo().GetDeclaredMethod("GetImportManyDescriptor");
|
||||
private static readonly Type[] s_supportedContractTypes = new[] { typeof(IList<>), typeof(ICollection<>), typeof(IEnumerable<>) };
|
||||
|
||||
public override IEnumerable<ExportDescriptorPromise> GetExportDescriptors(CompositionContract contract, DependencyAccessor definitionAccessor)
|
||||
{
|
||||
if (!(contract.ContractType.IsArray ||
|
||||
contract.ContractType.IsConstructedGenericType && s_supportedContractTypes.Contains(contract.ContractType.GetGenericTypeDefinition())))
|
||||
return NoExportDescriptors;
|
||||
|
||||
string keyToOrderBy;
|
||||
CompositionContract orderUnwrappedContract;
|
||||
if (!contract.TryUnwrapMetadataConstraint(OrderByMetadataImportMetadataConstraintName, out keyToOrderBy, out orderUnwrappedContract))
|
||||
return NoExportDescriptors;
|
||||
|
||||
var elementType = contract.ContractType.IsArray ?
|
||||
contract.ContractType.GetElementType() :
|
||||
contract.ContractType.GenericTypeArguments[0];
|
||||
|
||||
var elementContract = orderUnwrappedContract.ChangeType(elementType);
|
||||
|
||||
var gimd = s_getImportManyDefinitionMethod.MakeGenericMethod(elementType);
|
||||
|
||||
return new[] { (ExportDescriptorPromise)gimd.Invoke(null, new object[] { contract, elementContract, definitionAccessor, keyToOrderBy }) };
|
||||
}
|
||||
|
||||
private static ExportDescriptorPromise GetImportManyDescriptor<TElement>(CompositionContract importManyContract, CompositionContract elementContract, DependencyAccessor definitionAccessor, string keyToOrderBy)
|
||||
{
|
||||
return new ExportDescriptorPromise(
|
||||
importManyContract,
|
||||
typeof(TElement[]).Name,
|
||||
false,
|
||||
() => definitionAccessor.ResolveDependencies("item", elementContract, true),
|
||||
d =>
|
||||
{
|
||||
var dependentDescriptors = (keyToOrderBy != null) ?
|
||||
OrderDependentDescriptors(d, keyToOrderBy) :
|
||||
d.Select(el => el.Target.GetDescriptor()).ToArray();
|
||||
|
||||
return ExportDescriptor.Create((c, o) => dependentDescriptors.Select(e => (TElement)e.Activator(c, o)).ToArray(), NoMetadata);
|
||||
});
|
||||
}
|
||||
|
||||
private static IEnumerable<ExportDescriptor> OrderDependentDescriptors(IEnumerable<CompositionDependency> dependentDescriptors, string keyToOrderBy)
|
||||
{
|
||||
var targets = dependentDescriptors.Select(d => d.Target).ToArray();
|
||||
var missing = targets.Where(t => !t.GetDescriptor().Metadata.ContainsKey(keyToOrderBy) ||
|
||||
t.GetDescriptor().Metadata[keyToOrderBy] == null).ToArray();
|
||||
if (missing.Length != 0)
|
||||
{
|
||||
var origins = Formatters.ReadableQuotedList(missing.Select(m => m.Origin));
|
||||
var message = string.Format("The metadata '{0}' cannot be used for ordering because it is missing from exports on part(s) {1}.", keyToOrderBy, origins);
|
||||
throw new CompositionFailedException(message);
|
||||
}
|
||||
|
||||
return targets.Select(t => t.GetDescriptor()).OrderBy(d => d.Metadata[keyToOrderBy]).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Composition;
|
||||
|
||||
namespace Microsoft.Composition.Demos.ExtendedCollectionImports
|
||||
{
|
||||
/// <summary>
|
||||
/// Used in conjunction with an ImportMany import,
|
||||
/// specifies the metadata item associated with each value that will be used to
|
||||
/// order the result.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)]
|
||||
[MetadataAttribute]
|
||||
public sealed class OrderedImportManyAttribute : ImportAttribute
|
||||
{
|
||||
private readonly string _metadataKey;
|
||||
|
||||
private const string OrderByMetadataImportMetadataConstraintName = "OrderMetadataName";
|
||||
|
||||
/// <summary>
|
||||
/// Construct a <see cref="OrderByMetadataAttribute"/> for the specified metadata name.
|
||||
/// </summary>
|
||||
/// <param name="orderMetadataName">The name of the metadata item to use to order the collection.</param>
|
||||
public OrderedImportManyAttribute(string orderMetadataName)
|
||||
{
|
||||
_metadataKey = orderMetadataName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The name of the metadata item to use as the key of the dictionary.
|
||||
/// </summary>
|
||||
public string OrderMetadataName { get { return _metadataKey; } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.Composition.Demos.ExtendedCollectionImports.Util
|
||||
{
|
||||
internal static class Formatters
|
||||
{
|
||||
public static string Format(object value)
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException(nameof(value));
|
||||
|
||||
if (value is string)
|
||||
return "\"" + value + "\"";
|
||||
|
||||
return value.ToString();
|
||||
}
|
||||
|
||||
public static string ReadableQuotedList(IEnumerable<string> items)
|
||||
{
|
||||
return ReadableList(items.Select(i => "'" + i + "'"));
|
||||
}
|
||||
|
||||
public static string ReadableList(IEnumerable<string> items)
|
||||
{
|
||||
var itemArray = items.ToArray();
|
||||
if (itemArray.Length == 0)
|
||||
return "<none>";
|
||||
|
||||
if (itemArray.Length == 1)
|
||||
return itemArray[0];
|
||||
|
||||
var ordered = itemArray.OrderByDescending(t => t).ToArray();
|
||||
var commaSeparated = ordered.Skip(1).Reverse();
|
||||
var last = ordered.First();
|
||||
return string.Join(", ", commaSeparated) + " and " + last;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
external/corefx/src/System.Composition/dir.props
vendored
Normal file
8
external/corefx/src/System.Composition/dir.props
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\dir.props" />
|
||||
<PropertyGroup>
|
||||
<PackageVersion>1.1.0</PackageVersion>
|
||||
<AssemblyVersion>1.0.32.0</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
||||
6
external/corefx/src/System.Composition/perftests/App.config
vendored
Normal file
6
external/corefx/src/System.Composition/perftests/App.config
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
20
external/corefx/src/System.Composition/perftests/Benchmark.cs
vendored
Normal file
20
external/corefx/src/System.Composition/perftests/Benchmark.cs
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CompositionThroughput
|
||||
{
|
||||
internal abstract class Benchmark
|
||||
{
|
||||
public abstract Action GetOperation();
|
||||
public abstract bool SelfTest();
|
||||
public virtual string Description { get { return GetType().Name.Replace("Benchmark", ""); } }
|
||||
public virtual Version Version { get { return new Version(0, 0); } }
|
||||
}
|
||||
}
|
||||
30
external/corefx/src/System.Composition/perftests/ControlBenchmark.cs
vendored
Normal file
30
external/corefx/src/System.Composition/perftests/ControlBenchmark.cs
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CompositionThroughput
|
||||
{
|
||||
internal class ControlBenchmark : Benchmark
|
||||
{
|
||||
public override Action GetOperation()
|
||||
{
|
||||
return () => { };
|
||||
}
|
||||
|
||||
public override string Description
|
||||
{
|
||||
get { return "Control (Empty)"; }
|
||||
}
|
||||
|
||||
public override bool SelfTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
34
external/corefx/src/System.Composition/perftests/FiftyPerSecondTestBenchmark.cs
vendored
Normal file
34
external/corefx/src/System.Composition/perftests/FiftyPerSecondTestBenchmark.cs
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CompositionThroughput
|
||||
{
|
||||
internal class FiftyPerSecondTestBenchmark : Benchmark
|
||||
{
|
||||
public override bool SelfTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Timing test 50/s";
|
||||
}
|
||||
}
|
||||
|
||||
public override Action GetOperation()
|
||||
{
|
||||
return () => Thread.Sleep(1000 / 50);
|
||||
}
|
||||
}
|
||||
}
|
||||
1
external/corefx/src/System.Composition/perftests/HugeGraph4Scenario.cs.REMOVED.git-id
vendored
Normal file
1
external/corefx/src/System.Composition/perftests/HugeGraph4Scenario.cs.REMOVED.git-id
vendored
Normal file
@@ -0,0 +1 @@
|
||||
77455645faaf00d59bee5f8b1c00ffc89aef393e
|
||||
91
external/corefx/src/System.Composition/perftests/HugeGraphBenchmark.cs
vendored
Normal file
91
external/corefx/src/System.Composition/perftests/HugeGraphBenchmark.cs
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Composition;
|
||||
using System.Composition.Hosting;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CompositionThroughput.HugeGraph;
|
||||
|
||||
namespace CompositionThroughput
|
||||
{
|
||||
internal abstract class HugeGraphBenchmark : Benchmark
|
||||
{
|
||||
public override bool SelfTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected IEnumerable<Type> GetHugeGraphTypes(Type example)
|
||||
{
|
||||
return example.GetTypeInfo().Assembly.DefinedTypes.Where(t => t.Namespace == example.Namespace).Select(ti => ti.AsType());
|
||||
}
|
||||
}
|
||||
|
||||
internal abstract class LightweightHugeGraphBenchmark : HugeGraphBenchmark
|
||||
{
|
||||
private ExportFactory<T> ConfigureContainer<T>()
|
||||
{
|
||||
return new ContainerConfiguration()
|
||||
.WithParts(GetHugeGraphTypes(typeof(T)))
|
||||
.CreateContainer()
|
||||
.GetExport<ExportFactory<T>>();
|
||||
}
|
||||
|
||||
protected Action GetOperationFor<T>()
|
||||
{
|
||||
var c = ConfigureContainer<T>();
|
||||
return () =>
|
||||
{
|
||||
var scope = c.CreateExport();
|
||||
var x = scope.Value;
|
||||
scope.Dispose();
|
||||
};
|
||||
}
|
||||
|
||||
public override Version Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return typeof(CompositionContext).GetTypeInfo().Assembly.GetName().Version;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class LightweightHugeGraphABenchmark : LightweightHugeGraphBenchmark
|
||||
{
|
||||
public override Action GetOperation()
|
||||
{
|
||||
return GetOperationFor<TestClassA1>();
|
||||
}
|
||||
}
|
||||
|
||||
internal class LightweightLongGraphBBenchmark : LightweightHugeGraphBenchmark
|
||||
{
|
||||
public override Action GetOperation()
|
||||
{
|
||||
return GetOperationFor<TestClassB1>();
|
||||
}
|
||||
}
|
||||
|
||||
internal class LightweightHugeGraphCBenchmark : LightweightHugeGraphBenchmark
|
||||
{
|
||||
public override Action GetOperation()
|
||||
{
|
||||
return GetOperationFor<TestClassC1>();
|
||||
}
|
||||
}
|
||||
|
||||
internal class LightweightHugeGraph4Benchmark : LightweightHugeGraphBenchmark
|
||||
{
|
||||
public override Action GetOperation()
|
||||
{
|
||||
return GetOperationFor<HugeGraph4.TestClassA1>();
|
||||
}
|
||||
}
|
||||
}
|
||||
1
external/corefx/src/System.Composition/perftests/HugeGraphScenario.cs.REMOVED.git-id
vendored
Normal file
1
external/corefx/src/System.Composition/perftests/HugeGraphScenario.cs.REMOVED.git-id
vendored
Normal file
@@ -0,0 +1 @@
|
||||
b6734048650a5c6293d48991669b25b97849ee2f
|
||||
31
external/corefx/src/System.Composition/perftests/Microsoft.Composition.ThroughputHarness.csproj
vendored
Normal file
31
external/corefx/src/System.Composition/perftests/Microsoft.Composition.ThroughputHarness.csproj
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{E3E3DA53-B8AC-46B6-8AAB-EBF751A2D0C3}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>CompositionThroughput</RootNamespace>
|
||||
<AssemblyName>CompositionThroughput</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
<Compile Include="Benchmark.cs" />
|
||||
<Compile Include="ControlBenchmark.cs" />
|
||||
<Compile Include="FiftyPerSecondTestBenchmark.cs" />
|
||||
<Compile Include="HugeGraphBenchmark.cs" />
|
||||
<Compile Include="HugeGraphScenario.cs" />
|
||||
<Compile Include="ShootoutWithNewBenchmark.cs" />
|
||||
<Compile Include="HugeGraph4Scenario.cs" />
|
||||
<Compile Include="Suite.cs" />
|
||||
<Compile Include="WebBenchmarks.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="WebBenchmarkScenario.cs" />
|
||||
<Compile Include="ThroughputHarness.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
154
external/corefx/src/System.Composition/perftests/Program.cs
vendored
Normal file
154
external/corefx/src/System.Composition/perftests/Program.cs
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CompositionThroughput
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
//SerialRunForPeformanceAnalysis(new LightweightWebBenchmark());
|
||||
//return;
|
||||
|
||||
Console.WriteLine("Composition Throughput Benchmarks");
|
||||
Console.WriteLine("=================================");
|
||||
Console.Write(" ");
|
||||
WriteResultRow("Benchmark", "Version", "Serial", "Parallel", "Delta", "Start");
|
||||
|
||||
var suites = new[] {
|
||||
new Suite("Selftest", 30, new Benchmark[] {
|
||||
new FiftyPerSecondTestBenchmark()
|
||||
}),
|
||||
new Suite("Shootout with New", 20000000, new Benchmark[] {
|
||||
new LightweightNewBenchmark(),
|
||||
new LightweightNLNewBenchmark(),
|
||||
new OperatorNewBenchmark()
|
||||
}),
|
||||
new Suite("Huge Graph", 200000, new Benchmark[] {
|
||||
new LightweightHugeGraphABenchmark(),
|
||||
new LightweightLongGraphBBenchmark(),
|
||||
new LightweightHugeGraphCBenchmark(),
|
||||
new LightweightHugeGraph4Benchmark()
|
||||
}),
|
||||
new Suite("Web", 200000, new Benchmark[] {
|
||||
new NativeCodeWebBenchmark(),
|
||||
new LightweightWebBenchmark()
|
||||
})
|
||||
};
|
||||
|
||||
foreach (var suite in suites)
|
||||
{
|
||||
RunSuite(suite);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Debug(Benchmark benchmark)
|
||||
{
|
||||
var op = benchmark.GetOperation();
|
||||
op();
|
||||
}
|
||||
|
||||
private static void SerialRunForPeformanceAnalysis(Benchmark benchmark)
|
||||
{
|
||||
var op = benchmark.GetOperation();
|
||||
bool keepGoing = true;
|
||||
var worker = new Thread(() =>
|
||||
{
|
||||
while (keepGoing)
|
||||
{
|
||||
op();
|
||||
}
|
||||
});
|
||||
|
||||
worker.Start();
|
||||
Thread.Sleep(60000); // Run for 1 minute
|
||||
keepGoing = false;
|
||||
worker.Join();
|
||||
}
|
||||
|
||||
private static void RunSuite(Suite suite)
|
||||
{
|
||||
Console.WriteLine("--- {0} - {1} operations ---", suite.Name, suite.StandardRunOperations);
|
||||
|
||||
var benchmarks = suite.IncludedBenchmarks.Concat(new[] { new ControlBenchmark() }).OrderBy(f => Guid.NewGuid()).ToArray();
|
||||
|
||||
var results = from f in benchmarks
|
||||
let op = f.GetOperation()
|
||||
select new
|
||||
{
|
||||
Framework = f,
|
||||
TestPass = f.SelfTest(),
|
||||
Startup = MeasureStartupMilliseconds(f),
|
||||
Serial = ThroughputHarness.MeasureOperationsPerSecond(op, suite.StandardRunOperations, false),
|
||||
Parallel = ThroughputHarness.MeasureOperationsPerSecond(op, suite.StandardRunOperations * Environment.ProcessorCount, true)
|
||||
};
|
||||
|
||||
foreach (var result in results)
|
||||
{
|
||||
WritePassFail(result.TestPass, result.Parallel != 0 && result.Serial != 0);
|
||||
WriteResultRow(result.Framework.Description,
|
||||
result.Framework.Version.ToString(),
|
||||
result.Serial,
|
||||
result.Parallel,
|
||||
((decimal)result.Parallel / result.Serial).ToString("#.00"),
|
||||
result.Startup);
|
||||
}
|
||||
}
|
||||
|
||||
private static long MeasureStartupMilliseconds(Benchmark benchmark)
|
||||
{
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
var op = benchmark.GetOperation();
|
||||
op();
|
||||
sw.Stop();
|
||||
return sw.ElapsedMilliseconds;
|
||||
}
|
||||
|
||||
private static void WritePassFail(bool passed, bool producedResult)
|
||||
{
|
||||
var c = ConsoleColor.Red;
|
||||
var ch = 'F';
|
||||
|
||||
if (passed)
|
||||
{
|
||||
if (producedResult)
|
||||
{
|
||||
c = ConsoleColor.Green;
|
||||
ch = 'P';
|
||||
}
|
||||
else
|
||||
{
|
||||
c = ConsoleColor.Yellow;
|
||||
ch = 'W';
|
||||
}
|
||||
}
|
||||
|
||||
Console.Write("[");
|
||||
Console.ForegroundColor = c;
|
||||
Console.Write(ch);
|
||||
Console.ResetColor();
|
||||
Console.Write("] ");
|
||||
}
|
||||
|
||||
private static void WriteResultRow(string description, string version, object s, object p, object delta, object startup)
|
||||
{
|
||||
Console.WriteLine("{0} | {1} | {2} | {3} | {4} | {5}",
|
||||
description.PadLeft(4).PadRight(21),
|
||||
version.PadRight(9),
|
||||
s.ToString().PadLeft(9),
|
||||
p.ToString().PadLeft(9),
|
||||
delta.ToString().PadLeft(5),
|
||||
startup.ToString().PadLeft(4));
|
||||
}
|
||||
}
|
||||
}
|
||||
84
external/corefx/src/System.Composition/perftests/ShootoutWithNewBenchmark.cs
vendored
Normal file
84
external/corefx/src/System.Composition/perftests/ShootoutWithNewBenchmark.cs
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Composition;
|
||||
using System.Composition.Hosting;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CompositionThroughput
|
||||
{
|
||||
[Export]
|
||||
public class X { }
|
||||
|
||||
[Export]
|
||||
public class XFactory
|
||||
{
|
||||
private readonly ExportFactory<X> _xfactory;
|
||||
|
||||
[ImportingConstructor]
|
||||
public XFactory(ExportFactory<X> xfactory)
|
||||
{
|
||||
_xfactory = xfactory;
|
||||
}
|
||||
|
||||
public Export<X> CreateX()
|
||||
{
|
||||
return _xfactory.CreateExport();
|
||||
}
|
||||
}
|
||||
|
||||
internal abstract class ShootoutWithNewBenchmark : Benchmark
|
||||
{
|
||||
public override bool SelfTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
internal class OperatorNewBenchmark : ShootoutWithNewBenchmark
|
||||
{
|
||||
public override Action GetOperation()
|
||||
{
|
||||
return () => new X();
|
||||
}
|
||||
}
|
||||
|
||||
internal class LightweightNewBenchmark : ShootoutWithNewBenchmark
|
||||
{
|
||||
public override Action GetOperation()
|
||||
{
|
||||
var c = new ContainerConfiguration()
|
||||
.WithPart(typeof(X))
|
||||
.WithPart(typeof(XFactory))
|
||||
.CreateContainer();
|
||||
|
||||
var xf = c.GetExport<XFactory>();
|
||||
return () =>
|
||||
{
|
||||
var x = xf.CreateX();
|
||||
var unused = x.Value;
|
||||
x.Dispose();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
internal class LightweightNLNewBenchmark : ShootoutWithNewBenchmark
|
||||
{
|
||||
public override Action GetOperation()
|
||||
{
|
||||
var c = new ContainerConfiguration()
|
||||
.WithPart(typeof(X))
|
||||
.CreateContainer();
|
||||
|
||||
return () =>
|
||||
{
|
||||
c.GetExport<X>();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user