Skip to content

Commit

Permalink
Set the most logical config defaults for the wizard (#187)
Browse files Browse the repository at this point in the history
* 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
gathogojr and John Gathogo authored Jan 19, 2021
1 parent 9ccf826 commit fdcf18e
Show file tree
Hide file tree
Showing 19 changed files with 932 additions and 577 deletions.
46 changes: 46 additions & 0 deletions src/Common/ExtensionMethods.cs
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));
}
}
}
}
}
5 changes: 3 additions & 2 deletions src/Common/UserSettingsPersistenceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public static void Save(object userSettings, string providerId, string name, Act
{
// note: this overwrites existing settings file if it exists
stream = file.OpenFile(fileName, FileMode.Create);
using (var writer = XmlWriter.Create(stream))
using (var writer = XmlWriter.Create(stream, new XmlWriterSettings { Indent = true }))
{
var dcs = new DataContractSerializer(userSettings.GetType());
dcs.WriteObject(writer, userSettings);
Expand Down Expand Up @@ -112,7 +113,7 @@ public static T Load<T>(string providerId, string name, Action<T> onLoaded, Conn

private static string GetStorageFileName(string providerId, string name)
{
return providerId + "_" + name + ".xml";
return providerId + "." + name + ".xml";
}

private static IsolatedStorageFile GetIsolatedStorageFile()
Expand Down
6 changes: 3 additions & 3 deletions src/Models/ServiceConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal class ServiceConfigurationV4 : ServiceConfiguration
public bool EnableNamingAlias { get; set; }
public bool IgnoreUnexpectedElementsAndAttributes { get; set; }
public bool IncludeT4File { get; set; }
public List<string> ExcludedOperationImports;
public List<string> ExcludedBoundOperations;
public List<string> ExcludedOperationImports { get; set; }
public List<string> ExcludedBoundOperations { get; set; }
}
}
}
Loading

0 comments on commit fdcf18e

Please sign in to comment.