diff --git a/src/Wpf/Prism.Wpf/Regions/NavigationParameters.cs b/src/Wpf/Prism.Wpf/Regions/NavigationParameters.cs index bac9aba33b..871e847df3 100644 --- a/src/Wpf/Prism.Wpf/Regions/NavigationParameters.cs +++ b/src/Wpf/Prism.Wpf/Regions/NavigationParameters.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; +using Prism.Common; namespace Prism.Regions { @@ -13,260 +8,17 @@ namespace Prism.Regions /// /// This class can be used to to pass object parameters during Navigation. /// - public class NavigationParameters : IEnumerable> + public class NavigationParameters : ParametersBase { - private readonly List> _entries = new List>(); - - /// - /// Gets the number of parameters contained in the NavigationParameters - /// - public int Count - { - get - { - return _entries.Count; - } - } - - /// - /// Gets an IEnumerable containing the keys in the NavigationParameters - /// - public IEnumerable Keys - { - get { return _entries.Select(x => x.Key); } - } - /// /// Initializes a new instance of the class. /// - public NavigationParameters() - { - } - - /// - /// Initializes a new instance of the class with a query string. - /// - /// The query string. - public NavigationParameters(string query) - { - if (!String.IsNullOrWhiteSpace(query)) - { - int num = query.Length; - for (int i = ((query.Length > 0) && (query[0] == '?')) ? 1 : 0; i < num; i++) - { - int startIndex = i; - int num4 = -1; - while (i < num) - { - char ch = query[i]; - if (ch == '=') - { - if (num4 < 0) - { - num4 = i; - } - } - else if (ch == '&') - { - break; - } - i++; - } - string key = null; - string value = null; - if (num4 >= 0) - { - key = query.Substring(startIndex, num4 - startIndex); - value = query.Substring(num4 + 1, (i - num4) - 1); - } - else - { - value = query.Substring(startIndex, i - startIndex); - } - - if (key != null) - Add(Uri.UnescapeDataString(key), Uri.UnescapeDataString(value)); - } - } - } + public NavigationParameters() : base() { } /// - /// Gets the with the specified key. + /// Constructs a list of parameters /// - /// The value for the specified key, or if the query does not contain such a key. - public object this[string key] - { - get - { - foreach (var kvp in this._entries) - { - if (string.Compare(kvp.Key, key, StringComparison.Ordinal) == 0) - { - return kvp.Value; - } - } - - return null; - } - } - - /// - /// Gets the enumerator. - /// - /// - public IEnumerator> GetEnumerator() - { - return this._entries.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return this.GetEnumerator(); - } - - /// - /// Adds the specified key and value. - /// - /// The name. - /// The value. - public void Add(string key, object value) - { - this._entries.Add(new KeyValuePair(key, value)); - } - - /// - /// Determines whether the NavigationParameters contains the specified key - /// - /// The key to locate - public bool ContainsKey(string key) - { - foreach (var kvp in _entries) - { - if (string.Compare(kvp.Key, key, StringComparison.Ordinal) == 0) - { - return true; - } - } - - return false; - } - - /// - /// Gets a strongly typed value with the specified key. - /// - /// The type to cast/convert the value to. - /// The key. - /// The value. - public T GetValue(string key) - { - foreach (var kvp in _entries) - { - if (string.Compare(kvp.Key, key, StringComparison.Ordinal) == 0) - { - if (kvp.Value == null) - return default(T); - else if (kvp.Value.GetType() == typeof(T)) - return (T)kvp.Value; - else if (typeof(T).GetTypeInfo().IsAssignableFrom(kvp.Value.GetType().GetTypeInfo())) - return (T)kvp.Value; - else - return (T)Convert.ChangeType(kvp.Value, typeof(T)); - } - } - - return default(T); - } - - /// - /// Gets a strongly typed value with the specified key. - /// - /// The type to cast/convert the value to. - /// The key. - /// Key value if such key exists. - /// True if such key exists. - public bool TryGetValue(string key, out T value) - { - foreach (var kvp in _entries) - { - if (string.Compare(kvp.Key, key, StringComparison.Ordinal) == 0) - { - if (kvp.Value == null) - value = default(T); - else if (kvp.Value.GetType() == typeof(T)) - value = (T)kvp.Value; - else if (typeof(T).GetTypeInfo().IsAssignableFrom(kvp.Value.GetType().GetTypeInfo())) - value = (T)kvp.Value; - else - value = (T)Convert.ChangeType(kvp.Value, typeof(T)); - - return true; - } - } - - value = default(T); - return false; - } - - /// - /// Gets a strongly typed collection containing the values with the specified key. - /// - /// The type to cast/convert the value to. - /// The key. - /// The collection of values. - public IEnumerable GetValues(string key) - { - List values = new List(); - - foreach (var kvp in _entries) - { - if (string.Compare(kvp.Key, key, StringComparison.Ordinal) == 0) - { - if (kvp.Value == null) - values.Add(default(T)); - else if (kvp.Value.GetType() == typeof(T)) - values.Add((T)kvp.Value); - else if (typeof(T).GetTypeInfo().IsAssignableFrom(kvp.Value.GetType().GetTypeInfo())) - values.Add((T)kvp.Value); - else - values.Add((T)Convert.ChangeType(kvp.Value, typeof(T))); - } - } - - return values.AsEnumerable(); - } - - /// - /// Converts the list of key value pairs to a query string. - /// - /// - public override string ToString() - { - var queryBuilder = new StringBuilder(); - - if (this._entries.Count > 0) - { - queryBuilder.Append('?'); - var first = true; - - foreach (var kvp in this._entries) - { - if (!first) - { - queryBuilder.Append('&'); - } - else - { - first = false; - } - - queryBuilder.Append(Uri.EscapeDataString(kvp.Key)); - queryBuilder.Append('='); - queryBuilder.Append(Uri.EscapeDataString(kvp.Value != null ? kvp.Value.ToString() : "")); - } - } - - return queryBuilder.ToString(); - - } + /// Query string to be parsed + public NavigationParameters(string query) : base(query) { } } } diff --git a/src/Wpf/Prism.Wpf/Services/Dialogs/DialogParameters.cs b/src/Wpf/Prism.Wpf/Services/Dialogs/DialogParameters.cs index 0ca6643bbf..f1bd78eda5 100644 --- a/src/Wpf/Prism.Wpf/Services/Dialogs/DialogParameters.cs +++ b/src/Wpf/Prism.Wpf/Services/Dialogs/DialogParameters.cs @@ -1,11 +1,24 @@ -using Prism.Regions; +using Prism.Common; namespace Prism.Services.Dialogs { - public class DialogParameters : NavigationParameters, IDialogParameters + /// + /// Represents Dialog parameters. + /// + /// + /// This class can be used to to pass object parameters during the showing and closing of Dialogs. + /// + public class DialogParameters : ParametersBase, IDialogParameters { + /// + /// Initializes a new instance of the class. + /// public DialogParameters() : base() { } + /// + /// Constructs a list of parameters + /// + /// Query string to be parsed public DialogParameters(string query) : base(query) { } } }