Skip to content

Commit a0b6f9d

Browse files
committed
Avoid binary compat break in CloneFromCopyConstructor
1 parent 11466d7 commit a0b6f9d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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>

test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)