-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set the most logical config defaults for the wizard (#187)
* Set the most logical config defaults plus cleanup refactor * Fix unnecessary use of this * Revert version bump Co-authored-by: John Gathogo <[email protected]>
- Loading branch information
Showing
19 changed files
with
932 additions
and
577 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//----------------------------------------------------------------------------- | ||
// <copyright file="ExtensionMethods.cs" company=".NET Foundation"> | ||
// Copyright (c) .NET Foundation and Contributors. All rights reserved. | ||
// See License.txt in the project root for license information. | ||
// </copyright> | ||
//---------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Microsoft.OData.ConnectedService.Common | ||
{ | ||
internal static class ExtensionMethods | ||
{ | ||
/// <summary> | ||
/// Copies public properties with matching name and type from one object to the other. | ||
/// </summary> | ||
/// <param name="target">The target.</param> | ||
/// <param name="source">The source.</param> | ||
public static void CopyPropertiesFrom(this object target, object source) | ||
{ | ||
if (source == null) | ||
{ | ||
return; | ||
} | ||
|
||
var fromProperties = source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance) | ||
.Where(d => d.GetGetMethod() != null); | ||
var toProperties = target.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance) | ||
.Where(d => d.GetSetMethod() != null); | ||
|
||
foreach(var toProperty in toProperties) | ||
{ | ||
var fromProperty = fromProperties.SingleOrDefault(d => | ||
d.Name.Equals(toProperty.Name, StringComparison.Ordinal) | ||
&& toProperty.PropertyType.IsAssignableFrom(d.PropertyType)); | ||
|
||
if (fromProperty != null) | ||
{ | ||
toProperty.SetValue(target, fromProperty.GetValue(source)); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.