diff options
| author | Cody Robibero <cody@robibe.ro> | 2021-12-11 12:04:58 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-11 12:04:58 -0700 |
| commit | 4d1b8246513b352d65d4db6afcb97ae1e984c760 (patch) | |
| tree | cd7a3fe42e3ace4cfe0aa3268f5dcee29f855e43 /Jellyfin.Api/Helpers/ClassMigrationHelper.cs | |
| parent | fbc79cb4cee4fec27fd440127469f6dcdc1bc7c2 (diff) | |
| parent | a87b87825dac31f3739a8dc0254548c3e81a241e (diff) | |
Merge pull request #6902 from cvium/migrate_networkconfig
Migrate network configuration safely
Diffstat (limited to 'Jellyfin.Api/Helpers/ClassMigrationHelper.cs')
| -rw-r--r-- | Jellyfin.Api/Helpers/ClassMigrationHelper.cs | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/Jellyfin.Api/Helpers/ClassMigrationHelper.cs b/Jellyfin.Api/Helpers/ClassMigrationHelper.cs deleted file mode 100644 index 76fb27bcc..000000000 --- a/Jellyfin.Api/Helpers/ClassMigrationHelper.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Reflection; - -namespace Jellyfin.Api.Helpers -{ - /// <summary> - /// A static class for copying matching properties from one object to another. - /// TODO: remove at the point when a fixed migration path has been decided upon. - /// </summary> - public static class ClassMigrationHelper - { - /// <summary> - /// Extension for 'Object' that copies the properties to a destination object. - /// </summary> - /// <param name="source">The source.</param> - /// <param name="destination">The destination.</param> - public static void CopyProperties(this object source, object destination) - { - // If any this null throw an exception. - if (source == null || destination == null) - { - throw new ArgumentException("Source or/and Destination Objects are null"); - } - - // Getting the Types of the objects. - Type typeDest = destination.GetType(); - Type typeSrc = source.GetType(); - - // Iterate the Properties of the source instance and populate them from their destination counterparts. - PropertyInfo[] srcProps = typeSrc.GetProperties(); - foreach (PropertyInfo srcProp in srcProps) - { - if (!srcProp.CanRead) - { - continue; - } - - var targetProperty = typeDest.GetProperty(srcProp.Name); - if (targetProperty == null) - { - continue; - } - - if (!targetProperty.CanWrite) - { - continue; - } - - var obj = targetProperty.GetSetMethod(true); - if (obj != null && obj.IsPrivate) - { - continue; - } - - var target = targetProperty.GetSetMethod(); - if (target != null && (target.Attributes & MethodAttributes.Static) != 0) - { - continue; - } - - if (!targetProperty.PropertyType.IsAssignableFrom(srcProp.PropertyType)) - { - continue; - } - - // Passed all tests, lets set the value. - targetProperty.SetValue(destination, srcProp.GetValue(source, null), null); - } - } - } -} |
