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
|
using System;
using System.Collections.Generic;
namespace MarcelJKloubert
{
public class MyCloneableObject : ICloneable
{
#region Methoden
/// <summary>
///
/// </summary>
/// <see cref="System.ICloneable.Clone()"/>
public object Clone()
{
// hier kommt der Code zum klonen des Objektes rein...
}
#endregion
#region Operatoren
/// <summary>
/// Erstellt eine gewisse Anzahl von geklonten Objekten.
/// </summary>
/// <param name="obj">Objekt, das geklont werden soll.</param>
/// <param name="count">Anzahl der geklonten Objekte.</param>
/// <returns>Liste mit geklonten Objekten.</returns>
/// <exception cref="">Wird geworfen, wenn die Anzahl kleiner als 0 ist.</exception>
public static IEnumerable<MyCloneableObject> operator *(MyCloneableObject obj, int count)
{
if (count < 0)
{
throw new ArgumentOutOfRangeException("count");
}
for (int i = 0; i < count; i++)
{
MyCloneableObject item = obj is MyCloneableObject ?
(MyCloneableObject)obj.Clone() : null;
yield return item;
}
}
/// <summary>
/// Erstellt eine gewisse Anzahl von geklonten Objekten.
/// </summary>
/// <param name="count">Anzahl der geklonten Objekte.</param>
/// <param name="obj">Objekt, das geklont werden soll.</param>
/// <returns>Liste mit geklonten Objekten.</returns>
/// <exception cref="">Wird geworfen, wenn die Anzahl kleiner als 0 ist.</exception>
public static IEnumerable<MyCloneableObject> operator *(int count, MyCloneableObject obj)
{
return obj * count;
}
#endregion
}
}
|