Some attempts at making this compile on WinRT. Much work remains.

git-svn-id: file:///srv/devel/repo-conversion/nusu@281 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2012-03-17 13:03:40 +00:00
parent cc1b8d095a
commit 7d4a66e9f2
8 changed files with 163 additions and 34 deletions

View File

@ -21,6 +21,7 @@ License along with this library
using System;
using System.Collections.Generic;
using System.Collections;
using System.Reflection;
namespace Nuclex.Support.Collections {
@ -308,7 +309,11 @@ namespace Nuclex.Support.Collections {
/// <param name="value">Value that will be checked for compatibility</param>
/// <returns>True if the value can be placed in the deque</returns>
private static bool isCompatibleObject(object value) {
#if WINRT
return ((value is TItem) || ((value == null) && !typeof(TItem).GetTypeInfo().IsValueType));
#else
return ((value is TItem) || ((value == null) && !typeof(TItem).IsValueType));
#endif
}
/// <summary>Verifies that the provided object matches the deque's type</summary>

View File

@ -31,7 +31,11 @@ namespace Nuclex.Support.Collections {
/// <typeparam name="TValue">Type of values stored in the dictionary</typeparam>
public interface IMultiDictionary<TKey, TValue> :
IDictionary<TKey, ICollection<TValue>>,
#if WINRT
ICollection,
#else
IDictionary,
#endif
ICollection<KeyValuePair<TKey, TValue>>,
IEnumerable<KeyValuePair<TKey, TValue>>,
IEnumerable {

View File

@ -29,7 +29,7 @@ namespace Nuclex.Support.Collections {
/// <summary>Unit Test for the item event argument container</summary>
[TestFixture]
public class ItemReplaceEventArgsTest {
internal class ItemReplaceEventArgsTest {
/// <summary>
/// Tests whether an integer argument can be stored in the argument container

View File

@ -38,6 +38,8 @@ namespace Nuclex.Support.Collections {
#region IDictionary implementation
#if !WINRT
/// <summary>Adds an item into the dictionary</summary>
/// <param name="key">Key under which the item will be added</param>
/// <param name="value">Item that will be added</param>
@ -52,12 +54,6 @@ namespace Nuclex.Support.Collections {
return this.objectDictionary.Contains(key);
}
/// <summary>Returns a new entry enumerator for the dictionary</summary>
/// <returns>The new entry enumerator</returns>
IDictionaryEnumerator IDictionary.GetEnumerator() {
return new Enumerator(this);
}
/// <summary>Whether the size of the dictionary is fixed</summary>
bool IDictionary.IsFixedSize {
get { return this.objectDictionary.IsFixedSize; }
@ -93,8 +89,24 @@ namespace Nuclex.Support.Collections {
set { this[(TKey)key] = (ICollection<TValue>)value; }
}
#endif // !WINRT
#endregion
#region IDictionaryEnumerator implementation
#if !WINRT
/// <summary>Returns a new entry enumerator for the dictionary</summary>
/// <returns>The new entry enumerator</returns>
IDictionaryEnumerator IDictionary.GetEnumerator() {
return new Enumerator(this);
}
#endif // !WINRT
#endregion // IDictionaryEnumerator implementation
#region ICollection<KeyValuePair<TKey, TValue>> implementation
/// <summary>Inserts an already prepared element into the dictionary</summary>

View File

@ -34,7 +34,10 @@ namespace Nuclex.Support.Collections {
/// <summary>Enumerates the values stored in a multi dictionary</summary>
private class Enumerator :
IEnumerator<KeyValuePair<TKey, TValue>>, IDictionaryEnumerator {
#if !WINRT
IDictionaryEnumerator,
#endif
IEnumerator<KeyValuePair<TKey, TValue>> {
/// <summary>Initializes a new multi dictionary enumerator</summary>
/// <param name="dictionary">Dictionary that will be enumerated</param>
@ -125,6 +128,8 @@ namespace Nuclex.Support.Collections {
#region IDictionaryEnumerator implementation
#if !WINRT
/// <summary>The current entry the enumerator is pointing to</summary>
DictionaryEntry IDictionaryEnumerator.Entry {
get {
@ -136,15 +141,6 @@ namespace Nuclex.Support.Collections {
}
}
/// <summary>
/// Throws an exception if the enumerator is not on a valid position
/// </summary>
private void enforceEnumeratorOnValidPosition() {
if(this.currentValue == null) {
throw new InvalidOperationException("Enumerator is not on a valid position");
}
}
/// <summary>The current dictionary key</summary>
object IDictionaryEnumerator.Key {
get {
@ -161,8 +157,19 @@ namespace Nuclex.Support.Collections {
}
}
#endif // !WINRT
#endregion // IDictionaryEnumerator implementation
/// <summary>
/// Throws an exception if the enumerator is not on a valid position
/// </summary>
private void enforceEnumeratorOnValidPosition() {
if(this.currentValue == null) {
throw new InvalidOperationException("Enumerator is not on a valid position");
}
}
/// <summary>Dictionary over whose entries the enumerator is enumerating</summary>
private IDictionary<TKey, ICollection<TValue>> dictionary;
/// <summary>Current key the enumerator is at</summary>
@ -220,7 +227,9 @@ namespace Nuclex.Support.Collections {
/// <param name="dictionary">Dictionary the multi dictionary will be based on</param>
internal MultiDictionary(IDictionary<TKey, ICollection<TValue>> dictionary) {
this.typedDictionary = dictionary;
#if !WINRT
this.objectDictionary = (this.typedDictionary as IDictionary);
#endif
foreach(ICollection<TValue> values in dictionary.Values) {
this.count += values.Count;
@ -402,8 +411,10 @@ namespace Nuclex.Support.Collections {
/// <summary>The wrapped Dictionary under its type-safe interface</summary>
private IDictionary<TKey, ICollection<TValue>> typedDictionary;
#if !WINRT
/// <summary>The wrapped Dictionary under its object interface</summary>
private IDictionary objectDictionary;
#endif
/// <summary>The number of items currently in the multi dictionary</summary>
private int count;
/// <summary>Provides the values stores in the dictionary in sequence</summary>

View File

@ -40,7 +40,11 @@ namespace Nuclex.Support.Collections {
IDeserializationCallback,
#endif
IDictionary<TKey, TValue>,
#if WINRT
ICollection,
#else
IDictionary,
#endif
#if !NO_SPECIALIZED_COLLECTIONS
INotifyCollectionChanged,
#endif
@ -329,6 +333,8 @@ namespace Nuclex.Support.Collections {
#region IDictionary implementation
#if !WINRT
/// <summary>Adds an item into the Dictionary</summary>
/// <param name="key">Key under which the item will be added</param>
/// <param name="value">Item that will be added</param>
@ -344,12 +350,6 @@ namespace Nuclex.Support.Collections {
return this.objectDictionary.Contains(key);
}
/// <summary>Returns a new entry enumerator for the dictionary</summary>
/// <returns>The new entry enumerator</returns>
IDictionaryEnumerator IDictionary.GetEnumerator() {
return this.objectDictionary.GetEnumerator();
}
/// <summary>Whether the size of the Dictionary is fixed</summary>
bool IDictionary.IsFixedSize {
get { return this.objectDictionary.IsFixedSize; }
@ -395,7 +395,23 @@ namespace Nuclex.Support.Collections {
}
}
#endregion
#endif // !WINRT
#endregion // IDictionary implementation
#region IDictionaryEnumerator implementation
#if !WINRT
/// <summary>Returns a new entry enumerator for the dictionary</summary>
/// <returns>The new entry enumerator</returns>
IDictionaryEnumerator IDictionary.GetEnumerator() {
return this.objectDictionary.GetEnumerator();
}
#endif // !WINRT
#endregion // IDictionaryEnumerator implementation
#region ICollection<> implementation
@ -477,8 +493,10 @@ namespace Nuclex.Support.Collections {
/// <summary>The wrapped Dictionary under its type-safe interface</summary>
private IDictionary<TKey, TValue> typedDictionary;
#if !WINRT
/// <summary>The wrapped Dictionary under its object interface</summary>
private IDictionary objectDictionary;
#endif
}

View File

@ -37,8 +37,12 @@ namespace Nuclex.Support.Collections {
ISerializable,
IDeserializationCallback,
#endif
IDictionary<KeyType, ValueType>,
IDictionary {
#if WINRT
ICollection,
#else
IDictionary,
#endif
IDictionary<KeyType, ValueType> {
#if !NO_SERIALIZATION
@ -233,6 +237,8 @@ namespace Nuclex.Support.Collections {
#region IDictionary implementation
#if !WINRT
/// <summary>Removes all items from the Dictionary</summary>
void IDictionary.Clear() {
throw new NotSupportedException(
@ -256,12 +262,6 @@ namespace Nuclex.Support.Collections {
return this.objectDictionary.Contains(key);
}
/// <summary>Returns a new entry enumerator for the dictionary</summary>
/// <returns>The new entry enumerator</returns>
IDictionaryEnumerator IDictionary.GetEnumerator() {
return this.objectDictionary.GetEnumerator();
}
/// <summary>Whether the size of the Dictionary is fixed</summary>
bool IDictionary.IsFixedSize {
get { return this.objectDictionary.IsFixedSize; }
@ -313,7 +313,23 @@ namespace Nuclex.Support.Collections {
}
}
#endregion
#endif // !WINRT
#endregion // IDictionary implementation
#region IDictionaryEnumerator implementation
#if !WINRT
/// <summary>Returns a new entry enumerator for the dictionary</summary>
/// <returns>The new entry enumerator</returns>
IDictionaryEnumerator IDictionary.GetEnumerator() {
return this.objectDictionary.GetEnumerator();
}
#endif // !WINRT
#endregion // IDictionaryEnumerator implementation
#region ICollection<> implementation
@ -394,8 +410,10 @@ namespace Nuclex.Support.Collections {
/// <summary>The wrapped Dictionary under its type-safe interface</summary>
private IDictionary<KeyType, ValueType> typedDictionary;
#if !WINRT
/// <summary>The wrapped Dictionary under its object interface</summary>
private IDictionary objectDictionary;
#endif
/// <summary>ReadOnly wrapper for the keys collection of the Dictionary</summary>
private ReadOnlyCollection<KeyType> readonlyKeyCollection;
/// <summary>ReadOnly wrapper for the values collection of the Dictionary</summary>

View File

@ -58,7 +58,33 @@ namespace Nuclex.Support {
#endregion // class MemberInfoComparer
#if !(XBOX360 || WINDOWS_PHONE)
#if WINRT
/// <summary>
/// Returns all the fields of a type, including those defined in the type's base classes
/// </summary>
/// <param name="type">Type whose fields will be returned</param>
/// <param name="bindingFlags">Binding flags to use when querying the fields</param>
/// <returns>All of the type's fields, including its base types</returns>
public static FieldInfo[] GetFieldInfosIncludingBaseClasses(this Type type) {
var fieldInfoSet = new HashSet<FieldInfo>(fieldInfos, FieldInfoComparer.Default);
while(type != typeof(object)) {
TypeInfo typeInfo = type.GetTypeInfo();
foreach(FieldInfo fieldInfo in typeInfo.DeclaredFields) {
fieldInfoSet.Add(fieldInfo);
}
type = typeInfo.BaseType;
}
FieldInfo[] fieldInfos = new FieldInfo[fieldInfoSet.Count];
fieldInfoSet.CopyTo(fieldInfos, 0);
return fieldInfos;
}
#elif !(XBOX360 || WINDOWS_PHONE)
/// <summary>
/// Returns all the fields of a type, including those defined in the type's base classes
@ -140,6 +166,23 @@ namespace Nuclex.Support {
#endif // !(XBOX360 || WINDOWS_PHONE)
#if WINRT
/// <summary>Determines whether the given type has a default constructor</summary>
/// <param name="type">Type which is to be checked</param>
/// <returns>True if the type has a default constructor</returns>
public static bool HasDefaultConstructor(this Type type) {
foreach(ConstructorInfo constructorInfo in type.GetTypeInfo().DeclaredConstructors) {
if(constructorInfo.IsPublic && (constructorInfo.GetParameters().Length == 0)) {
return true;
}
}
return false;
}
#else
/// <summary>Determines whether the given type has a default constructor</summary>
/// <param name="type">Type which is to be checked</param>
/// <returns>True if the type has a default constructor</returns>
@ -156,6 +199,8 @@ namespace Nuclex.Support {
return false;
}
#endif
/// <summary>Determines whether the type has the specified attribute</summary>
/// <typeparam name="TAttribute">Attribute the type will be checked for</typeparam>
/// <param name="type">
@ -166,6 +211,20 @@ namespace Nuclex.Support {
return type.HasAttribute(typeof(TAttribute));
}
#if WINRT
/// <summary>Determines whether the type has the specified attribute</summary>
/// <param name="type">
/// Type that will be checked for presence of the specified attribute
/// </param>
/// <param name="attributeType">Attribute the type will be checked for</typeparam>
/// <returns>True if the type has the specified attribute, otherwise false</returns>
public static bool HasAttribute(this Type type, Type attributeType) {
return (type.GetTypeInfo().GetCustomAttribute(attributeType) != null);
}
#else
/// <summary>Determines whether the type has the specified attribute</summary>
/// <param name="type">
/// Type that will be checked for presence of the specified attribute
@ -177,6 +236,8 @@ namespace Nuclex.Support {
return (attributes != null) && (attributes.Length > 0);
}
#endif
}
} // namespace Nuclex.Support