-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathProductPartLink.cs
83 lines (74 loc) · 2.22 KB
/
ProductPartLink.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0
namespace Moryx.AbstractionLayer.Products
{
/// <summary>
/// Base class that allows to assign a value to <see cref="IPersistentObject.Id"/>
/// </summary>
public abstract class ProductPartLink : IProductPartLink
{
/// <summary>
/// Default constructor for a new part link
/// </summary>
internal ProductPartLink()
{
}
/// <summary>
/// Constructor for parts links that are read from database
/// </summary>
/// <param name="id"></param>
internal ProductPartLink(long id)
{
Id = id;
}
/// <summary>
/// Unique id of this link object
/// </summary>
public long Id { get; set; }
/// <summary>
/// Parent product for this part link
/// </summary>
public IProductType Parent { get; set; }
/// <summary>
/// Generic product reference of this link
/// </summary>
public IProductType Product { get; set; }
/// <summary>
/// Create single instance for this part
/// </summary>
public virtual ProductInstance Instantiate()
{
var instance = Product.CreateInstance();
instance.PartLink = this;
return instance;
}
}
/// <summary>
/// Class to create generic part structure
/// </summary>
public class ProductPartLink<TProduct> : ProductPartLink, IProductPartLink<TProduct>
where TProduct : class, IProductType
{
/// <summary>
/// Default constructor for a new part link
/// </summary>
public ProductPartLink()
{
}
/// <summary>
/// Constructor for parts links that are read from database
/// </summary>
/// <param name="id"></param>
public ProductPartLink(long id) : base(id)
{
}
/// <summary>
/// Reference to the generic product
/// </summary>
public new TProduct Product
{
get => (TProduct)base.Product;
set => base.Product = value;
}
}
}