Commits

Inside Zhou  committed 71deeac

整理一下代码。

  • Participants
  • Parent commits 26f3b63

Comments (0)

Files changed (5)

File IListExtension.cs

-using System;
-using System.Collections;
-using System.Collections.Generic;
-
-namespace Inside.Util {
-	/// <summary>
-	/// 为集合提供扩展方法。
-	/// </summary>
-	public static class IListExtension {
-		/// <summary>
-		/// 从集合中随机选择元素。
-		/// </summary>
-		public static T[] RandomSelect<T>(this IList src, int count = 6) {
-			if(null == src) {
-				throw new ArgumentNullException("src");
-			}
-
-			if(src.Count <= count) {
-				throw new ArgumentException("集合的长度必须大于选择的个数。", "count");
-			}
-
-			var result = new List<T>();
-			for(int i = 0;i < count;++i) {
-				result.Add((T)src[Math.Abs(Guid.NewGuid().GetHashCode()) % src.Count]);
-			}
-
-			return result.ToArray();
-		}
-
-		/// <summary>
-		/// 打乱集合中元素的次序。
-		/// </summary>
-		/// PDL:
-		/// 从尾部开始遍历该集合;
-		/// 每访问一个索引,将其中的元素随机地与剩余索引中的元素交换一次;
-		/// 访问至集合头部的元素时停止。
-		public static void Shuffle(this IList src) {
-			if(null == src || 0 == src.Count) {
-				return;
-			}
-
-			Object tmpForSwap = null;
-			int tmpCursorIndex = 0;
-
-			for(int cursorIndex = src.Count - 1;0 != cursorIndex;--cursorIndex) {
-				/* 生成一个区间在[0.0, 1.0)的随机数,
-				 * 将其与光标索引相乘得到位于[0, cursorIndex)区间的一个随机数。
-				 */
-				tmpCursorIndex = Math.Abs(Guid.NewGuid().GetHashCode()) % cursorIndex;
-
-				tmpForSwap = src[cursorIndex];
-				src[cursorIndex] = src[tmpCursorIndex];
-				src[tmpCursorIndex] = tmpForSwap;
-			}
-		}
-	}
-}

File Inside.Util.csproj

   <ItemGroup>
     <Compile Include="ByteExtension.cs" />
     <Compile Include="DyObj.cs" />
-    <Compile Include="IListExtension.cs" />
+    <Compile Include="ListExtension.cs" />
     <Compile Include="Json\ByteArrayConverter.cs" />
     <Compile Include="Json\DBNullConverter.cs" />
     <Compile Include="Json\DecimalConverter.cs" />
     <Compile Include="Json\JsonHelper.cs" />
     <Compile Include="Json\SimpleDateTimeConverter.cs" />
     <Compile Include="MiscExtension.cs" />
+    <Compile Include="ObjectExtension.cs" />
     <Compile Include="ObjectHelper.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Sql\Condition.cs" />

File ListExtension.cs

+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Inside.Util {
+	public static class ListExtension {
+		/// <summary>
+		/// 从列表中随机选择元素。
+		/// </summary>
+		public static T[] RandomSelect<T>(this IList src, int count = 6) {
+			if(null == src) {
+				throw new ArgumentNullException("src");
+			}
+
+			if(src.Count <= count) {
+				throw new ArgumentException("集合的长度必须大于选择的个数。", "count");
+			}
+
+			var result = new List<T>();
+			for(int i = 0;i < count;++i) {
+				result.Add((T)src[Math.Abs(Guid.NewGuid().GetHashCode()) % src.Count]);
+			}
+
+			return result.ToArray();
+		}
+
+		/// <summary>
+		/// 打乱列表中元素的次序。
+		/// </summary>
+		public static void Shuffle(this IList src) {
+			if(null == src || 0 == src.Count) {
+				return;
+			}
+
+			Object tmpForSwap = null;
+			int tmpCursorIndex = 0;
+
+			for(int cursorIndex = src.Count - 1;0 != cursorIndex;--cursorIndex) {
+				tmpCursorIndex = Math.Abs(Guid.NewGuid().GetHashCode()) % cursorIndex;
+
+				tmpForSwap = src[cursorIndex];
+				src[cursorIndex] = src[tmpCursorIndex];
+				src[tmpCursorIndex] = tmpForSwap;
+			}
+		}
+	}
+}

File ObjectExtension.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Inside.Util {
+	public static class ObjectExtension {
+		public static bool IsNil(this object src) {
+			return ObjectHelper.IsNil(src);
+		}
+	}
+}

File Web/MvcControllerBase.cs

 			this.Debugging = requestContext.HttpContext.IsDebuggingEnabled;
 		}
 
-		protected override void OnActionExecuted(ActionExecutedContext filterContext) {
-			base.OnActionExecuted(filterContext);
-
-			if(!filterContext.Canceled) {
-				this.ViewBag.useragent = this.UserAgent;
-				this.ViewBag.debugging = this.Debugging;
-			}
-		}
-
 		protected ActionResult ViewAsFile(string view_name, string content_type, object model, string file_download_name, string master_name = null) {
 			if(null != model) {
 				this.ViewData.Model = model;