Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ExportFactory.cs « Factories « Composition « ComponentModel « System « ComponentModelUnitTest « Tests « System.ComponentModel.Composition « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7813fee2b6f41645f548736520a5e81bb7c3207a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Primitives;

namespace System.ComponentModel.Composition.Factories
{
    // This class deliberately does not create instances of Lazy<T, TMetadataView>,
    // so as to test other derived classes from Lazy<T, TMetadataView>.
    internal static partial class ExportFactory
    {
        public static IEnumerable<Export> Create(string contractName, int count)
        {
            Export[] exports = new Export[count];

            for (int i = 0; i < count; i++)
            {
                exports[i] = Create(contractName, (object)null);
            }

            return exports;
        }

        public static Lazy<T> Create<T>(T value)
        {
            return new Lazy<T>(() => value, false);
        }

        public static Lazy<T, IDictionary<string, object>> Create<T>(T value, IDictionary<string, object> metadata)
        {
            return Create<T, IDictionary<string, object>>(() => value, metadata);
        }

        public static Export Create(string contractName, Func<object> exportedValueGetter)
        {
            return Create(contractName,(IDictionary<string, object>)null, exportedValueGetter);
        }

        public static Export Create(string contractName)
        {
            return Create(contractName, null, (IDictionary<string, object>)null);
        }

        public static Export Create(string contractName, object value)
        {
            return Create(contractName, value, (IDictionary<string, object>)null);
        }

        public static Export Create(string contractName, object value, IDictionary<string, object> metadata)
        {
            return Create(contractName, metadata, () => value);
        }

        public static Export Create(string contractName, IDictionary<string, object> metadata, Func<object> exportedValueGetter)
        {
            return new Export(ExportDefinitionFactory.Create(contractName, metadata), exportedValueGetter);
        }

        private static Lazy<T, TMetadataView> Create<T, TMetadataView>(Func<T> exportedValueGetter, IDictionary<string, object> metadata)
        {
            return new Lazy<T, TMetadataView>(exportedValueGetter, AttributedModelServices.GetMetadataView<TMetadataView>(metadata), false);
        }
    }
}