C# copy interface properties

Date: 2023-07-04
internal static ICommonOrderDataArticle Copy(ICommonOrderDataArticle commonOrderDataArticle)
{
    var article = new CommonOrderDataArticle();
    CopyPropertiesTo(commonOrderDataArticle, article);
    return article;
}

public static void CopyPropertiesTo<T>(T source, T dest)
{
    var plist = typeof(T).GetProperties().Where(x => x.CanRead && x.CanWrite).ToList();
    foreach (var prop in plist)
        prop.SetValue(dest, prop.GetValue(source, null), null);
}
78920cookie-checkC# copy interface properties