5
5
using k8s . Models ;
6
6
using KubeOps . Operator . Comparing ;
7
7
8
- namespace KubeOps . Operator . Entities
8
+ namespace KubeOps . Operator . Entities . Extensions
9
9
{
10
- internal static class EntityExtensions
10
+ internal static class DeepCloneExtensions
11
11
{
12
- internal static CustomEntityDefinition CreateResourceDefinition (
13
- this IKubernetesObject < V1ObjectMeta > kubernetesEntity ) =>
14
- CreateResourceDefinition ( kubernetesEntity . GetType ( ) ) ;
15
-
16
- internal static CustomEntityDefinition CreateResourceDefinition < TResource > ( )
17
- where TResource : IKubernetesObject < V1ObjectMeta > =>
18
- CreateResourceDefinition ( typeof ( TResource ) ) ;
19
-
20
- internal static CustomEntityDefinition CreateResourceDefinition ( Type resourceType )
12
+ /// <summary>
13
+ /// Returns a Deep Clone / Deep Copy of an object of type T using a recursive call to the CloneMethod specified above.
14
+ /// </summary>
15
+ internal static TResource DeepClone < TResource > ( this TResource obj )
16
+ where TResource : IKubernetesObject < V1ObjectMeta >
21
17
{
22
- var attribute = resourceType . GetCustomAttribute < KubernetesEntityAttribute > ( ) ;
23
- if ( attribute == null )
24
- {
25
- throw new ArgumentException ( $ "The Type { resourceType } does not have the kubernetes entity attribute.") ;
26
- }
27
-
28
- var scopeAttribute = resourceType . GetCustomAttribute < EntityScopeAttribute > ( ) ;
29
- var kind = string . IsNullOrWhiteSpace ( attribute . Kind ) ? resourceType . Name : attribute . Kind ;
30
-
31
- return new CustomEntityDefinition (
32
- kind ,
33
- $ "{ kind } List",
34
- attribute . Group ,
35
- attribute . ApiVersion ,
36
- kind . ToLower ( ) ,
37
- string . IsNullOrWhiteSpace ( attribute . PluralName ) ? $ "{ kind . ToLower ( ) } s" : attribute . PluralName ,
38
- scopeAttribute ? . Scope ?? default ) ;
18
+ return ( TResource ) ( DeepClone_Internal (
19
+ obj ,
20
+ new Dictionary < object , object > ( new ReferenceEqualityComparer ( ) ) ) ??
21
+ throw new InvalidCastException ( ) ) ;
39
22
}
40
23
41
24
/// <summary>
@@ -55,18 +38,6 @@ private static bool IsPrimitive(this Type type)
55
38
return ( type . IsValueType & type . IsPrimitive ) ;
56
39
}
57
40
58
- /// <summary>
59
- /// Returns a Deep Clone / Deep Copy of an object of type T using a recursive call to the CloneMethod specified above.
60
- /// </summary>
61
- internal static TResource DeepClone < TResource > ( this TResource obj )
62
- where TResource : IKubernetesObject < V1ObjectMeta >
63
- {
64
- return ( TResource ) ( DeepClone_Internal (
65
- obj ,
66
- new Dictionary < object , object > ( new ReferenceEqualityComparer ( ) ) ) ??
67
- throw new InvalidCastException ( ) ) ;
68
- }
69
-
70
41
private static object ? DeepClone_Internal ( object ? obj , IDictionary < object , object > visited )
71
42
{
72
43
if ( obj == null ) return null ;
0 commit comments