关于DataGrid 取选中行的值时Mscorlib_CollectionDebugView问题
程序员文章站
2022-07-14 08:37:47
...
当Mscorlib_CollectionDebugView解析不出来时,可添加如下的namespace,原理不太清楚,是我在microsoft官网上查询相关的类,添加出来的,Generic里应该不需要那么多的类,节省时间,我基本上都粘贴复制了,能用就好
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Collections.ObjectModel;
using System.Security.Permissions;
namespace System.Collections.Generic
{
using System;
using System.Collections.ObjectModel;
using System.Security.Permissions;
using System.Diagnostics;
using System.Diagnostics.Contracts;
//
// VS IDE can't differentiate between types with the same name from different
// assembly. So we need to use different names for collection debug view for
// collections in mscorlib.dll and system.dll.
//
public sealed class Mscorlib_CollectionDebugView<T>
{
private ICollection<T> collection;
public Mscorlib_CollectionDebugView(ICollection<T> collection)
{
if (collection == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
this.collection = collection;
}
internal static class ThrowHelper
{
internal static void ThrowArgumentNullException(ExceptionArgument argument)
{
throw new System.ArgumentNullException(GetArgumentName(argument));
}
}
internal enum ExceptionArgument
{
obj,
dictionary,
dictionaryCreationThreshold,
array,
info,
key,
collection,
list,
match,
converter,
queue,
stack,
capacity,
index,
startIndex,
value,
count,
arrayIndex,
name,
mode,
item,
options,
view,
sourceBytesToCopy,
}
internal static string GetArgumentName(ExceptionArgument argument)
{
string argumentName = null;
switch (argument)
{
case ExceptionArgument.array:
argumentName = "array";
break;
case ExceptionArgument.arrayIndex:
argumentName = "arrayIndex";
break;
case ExceptionArgument.capacity:
argumentName = "capacity";
break;
case ExceptionArgument.collection:
argumentName = "collection";
break;
case ExceptionArgument.list:
argumentName = "list";
break;
case ExceptionArgument.converter:
argumentName = "converter";
break;
case ExceptionArgument.count:
argumentName = "count";
break;
case ExceptionArgument.dictionary:
argumentName = "dictionary";
break;
case ExceptionArgument.dictionaryCreationThreshold:
argumentName = "dictionaryCreationThreshold";
break;
case ExceptionArgument.index:
argumentName = "index";
break;
case ExceptionArgument.info:
argumentName = "info";
break;
case ExceptionArgument.key:
argumentName = "key";
break;
case ExceptionArgument.match:
argumentName = "match";
break;
case ExceptionArgument.obj:
argumentName = "obj";
break;
case ExceptionArgument.queue:
argumentName = "queue";
break;
case ExceptionArgument.stack:
argumentName = "stack";
break;
case ExceptionArgument.startIndex:
argumentName = "startIndex";
break;
case ExceptionArgument.value:
argumentName = "value";
break;
case ExceptionArgument.name:
argumentName = "name";
break;
case ExceptionArgument.mode:
argumentName = "mode";
break;
case ExceptionArgument.item:
argumentName = "item";
break;
case ExceptionArgument.options:
argumentName = "options";
break;
case ExceptionArgument.view:
argumentName = "view";
break;
case ExceptionArgument.sourceBytesToCopy:
argumentName = "sourceBytesToCopy";
break;
default:
Contract.Assert(false, "The enum value is not defined, please checked ExceptionArgumentName Enum.");
return string.Empty;
}
return argumentName;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public T[] Items
{
get
{
T[] items = new T[collection.Count];
collection.CopyTo(items, 0);
return items;
}
}
}
}
上一篇: WPF设置ListBoxItem失去焦点时的背景色不生效的问题
下一篇: L - 12 C++