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

PartDefinitionFactory.DerivedComposablePartDefinition.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: 09fdd205ba6f2d5a5d1130425aad570690fd6845 (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
68
69
70
71
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.ComponentModel.Composition.Primitives;

namespace System.ComponentModel.Composition.Factories
{
    partial class PartDefinitionFactory
    {
        private class DerivedComposablePartDefinition : ComposablePartDefinition
        {
            private readonly Func<ComposablePart> _partCreator;
            private readonly IDictionary<string, object> _metadata;
            private IEnumerable<ImportDefinition> _importDefinitions;
            private IEnumerable<ExportDefinition> _exportDefinitions;
            private readonly Func<IEnumerable<ImportDefinition>> _importsCreator;
            private readonly Func<IEnumerable<ExportDefinition>> _exportsCreator;


            public DerivedComposablePartDefinition(
                IDictionary<string, object> metadata,
                Func<ComposablePart> partCreator,
                Func<IEnumerable<ImportDefinition>> importsCreator,
                Func<IEnumerable<ExportDefinition>> exportsCreator)
            {
                this._metadata = metadata.AsReadOnly();
                this._partCreator = partCreator;
                this._importsCreator = importsCreator;
                this._exportsCreator = exportsCreator;
            }

            public override IDictionary<string, object> Metadata
            {
                get { return this._metadata; }
            }

            public override IEnumerable<ExportDefinition> ExportDefinitions
            {
                get 
                {
                    if (this._exportDefinitions == null)
                    {
                        this._exportDefinitions = this._exportsCreator.Invoke() ?? Enumerable.Empty<ExportDefinition>();
                    }
                    return this._exportDefinitions; 
                }
            }

            public override IEnumerable<ImportDefinition> ImportDefinitions
            {
                get
                {
                    if (this._importDefinitions == null)
                    {
                        this._importDefinitions = this._importsCreator.Invoke() ?? Enumerable.Empty<ImportDefinition>();
                    }
                    return this._importDefinitions;
                }
            }

            public override ComposablePart CreatePart()
            {
                return this._partCreator();
            }
        }
    }
}