-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathIProductPartLink.cs
52 lines (47 loc) · 1.48 KB
/
IProductPartLink.cs
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
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0
using System.Collections.Generic;
using System.Linq;
namespace Moryx.AbstractionLayer.Products
{
/// <summary>
/// Base interface for the link
/// </summary>
public interface IProductPartLink : IPersistentObject
{
/// <summary>
/// Generic access to the product of this part link
/// </summary>
IProductType Product { get; set; }
/// <summary>
/// Create single product instance for this part
/// </summary>
ProductInstance Instantiate();
}
/// <summary>
/// API for part wrapper
/// </summary>
/// <typeparam name="TProduct"></typeparam>
public interface IProductPartLink<TProduct> : IProductPartLink
where TProduct : IProductType
{
/// <summary>
/// Typed product of this part
/// </summary>
new TProduct Product { get; set; }
}
/// <summary>
/// Extension to instantiate instance collection from product type parts collection
/// </summary>
public static class PartLinkExtension
{
/// <summary>
/// Instantiate product instance collection
/// </summary>
public static List<TInstance> Instantiate<TInstance>(this IEnumerable<IProductPartLink> parts)
where TInstance : ProductInstance
{
return parts.Select(p => (TInstance)p.Instantiate()).ToList();
}
}
}