File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
src/Microsoft.OpenApi/Any
test/Microsoft.OpenApi.Tests/PublicApi Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,29 @@ namespace Microsoft.OpenApi.Any
1010 /// </summary>
1111 public class OpenApiAnyCloneHelper
1212 {
13+ /// <summary>
14+ /// Clones an instance of <see cref="IOpenApiAny"/> object from the copy constructor
15+ /// </summary>
16+ /// <param name="obj">The object instance.</param>
17+ /// <returns>A clone copy or the object itself.</returns>
18+ public static IOpenApiAny CloneFromCopyConstructor ( IOpenApiAny obj )
19+ {
20+ if ( obj != null )
21+ {
22+ var t = obj . GetType ( ) ;
23+ foreach ( var ci in t . GetConstructors ( ) )
24+ {
25+ var pi = ci . GetParameters ( ) ;
26+ if ( pi . Length == 1 && pi [ 0 ] . ParameterType == t )
27+ {
28+ return ( IOpenApiAny ) ci . Invoke ( new object [ ] { obj } ) ;
29+ }
30+ }
31+ }
32+
33+ return obj ;
34+ }
35+
1336 /// <summary>
1437 /// Clones an instance of <see cref="IOpenApiAny"/> object from the copy constructor
1538 /// </summary>
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ namespace Microsoft.OpenApi.Any
2222 public class OpenApiAnyCloneHelper
2323 {
2424 public OpenApiAnyCloneHelper() { }
25+ public static Microsoft.OpenApi.Any.IOpenApiAny CloneFromCopyConstructor(Microsoft.OpenApi.Any.IOpenApiAny obj) { }
2526 public static Microsoft.OpenApi.Any.IOpenApiAny CloneFromCopyConstructor<T>(T obj)
2627 where T : Microsoft.OpenApi.Any.IOpenApiAny { }
2728 }
You can’t perform that action at this time.
0 commit comments