It seems that contrary to what MSDN says, the Dictionary<K, T> class does not have a constructor accepting an IEqualityComparer on the Xbox 360 or Windows Phone 7; added missing documentation in Pool class

git-svn-id: file:///srv/devel/repo-conversion/nusu@270 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2012-03-08 12:05:59 +00:00
parent 58a1652749
commit 97de199705
5 changed files with 85 additions and 58 deletions

View File

@ -279,7 +279,7 @@
</Compile> </Compile>
<Compile Include="Source\TypeHelper.cs" /> <Compile Include="Source\TypeHelper.cs" />
<Compile Include="Source\TypeHelper.Test.cs"> <Compile Include="Source\TypeHelper.Test.cs">
<DependentUpon>\TypeHelper.cs</DependentUpon> <DependentUpon>TypeHelper.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Source\Semaphore.cs" /> <Compile Include="Source\Semaphore.cs" />
<Compile Include="Source\Semaphore.Test.cs"> <Compile Include="Source\Semaphore.Test.cs">

View File

@ -310,7 +310,7 @@
</Compile> </Compile>
<Compile Include="Source\TypeHelper.cs" /> <Compile Include="Source\TypeHelper.cs" />
<Compile Include="Source\TypeHelper.Test.cs"> <Compile Include="Source\TypeHelper.Test.cs">
<DependentUpon>\TypeHelper.cs</DependentUpon> <DependentUpon>TypeHelper.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Source\Semaphore.cs" /> <Compile Include="Source\Semaphore.cs" />
<Compile Include="Source\Semaphore.Test.cs"> <Compile Include="Source\Semaphore.Test.cs">

View File

@ -321,7 +321,7 @@
</Compile> </Compile>
<Compile Include="Source\TypeHelper.cs" /> <Compile Include="Source\TypeHelper.cs" />
<Compile Include="Source\TypeHelper.Test.cs"> <Compile Include="Source\TypeHelper.Test.cs">
<DependentUpon>\TypeHelper.cs</DependentUpon> <DependentUpon>TypeHelper.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Source\Semaphore.cs" /> <Compile Include="Source\Semaphore.cs" />
<Compile Include="Source\Semaphore.Test.cs"> <Compile Include="Source\Semaphore.Test.cs">

View File

@ -166,7 +166,9 @@ namespace Nuclex.Support.Collections {
/// Required because the Queue class doesn't allow this value to be retrieved /// Required because the Queue class doesn't allow this value to be retrieved
/// </remarks> /// </remarks>
private int capacity; private int capacity;
/// <summary>Delegate used to create new instances of the pool's type</summary>
private Func<TItem> createNewDelegate; private Func<TItem> createNewDelegate;
/// <summary>Delegate used to recycle instances</summary>
private Action<TItem> recycleDelegate; private Action<TItem> recycleDelegate;
} }

View File

@ -27,6 +27,8 @@ namespace Nuclex.Support {
/// <summary>Helper methods for the reflection Type class</summary> /// <summary>Helper methods for the reflection Type class</summary>
public static class TypeHelper { public static class TypeHelper {
#if !(XBOX360 || WINDOWS_PHONE)
#region class MemberInfoComparer #region class MemberInfoComparer
/// <summary>Determines whether member informations relate to the same member</summary> /// <summary>Determines whether member informations relate to the same member</summary>
@ -58,60 +60,6 @@ namespace Nuclex.Support {
#endregion // class MemberInfoComparer #endregion // class MemberInfoComparer
/// <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) {
ConstructorInfo[] constructors = type.GetConstructors();
for(int index = 0; index < constructors.Length; ++index) {
ConstructorInfo constructor = constructors[index];
if(constructor.IsPublic && (constructor.GetParameters().Length == 0)) {
return true;
}
}
return false;
}
#if XBOX || WINDOWS_PHONE
/// <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, BindingFlags bindingFlags
) {
FieldInfo[] fieldInfos = type.GetFields(bindingFlags);
// If this class doesn't have a base, don't waste any time
if(type.BaseType != typeof(object)) {
var fieldInfoSet = new Dictionary<FieldInfo, object>(MemberInfoComparer.Default);
for(int index = 0; index < fieldInfos.Length; ++index) {
fieldInfoSet.Add(fieldInfos[index], null);
}
while(type.BaseType != typeof(object)) {
type = type.BaseType;
fieldInfos = type.GetFields(bindingFlags);
for(int index = 0; index < fieldInfos.Length; ++index) {
FieldInfo fieldInfo = fieldInfos[index];
if(!fieldInfoSet.ContainsKey(fieldInfo)) {
fieldInfoSet.Add(fieldInfo, null);
}
}
}
fieldInfos = new FieldInfo[fieldInfoSet.Count];
fieldInfoSet.Keys.CopyTo(fieldInfos, 0);
}
return fieldInfos;
}
#else
/// <summary> /// <summary>
/// Returns all the fields of a type, including those defined in the type's base classes /// Returns all the fields of a type, including those defined in the type's base classes
/// </summary> /// </summary>
@ -140,7 +88,84 @@ namespace Nuclex.Support {
return fieldInfos; return fieldInfos;
} }
#endif
#else // !(XBOX360 || WINDOWS_PHONE)
/// <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, BindingFlags bindingFlags
) {
FieldInfo[] fieldInfos = type.GetFields(bindingFlags);
// If this class doesn't have a base, don't waste any time
if(type.BaseType != typeof(object)) {
var fieldInfoList = new List<FieldInfo>(fieldInfos.Length * 2);
for(int index = 0; index < fieldInfos.Length; ++index) {
fieldInfoList.Add(fieldInfos[index]);
}
while(type.BaseType != typeof(object)) {
type = type.BaseType;
fieldInfos = type.GetFields(bindingFlags);
for(int index = 0; index < fieldInfos.Length; ++index) {
addIfNotExists(fieldInfoList, fieldInfos[index]);
}
}
fieldInfos = fieldInfoList.ToArray();
}
return fieldInfos;
}
/// <summary>
/// Adds field informations to a list if they're not already contained in it
/// </summary>
/// <param name="fieldInfos">List the field informations will be added to</param>
/// <param name="fieldInfo">Field informations that will be added to the list</param>
private static void addIfNotExists(IList<FieldInfo> fieldInfos, FieldInfo fieldInfo) {
bool matchFound = false;
for(int index = 0; index < fieldInfos.Count; ++index) {
FieldInfo current = fieldInfos[index];
matchFound =
(current.DeclaringType == fieldInfo.DeclaringType) &&
(current.Name == fieldInfo.Name);
if(matchFound) {
break;
}
}
if(!matchFound) {
fieldInfos.Add(fieldInfo);
}
}
#endif // !(XBOX360 || WINDOWS_PHONE)
/// <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) {
ConstructorInfo[] constructors = type.GetConstructors();
for(int index = 0; index < constructors.Length; ++index) {
ConstructorInfo constructor = constructors[index];
if(constructor.IsPublic && (constructor.GetParameters().Length == 0)) {
return true;
}
}
return false;
}
} }