Skip to content

Commit

Permalink
Avoid binary compat break in CloneFromCopyConstructor
Browse files Browse the repository at this point in the history
  • Loading branch information
captainsafia committed Jul 6, 2024
1 parent 11466d7 commit a0b6f9d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,29 @@ namespace Microsoft.OpenApi.Any
/// </summary>
public class OpenApiAnyCloneHelper
{
/// <summary>
/// Clones an instance of <see cref="IOpenApiAny"/> object from the copy constructor
/// </summary>
/// <param name="obj">The object instance.</param>
/// <returns>A clone copy or the object itself.</returns>
public static IOpenApiAny CloneFromCopyConstructor(IOpenApiAny obj)
{
if (obj != null)
{
var t = obj.GetType();
foreach (var ci in t.GetConstructors())
{
var pi = ci.GetParameters();
if (pi.Length == 1 && pi[0].ParameterType == t)
{
return (IOpenApiAny)ci.Invoke(new object[] { obj });
}
}
}

return obj;
}

/// <summary>
/// Clones an instance of <see cref="IOpenApiAny"/> object from the copy constructor
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Microsoft.OpenApi.Any
public class OpenApiAnyCloneHelper
{
public OpenApiAnyCloneHelper() { }
public static Microsoft.OpenApi.Any.IOpenApiAny CloneFromCopyConstructor(Microsoft.OpenApi.Any.IOpenApiAny obj) { }
public static Microsoft.OpenApi.Any.IOpenApiAny CloneFromCopyConstructor<T>(T obj)
where T : Microsoft.OpenApi.Any.IOpenApiAny { }
}
Expand Down

0 comments on commit a0b6f9d

Please sign in to comment.