浏览代码

ListView - handle null collection

Jamie D 5 年之前
父节点
当前提交
ef5b114317
共有 1 个文件被更改,包括 7 次插入5 次删除
  1. 7 5
      Terminal.Gui/Views/ListView.cs

+ 7 - 5
Terminal.Gui/Views/ListView.cs

@@ -551,15 +551,17 @@ namespace Terminal.Gui {
 		/// <param name="source"></param>
 		/// <param name="source"></param>
 		public ListWrapper (IList source)
 		public ListWrapper (IList source)
 		{
 		{
-			count = source.Count;
-			marks = new BitArray (count);
-			this.src = source;
+			if (source != null) {
+				count = source.Count;
+				marks = new BitArray (count);
+				this.src = source;
+			}
 		}
 		}
 
 
 		/// <summary>
 		/// <summary>
 		/// Gets the number of items in the <see cref="IList"/>.
 		/// Gets the number of items in the <see cref="IList"/>.
 		/// </summary>
 		/// </summary>
-		public int Count => src.Count;
+		public int Count => Convert.ToInt32 (src?.Count);
 
 
 		void RenderUstr (ConsoleDriver driver, ustring ustr, int col, int line, int width)
 		void RenderUstr (ConsoleDriver driver, ustring ustr, int col, int line, int width)
 		{
 		{
@@ -594,7 +596,7 @@ namespace Terminal.Gui {
 			container.Move (col, line);
 			container.Move (col, line);
 			var t = src [item];
 			var t = src [item];
 			if (t == null) {
 			if (t == null) {
-				RenderUstr (driver, ustring.Make(""), col, line, width);
+				RenderUstr (driver, ustring.Make (""), col, line, width);
 			} else {
 			} else {
 				if (t is ustring) {
 				if (t is ustring) {
 					RenderUstr (driver, (ustring)t, col, line, width);
 					RenderUstr (driver, (ustring)t, col, line, width);