<Compile Include="System\ComponentModel\Composition\Diagnostics\CompositionTrace.cs" />
<Compile Include="System\ComponentModel\Composition\Diagnostics\CompositionTraceId.cs" />
<Compile Include="System\ComponentModel\Composition\Diagnostics\CompositionTraceSource.cs" />
- <Compile Include="System\ComponentModel\Composition\Diagnostics\SilverlightTraceWriter.cs" />
+ <Compile Include="System\ComponentModel\Composition\Diagnostics\DebuggerTraceWriter.cs" />
<Compile Include="System\ComponentModel\Composition\Diagnostics\TraceWriter.cs" />
<Compile Include="System\ComponentModel\Composition\Hosting\AggregateCatalog.cs" />
<Compile Include="System\ComponentModel\Composition\Hosting\AggregateExportProvider.cs" />
<Link>Microsoft\Internal\Requires.cs</Link>
</Compile>
</ItemGroup>
- <ItemGroup>
+ <ItemGroup Condition="'$(TargetGroup)' != 'netstandard'">
<EmbeddedResource Include="$(CommonPath)\Microsoft\Internal\CommonStrings.resx">
<Link>Microsoft\Internal\CommonStrings.resx</Link>
<Generator>ResXFileCodeGenerator</Generator>
public AttributedPartCreationInfo(Type type, PartCreationPolicyAttribute partCreationPolicy, bool ignoreConstructorImports, ICompositionElement origin)
{
Assumes.NotNull(type);
-
+
_type = type;
_ignoreConstructorImports = ignoreConstructorImports;
_partCreationPolicy = partCreationPolicy;
return isArityMatched;
}
-string ICompositionElement.DisplayName
+ string ICompositionElement.DisplayName
{
get { return GetDisplayName(); }
}
{
foreach (ExportAttribute exportAttribute in member.GetAttributes<ExportAttribute>())
{
- var attributedExportDefinition = CreateExportDefinition(member, exportAttribute);
+ AttributedExportDefinition attributedExportDefinition = CreateExportDefinition(member, exportAttribute);
if (exportAttribute.GetType() == CompositionServices.InheritedExportAttributeType)
{
{
foreach (InheritedExportAttribute exportAttribute in type.GetAttributes<InheritedExportAttribute>())
{
- var attributedExportDefinition = CreateExportDefinition(type, exportAttribute);
+ AttributedExportDefinition attributedExportDefinition = CreateExportDefinition(type, exportAttribute);
if (!_contractNamesOnNonInterfaces.Contains(attributedExportDefinition.ContractName))
{
}
// Walk the fields
- foreach (var member in type.GetFields(flags))
+ foreach (FieldInfo member in type.GetFields(flags))
{
if (IsExport(member))
{
}
// Walk the properties
- foreach (var member in type.GetProperties(flags))
+ foreach (PropertyInfo member in type.GetProperties(flags))
{
if (IsExport(member))
{
}
// Walk the methods
- foreach (var member in type.GetMethods(flags))
+ foreach (MethodInfo member in type.GetMethods(flags))
{
if (IsExport(member))
{
{
yield break;
}
-
+
// Stopping at object instead of null to help with performance. It is a noticable performance
// gain (~5%) if we don't have to try and pull the attributes we know don't exist on object.
// We also need the null check in case we're passed a type that doesn't live in the runtime context.
imports.Add(importDefinition);
}
- var constructor = GetConstructor();
+ ConstructorInfo constructor = GetConstructor();
if (constructor != null)
{
BindingFlags flags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
// Walk the fields
- foreach (var member in type.GetFields(flags))
+ foreach (FieldInfo member in type.GetFields(flags))
{
if (IsImport(member))
{
}
// Walk the properties
- foreach (var member in type.GetProperties(flags))
+ foreach (PropertyInfo member in type.GetProperties(flags))
{
if (IsImport(member))
{
{
private readonly IEnumerable<CompositionError> _errors;
private readonly T _value;
-
+
public CompositionResult(T value)
- : this(value, (CompositionError[])null)
+ : this(value, null)
{
}
public CompositionResult(params CompositionError[] errors)
- : this(default(T), (IEnumerable<CompositionError>)errors)
+ : this(default, errors)
{
}
public CompositionResult(IEnumerable<CompositionError> errors)
- : this(default(T), errors)
+ : this(default, errors)
{
}
/// </summary>
public T Value
{
- get
+ get
{
ThrowOnErrors();
- return _value;
+ return _value;
}
}
if (CompositionTraceSource.CanWriteInformation)
{
- CompositionTraceSource.WriteInformation(CompositionTraceId.Rejection_DefinitionResurrected,
- SR.CompositionTrace_Rejection_DefinitionResurrected,
- definition.GetDisplayName());
+ CompositionTraceSource.WriteInformation(CompositionTraceId.Rejection_DefinitionResurrected,
+ SR.CompositionTrace_Rejection_DefinitionResurrected,
+ definition.GetDisplayName());
}
}
if (CompositionTraceSource.CanWriteWarning)
{
- CompositionTraceSource.WriteWarning(CompositionTraceId.Rejection_DefinitionRejected,
- SR.CompositionTrace_Rejection_DefinitionRejected,
- definition.GetDisplayName(),
- exception.Message);
+ CompositionTraceSource.WriteWarning(CompositionTraceId.Rejection_DefinitionRejected,
+ SR.CompositionTrace_Rejection_DefinitionRejected,
+ definition.GetDisplayName(),
+ exception.Message);
}
}
internal static void AssemblyLoadFailed(DirectoryCatalog catalog, string fileName, Exception exception)
{
Assumes.NotNull(catalog, exception);
- Assumes.NotNullOrEmpty(fileName);
+ Assumes.NotNullOrEmpty(fileName);
if (CompositionTraceSource.CanWriteWarning)
{
- CompositionTraceSource.WriteWarning(CompositionTraceId.Discovery_AssemblyLoadFailed,
- SR.CompositionTrace_Discovery_AssemblyLoadFailed,
- catalog.GetDisplayName(),
- fileName,
- exception.Message);
+ CompositionTraceSource.WriteWarning(CompositionTraceId.Discovery_AssemblyLoadFailed,
+ SR.CompositionTrace_Discovery_AssemblyLoadFailed,
+ catalog.GetDisplayName(),
+ fileName,
+ exception.Message);
}
}
if (CompositionTraceSource.CanWriteInformation)
{
- CompositionTraceSource.WriteInformation(CompositionTraceId.Discovery_DefinitionMarkedWithPartNotDiscoverableAttribute,
- SR.CompositionTrace_Discovery_DefinitionMarkedWithPartNotDiscoverableAttribute,
- type.GetDisplayName());
+ CompositionTraceSource.WriteInformation(CompositionTraceId.Discovery_DefinitionMarkedWithPartNotDiscoverableAttribute,
+ SR.CompositionTrace_Discovery_DefinitionMarkedWithPartNotDiscoverableAttribute,
+ type.GetDisplayName());
}
}
if (CompositionTraceSource.CanWriteInformation)
{
CompositionTraceSource.WriteInformation(CompositionTraceId.Discovery_DefinitionMismatchedExportArity,
- SR.CompositionTrace_Discovery_DefinitionMismatchedExportArity,
- type.GetDisplayName(), member.GetDisplayName());
+ SR.CompositionTrace_Discovery_DefinitionMismatchedExportArity,
+ type.GetDisplayName(), member.GetDisplayName());
}
}
if (CompositionTraceSource.CanWriteInformation)
{
CompositionTraceSource.WriteInformation(CompositionTraceId.Discovery_DefinitionContainsNoExports,
- SR.CompositionTrace_Discovery_DefinitionContainsNoExports,
- type.GetDisplayName());
+ SR.CompositionTrace_Discovery_DefinitionContainsNoExports,
+ type.GetDisplayName());
}
}
if (CompositionTraceSource.CanWriteError)
{
CompositionTraceSource.WriteError(CompositionTraceId.Discovery_MemberMarkedWithMultipleImportAndImportMany,
- SR.CompositionTrace_Discovery_MemberMarkedWithMultipleImportAndImportMany,
- item.GetDisplayName());
+ SR.CompositionTrace_Discovery_MemberMarkedWithMultipleImportAndImportMany,
+ item.GetDisplayName());
}
}
}
Rejection_DefinitionRejected = 1,
Rejection_DefinitionResurrected = 2,
+ // Discovery
+
Discovery_AssemblyLoadFailed = 3,
Discovery_DefinitionMarkedWithPartNotDiscoverableAttribute = 4,
Discovery_DefinitionMismatchedExportArity = 5,
namespace System.ComponentModel
{
- internal static class ExceptionBuilder // UNDONE combine with other one
+ internal static class ExceptionBuilder
{
public static Exception CreateDiscoveryException(string messageFormat, params string[] arguments)
{
+++ /dev/null
-// 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.Collections.ObjectModel;
-using System.ComponentModel.Composition.Primitives;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Linq;
-using Microsoft.Internal;
-using Microsoft.Internal.Collections;
-using System.Threading;
-
-namespace System.ComponentModel.Composition
-{
- public static class AdaptationConstants
- {
- private const string CompositionNamespace = "System.ComponentModel.Composition";
-
- public const string AdapterContractName = CompositionNamespace + ".AdapterContract";
- public const string AdapterFromContractMetadataName = "FromContract";
- public const string AdapterToContractMetadataName = "ToContract";
-
- }
-}
+++ /dev/null
-// 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.Collections.Generic;
-
-namespace System.ComponentModel.Composition
-{
- public interface ITrans_CacheTests_SimpleMetadataView
- {
- string String { get; }
- int Int { get; }
- float Float { get; }
- Type Type { get; }
- object Object { get; }
- IEnumerable<string> Collection { get; }
- }
-}
+++ /dev/null
-// 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.Collections.Generic;
-
-namespace System.ComponentModel.Composition
-{
- public interface ITrans_CollectionOfStrings
- {
- IEnumerable<string> Values { get; }
- }
-}
+++ /dev/null
-// 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.
-
-namespace System.ComponentModel.Composition
-{
- public interface ITrans_ExportableTest
- {
- string Var1 { get; }
- }
-}
namespace System.ComponentModel.Composition
{
- public interface ITrans_MetadataView
- {
- string Foo { get; }
-
- [System.ComponentModel.DefaultValue(null)]
- string OptionalFoo { get; }
- }
-
public interface ITrans_MetadataViewWithDefaultedInt64
{
[DefaultValue(long.MaxValue)]
string MyString { get; }
}
- public interface ITrans_MetadataViewUnboxAsInt
- {
- int Value { get; }
- }
-
public interface ITrans_HasInt64
{
int Value { get; }
+++ /dev/null
-// 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.
-
-namespace System.ComponentModel.Composition
-{
-
- public interface ITrans_SimpleMetadataView
- {
- string String { get; }
- int Int { get; }
- float Float { get; }
- Type Type { get; }
- object Object { get; }
- }
-}
namespace System.ComponentModel.Composition
{
- public interface ITrans_RecompositionTest_RelationshipView
- {
- string Relationship { get; }
- }
-
public interface ITrans_StronglyTypedStructure
{
string String1 { get; }
+++ /dev/null
-// 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.Linq;
-using System.Reflection;
-using Microsoft.VisualBasic;
-using Xunit;
-
-namespace System
-{
- public class StringsTests
- {
- [Fact]
- [ActiveIssue(25498)]
- public void PropertiesAreInsyncWithResources()
- {
- var properties = GetStringProperties();
-
- Assert.True(properties.Length > 0, "Expected to find at least one string property in Strings.cs.");
-
- Assert.All(properties, property =>
- {
- object value = property.GetValue(null, (object[])null);
- Assert.NotNull(value);
- });
- }
-
- private static PropertyInfo[] GetStringProperties()
- {
- PropertyInfo[] properties = typeof(Strings).GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
-
- return properties.Where(property =>
- {
- return !CanIgnore(property);
-
- }).ToArray();
- }
-
- private static bool CanIgnore(PropertyInfo property)
- {
- switch (property.Name)
- {
- case "Culture":
- case "ResourceManager":
- return true;
- }
-
- return false;
- }
- }
-}
<Compile Include="$(CommonTestPath)\System\IO\TempFile.cs">
<Link>Common\System\IO\TempFile.cs</Link>
</Compile>
- <Compile Include="CacheTestsMetadataViews.cs" />
- <Compile Include="ICollectionOfStrings.cs" />
- <Compile Include="IExportableTest.cs" />
<Compile Include="IMetadataView.cs" />
- <Compile Include="ISimpleMetadataView.cs" />
<Compile Include="MetadataTests_IMetadataView.cs" />
- <Compile Include="Microsoft\Internal\LazyServices.cs" />
- <Compile Include="StringsTests.cs" />
+ <Compile Include="System\LazyHelper.cs" />
<Compile Include="System\ComponentModel\Composition\AdvancedValueComposition.cs" />
<Compile Include="System\ComponentModel\Composition\AggregateExportProviderTest.cs" />
<Compile Include="System\ComponentModel\Composition\AttributedModelServicesTests.cs" />
<Compile Include="System\ComponentModel\Composition\ConstraintServicesTests.cs" />
<Compile Include="System\ComponentModel\Composition\ContractBasedImportDefinitionTests.cs" />
<Compile Include="System\ComponentModel\Composition\ContractMismatchExceptionTests.cs" />
- <Compile Include="System\ComponentModel\Composition\Diagnostics\CompositionTraceIdTests.cs" />
- <Compile Include="System\ComponentModel\Composition\Diagnostics\TraceEventDetails.cs" />
- <Compile Include="System\ComponentModel\Composition\Diagnostics\TraceId.cs" />
<Compile Include="System\ComponentModel\Composition\DynamicMetadata.cs" />
<Compile Include="System\ComponentModel\Composition\Expectations.cs" />
<Compile Include="System\ComponentModel\Composition\ExportableAttributeTests.cs" />
<Compile Include="System\ComponentModel\Composition\ScopedCompositionServicetests.cs" />
<Compile Include="System\ComponentModel\Composition\ScopeExportFactoryTests.cs" />
<Compile Include="System\ComponentModel\Composition\ScopingHelpers.cs" />
- <Compile Include="System\Globalization\CurrentCultureContext.cs" />
<Compile Include="System\Integration\AdaptingCollectionTests.cs" />
<Compile Include="System\Integration\CatalogFilteringTests.cs" />
<Compile Include="System\Integration\CompositionContainerAttributedModelCycleTests.cs" />
<Compile Include="System\UnitTesting\ExtendedAssert.cs" />
<Compile Include="System\UnitTesting\RetryMode.cs" />
<Compile Include="System\UnitTesting\TestServices.cs" />
- <Compile Include="TestAssembly.cs" />
- <Compile Include="TransparentTestCase.cs" />
+ <Compile Include="$(CommonTestPath)\System\ThreadCultureChange.cs">
+ <Link>Common\System\ThreadCultureChange.cs</Link>
+ </Compile>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ProjectReference>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
-</Project>
+</Project>
\ No newline at end of file
namespace System.ComponentModel.Composition
{
+ public interface ITrans_ExportableTest
+ {
+ string Var1 { get; }
+ }
+
+ public interface ITrans_CollectionOfStrings
+ {
+ IEnumerable<string> Values { get; }
+ }
+
public class AdvancedValueComposition
{
[Fact]
}
[Fact]
- [ActiveIssue(25498, TestPlatforms.AnyUnix)] // System.ArgumentException: ComposablePartDefinition of type 'System.ComponentModel.Composition.AttributedModel.ConcreteCPD' cannot be used in this context. Only part definitions produced by the ReflectionModelServices.CreatePartDefinition are supported.
public void CreatePart_From_InvalidPartDefiniton_ShouldThrowArgumentException()
{
Assert.Throws<ArgumentException>("partDefinition", () =>
{
- try
- {
- var partDefinition = new ConcreteCPD();
- var instance = new CPDTest();
- var part = AttributedModelServices.CreatePart(partDefinition, instance);
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- throw;
- }
-
+ var partDefinition = new ConcreteCPD();
+ var instance = new CPDTest();
+ AttributedModelServices.CreatePart(partDefinition, instance);
});
}
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
+using System.Common.Tests;
using System.ComponentModel.Composition.Factories;
using System.ComponentModel.Composition.Primitives;
using System.Globalization;
[Fact]
public void Message_ShouldFormatCountOfRootCausesUsingTheCurrentCulture()
{
- var cultures = Expectations.GetCulturesForFormatting();
+ IEnumerable<CultureInfo> cultures = Expectations.GetCulturesForFormatting();
- foreach (var culture in cultures)
+ foreach (CultureInfo culture in cultures)
{
- using (new CurrentCultureContext(culture))
+ // Save old culture and set a fixed culture for object instantiation
+ using (new ThreadCultureChange(culture))
{
- var errors = CreateCompositionErrors(1000);
- var exception = CreateCompositionException(errors);
+ CompositionError[] errors = CreateCompositionErrors(1000);
+ CompositionException exception = CreateCompositionException(errors);
AssertMessage(exception, 1000, culture);
errors = CreateCompositionErrors(1);
+++ /dev/null
-// 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.UnitTesting;
-using Xunit;
-
-namespace System.ComponentModel.Composition.Diagnostics
-{
- public class CompositionTraceIdTests
- {
- [Fact]
- [ActiveIssue(25498, TargetFrameworkMonikers.UapAot)]
- public void CompositionTraceIdsAreInSyncWithTraceIds()
- {
- ExtendedAssert.EnumsContainSameValues<CompositionTraceId, TraceId>();
- }
- }
-}
+++ /dev/null
-// 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.Diagnostics;
-
-namespace System.ComponentModel.Composition.Diagnostics
-{
- public class TraceEventDetails
- {
- public TraceEventDetails(TraceEventCache eventCache, string source, TraceEventType eventType, TraceId id, string format, params object[] args)
- {
- EventCache = eventCache;
- Source = source;
- EventType = eventType;
- Id = id;
- Format = format;
- Args = args;
- }
-
- public TraceEventCache EventCache
- {
- get;
- private set;
- }
-
- public string Source
- {
- get;
- private set;
- }
-
- public TraceEventType EventType
- {
- get;
- private set;
- }
-
- public TraceId Id
- {
- get;
- private set;
- }
-
- public string Format
- {
- get;
- private set;
- }
-
- public object[] Args
- {
- get;
- private set;
- }
- }
-}
+++ /dev/null
-// 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.
-
-namespace System.ComponentModel.Composition.Diagnostics
-{
- // We need a public version of CompositionTraceId, so that the QA tests can access and verify the trace.
- public enum TraceId : ushort
- {
- Rejection_DefinitionRejected = CompositionTraceId.Rejection_DefinitionRejected,
- Rejection_DefinitionResurrected = CompositionTraceId.Rejection_DefinitionResurrected,
-
- Discovery_AssemblyLoadFailed = CompositionTraceId.Discovery_AssemblyLoadFailed,
- Discovery_DefinitionMarkedWithPartNotDiscoverableAttribute = CompositionTraceId.Discovery_DefinitionMarkedWithPartNotDiscoverableAttribute,
- Discovery_DefinitionMismatchedExportArity = CompositionTraceId.Discovery_DefinitionMismatchedExportArity,
- Discovery_DefinitionContainsNoExports = CompositionTraceId.Discovery_DefinitionContainsNoExports,
- Discovery_MemberMarkedWithMultipleImportAndImportMany = CompositionTraceId.Discovery_MemberMarkedWithMultipleImportAndImportMany,
- }
-}
public CustomImportManyAttribute()
{
}
-
- public CustomImportManyAttribute(Type type)
- : base(type)
- {
- }
}
}
}
}
+ public class TestAssemblyOne { }
+
+ public class TestAssemblyTwo { }
+
+ public class TestAssemblyThree { }
+
+ public class TestAssemblyFour { }
+
public class AssemblyCatalogTestsHelper
{
protected string GetAttributedAssemblyCodeBase()
namespace System.ComponentModel.Composition
{
+ internal static class TransparentTestCase
+ {
+ public static int GetMetadataView_IMetadataViewWithDefaultedIntInTranparentType(ITrans_MetadataViewWithDefaultedInt view)
+ {
+ return view.MyInt;
+ }
+ }
+
[MetadataViewImplementation(typeof(MetadataViewWithImplementation))]
public interface IMetadataViewWithImplementation
{
[Export]
public class ClassRoot
{
- [ImportAttribute]
+ [ImportAttribute]
public ExportFactory<ClassA> classA;
- [ImportAttribute]
+ [ImportAttribute]
public ClassA localClassA;
}
public class FromRoot
{
[Import]
- public ExportFactory<ClassRequiresICompositionService> Required { get; set; }
-
+ public ExportFactory<ClassRequiresICompositionService> Required { get; set; }
+
[Import]
- public ExportFactory<ClassOptionallyImportsICompositionService> Optional { get; set; }
+ public ExportFactory<ClassOptionallyImportsICompositionService> Optional { get; set; }
}
[Export]
public class ClassRequiresICompositionService
{
- [Import(AllowDefault=false)]
- public ICompositionService CompositionService { get; set; }
+ [Import(AllowDefault = false)]
+ public ICompositionService CompositionService { get; set; }
}
[Export]
public class ClassOptionallyImportsICompositionService
{
- [Import(AllowDefault=true)]
- public ICompositionService CompositionService { get; set; }
+ [Import(AllowDefault = true)]
+ public ICompositionService CompositionService { get; set; }
}
[Fact]
Assert.Throws<ImportCardinalityMismatchException>(() =>
{
- var service = container.GetExportedValue<ClassRequiresICompositionService>();
+ ClassRequiresICompositionService service = container.GetExportedValue<ClassRequiresICompositionService>();
Assert.Null(service.CompositionService);
});
}
[Fact]
public void DontExportICompositionServiceFromRootOptionalImportShouldSucceed()
{
- var rootCatalog = new TypeCatalog(typeof(ClassRequiresICompositionService),typeof(ClassOptionallyImportsICompositionService));
+ var rootCatalog = new TypeCatalog(typeof(ClassRequiresICompositionService), typeof(ClassOptionallyImportsICompositionService));
var container = new CompositionContainer(rootCatalog);
- var service = container.GetExportedValue<ClassOptionallyImportsICompositionService>();
+ ClassOptionallyImportsICompositionService service = container.GetExportedValue<ClassOptionallyImportsICompositionService>();
Assert.Null(service.CompositionService);
}
[Fact]
public void ExportICompositionServiceFromRootRequiredImportShouldsucceed()
{
- var rootCatalog = new TypeCatalog(typeof(ClassRequiresICompositionService),typeof(ClassOptionallyImportsICompositionService));
+ var rootCatalog = new TypeCatalog(typeof(ClassRequiresICompositionService), typeof(ClassOptionallyImportsICompositionService));
var container = new CompositionContainer(rootCatalog, CompositionOptions.ExportCompositionService);
- var service = container.GetExportedValue<ClassRequiresICompositionService>();
+ ClassRequiresICompositionService service = container.GetExportedValue<ClassRequiresICompositionService>();
Assert.NotNull(service.CompositionService);
}
[Fact]
public void ExportICompositionServiceFromRootOptionalImportShouldSucceed()
{
- var rootCatalog = new TypeCatalog(typeof(ClassRequiresICompositionService),typeof(ClassOptionallyImportsICompositionService));
+ var rootCatalog = new TypeCatalog(typeof(ClassRequiresICompositionService), typeof(ClassOptionallyImportsICompositionService));
var container = new CompositionContainer(rootCatalog, CompositionOptions.ExportCompositionService);
- var service = container.GetExportedValue<ClassOptionallyImportsICompositionService>();
+ ClassOptionallyImportsICompositionService service = container.GetExportedValue<ClassOptionallyImportsICompositionService>();
Assert.NotNull(service.CompositionService);
}
[Fact]
public void DontExportICompositionServiceFromChildImportShouldShouldThrowCompositionException()
{
- var rootCatalog = new TypeCatalog( typeof(FromRoot) );
- var childCatalog = new TypeCatalog( typeof(ClassRequiresICompositionService), typeof(ClassOptionallyImportsICompositionService) );
- var scope = rootCatalog.AsScope(childCatalog.AsScope());
+ var rootCatalog = new TypeCatalog(typeof(FromRoot));
+ var childCatalog = new TypeCatalog(typeof(ClassRequiresICompositionService), typeof(ClassOptionallyImportsICompositionService));
+ CompositionScopeDefinition scope = rootCatalog.AsScope(childCatalog.AsScope());
var container = new CompositionContainer(scope);
Assert.Throws<ImportCardinalityMismatchException>(() =>
{
- var fromRoot = container.GetExportedValue<FromRoot>();
+ FromRoot fromRoot = container.GetExportedValue<FromRoot>();
Assert.Null(fromRoot);
});
}
[Fact]
public void ExportICompositionServiceFromChildImportShouldShouldSucceed()
{
- var childCatalog = new TypeCatalog( typeof(ClassRequiresICompositionService), typeof(ClassOptionallyImportsICompositionService) );
- var rootCatalog = new TypeCatalog( typeof(FromRoot) );
- var scope = rootCatalog.AsScope(childCatalog.AsScope());
+ var childCatalog = new TypeCatalog(typeof(ClassRequiresICompositionService), typeof(ClassOptionallyImportsICompositionService));
+ var rootCatalog = new TypeCatalog(typeof(FromRoot));
+ CompositionScopeDefinition scope = rootCatalog.AsScope(childCatalog.AsScope());
var container = new CompositionContainer(scope, CompositionOptions.ExportCompositionService);
- var fromRoot = container.GetExportedValue<FromRoot>();
+ FromRoot fromRoot = container.GetExportedValue<FromRoot>();
- var requiredService = fromRoot.Required.CreateExport();
- Console.WriteLine("requiredService: {0}", requiredService.Value.CompositionService);
+ ExportLifetimeContext<ClassRequiresICompositionService> requiredService = fromRoot.Required.CreateExport();
Assert.NotNull(requiredService.Value.CompositionService);
- var optionalService = fromRoot.Optional.CreateExport();
- Console.WriteLine("optionalService: {0}", optionalService.Value.CompositionService);
+ ExportLifetimeContext<ClassOptionallyImportsICompositionService> optionalService = fromRoot.Optional.CreateExport();
Assert.NotNull(optionalService.Value.CompositionService);
}
[Fact]
public void ScopingEndToEndWithCompositionService_MatchingCatalogsShouldSucceed()
{
- var c = new TypeCatalog( typeof(ClassRoot), typeof(ClassA) );
- var sd = c.AsScope( c.AsScope() );
+ var c = new TypeCatalog(typeof(ClassRoot), typeof(ClassA));
+ CompositionScopeDefinition sd = c.AsScope(c.AsScope());
var container = new CompositionContainer(sd, CompositionOptions.ExportCompositionService);
- var fromRoot = container.GetExportedValue<ClassRoot>();
- var a1 = fromRoot.classA.CreateExport().Value;
- var a2 = fromRoot.classA.CreateExport().Value;
+ ClassRoot fromRoot = container.GetExportedValue<ClassRoot>();
+ ClassA a1 = fromRoot.classA.CreateExport().Value;
+ ClassA a2 = fromRoot.classA.CreateExport().Value;
fromRoot.localClassA.InstanceValue = 101;
a1.InstanceValue = 202;
a2.InstanceValue = 303;
- if (a1.InstanceValue == a2.InstanceValue) { throw new Exception("Incorrect sharing, a1 is shared with a2"); }
+ if (a1.InstanceValue == a2.InstanceValue)
+ { throw new Exception("Incorrect sharing, a1 is shared with a2"); }
var xroot = new ImportA();
var x1 = new ImportA();
fromRoot.localClassA.CompositionService.SatisfyImportsOnce(xroot);
a1.CompositionService.SatisfyImportsOnce(x1);
a2.CompositionService.SatisfyImportsOnce(x2);
- Assert.Equal(xroot.classA.InstanceValue, fromRoot.localClassA.InstanceValue);
- Assert.Equal(x1.classA.InstanceValue, a1.InstanceValue);
- Assert.Equal(x2.classA.InstanceValue, a2.InstanceValue);
+ Assert.Equal(xroot.classA.InstanceValue, fromRoot.localClassA.InstanceValue);
+ Assert.Equal(x1.classA.InstanceValue, a1.InstanceValue);
+ Assert.Equal(x2.classA.InstanceValue, a2.InstanceValue);
}
[Fact]
public void ScopingEndToEndWithCompositionService_PartitionedCatalogsShouldSucceed()
{
- var c1 = new TypeCatalog( typeof(ClassRoot), typeof(ClassA) );
- var c2 = new TypeCatalog( typeof(ClassA) );
- var sd = c1.AsScope( c2.AsScope() );
+ var c1 = new TypeCatalog(typeof(ClassRoot), typeof(ClassA));
+ var c2 = new TypeCatalog(typeof(ClassA));
+ CompositionScopeDefinition sd = c1.AsScope(c2.AsScope());
var container = new CompositionContainer(sd, CompositionOptions.ExportCompositionService);
- var fromRoot = container.GetExportedValue<ClassRoot>();
- var a1 = fromRoot.classA.CreateExport().Value;
- var a2 = fromRoot.classA.CreateExport().Value;
+ ClassRoot fromRoot = container.GetExportedValue<ClassRoot>();
+ ClassA a1 = fromRoot.classA.CreateExport().Value;
+ ClassA a2 = fromRoot.classA.CreateExport().Value;
fromRoot.localClassA.InstanceValue = 101;
a1.InstanceValue = 202;
a2.InstanceValue = 303;
- if (a1.InstanceValue == a2.InstanceValue) { throw new Exception("Incorrect sharing, a1 is shared with a2"); }
+ if (a1.InstanceValue == a2.InstanceValue)
+ { throw new Exception("Incorrect sharing, a1 is shared with a2"); }
var xroot = new ImportA();
var x1 = new ImportA();
fromRoot.localClassA.CompositionService.SatisfyImportsOnce(xroot);
a1.CompositionService.SatisfyImportsOnce(x1);
a2.CompositionService.SatisfyImportsOnce(x2);
- Assert.Equal(xroot.classA.InstanceValue, fromRoot.localClassA.InstanceValue);
- Assert.Equal(x1.classA.InstanceValue, a1.InstanceValue);
- Assert.Equal(x2.classA.InstanceValue, a2.InstanceValue);
+ Assert.Equal(xroot.classA.InstanceValue, fromRoot.localClassA.InstanceValue);
+ Assert.Equal(x1.classA.InstanceValue, a1.InstanceValue);
+ Assert.Equal(x2.classA.InstanceValue, a2.InstanceValue);
}
-
}
}
+++ /dev/null
-// 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.Threading;
-
-namespace System.Globalization
-{
- public class CurrentCultureContext : IDisposable
- {
- private CultureInfo _previousCulture;
-
- public CurrentCultureContext(CultureInfo culture)
- {
- _previousCulture = Thread.CurrentThread.CurrentCulture;
-
- Thread.CurrentThread.CurrentCulture = culture;
- }
-
- public void Dispose()
- {
- if (_previousCulture != null)
- {
- Thread.CurrentThread.CurrentCulture = _previousCulture;
- }
- }
- }
-}
// 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.Threading;
-namespace Microsoft.Internal
+namespace System
{
- internal static class LazyServices
+ internal static class LazyHelper
{
public static Lazy<T> AsLazy<T>(this T t)
where T : class
+++ /dev/null
-// 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;
-
-namespace System.ComponentModel.Composition
-{
- public class TestAssemblyOne { }
-
- public class TestAssemblyTwo { }
-
- public class TestAssemblyThree { }
-
- public class TestAssemblyFour { }
-
- [Export]
- public class TestAssemblyOneExport { }
-
- // This is a glorious do nothing ReflectionContext
- public class ReflectionContextTestAssemblyThreeReflectionContext : ReflectionContext
- {
- private ReflectionContextTestAssemblyThreeReflectionContext() {}
- public override Assembly MapAssembly(Assembly assembly)
- {
- return assembly;
- }
-
- public override TypeInfo MapType(TypeInfo type)
- {
- return type;
- }
- }
-
- // This is a glorious do nothing ReflectionContext
- public class ReflectionContextTestAssemblyOneReflectionContext : ReflectionContext
- {
- public override Assembly MapAssembly(Assembly assembly)
- {
- return assembly;
- }
-
- public override TypeInfo MapType(TypeInfo type)
- {
- return type;
- }
- }
-
- [Export]
- public class TestAssemblyTwoExport { }
-
- public class MyLittleConventionAttribute : CatalogReflectionContextAttribute
- {
- public MyLittleConventionAttribute() : base(typeof(ReflectionContextTestAssemblyTwo))
- {
- }
-
- // This is a glorious do nothing ReflectionContext
- public class ReflectionContextTestAssemblyTwo : ReflectionContext
- {
- public override Assembly MapAssembly(Assembly assembly)
- {
- return assembly;
- }
-
- public override TypeInfo MapType(TypeInfo type)
- {
- return type;
- }
- }
- }
-}
+++ /dev/null
-// 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.
-
-namespace System.ComponentModel.Composition
-{
- static public class TransparentTestCase
- {
- static public int GetMetadataView_IMetadataViewWithDefaultedIntInTranparentType(ITrans_MetadataViewWithDefaultedInt view)
- {
- return view.MyInt;
- }
- }
-}