public static T As<T>(this object obj) where T : class { return obj as T; } public static bool Contains(this string source, string toCheck, StringComparison comp) { return source.IndexOf(toCheck, comp) >= 0; } public static bool Contains(this IEnumerable<string> container, string toCheck, StringComparison comp) { return container.Any(c => string.Equals(c, toCheck, comp)); } public static string GetDescription(this Enum value) { var field = value.GetType().GetField(value.ToString()); var attribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)).As<DescriptionAttribute>(); return attribute == null ? value.ToString() : attribute.Description; } public static T DeepClone<T>(this T obj) { using (var ms = new MemoryStream()) { var formatter = new BinaryFormatter(); formatter.Serialize(ms, obj); ms.Position = 0; return (T)formatter.Deserialize(ms); } } public static T DeepCloneDataContract<T>(this T obj) { using (var ms = new MemoryStream()) { var dcs = new DataContractSerializer(typeof(T)); dcs.WriteObject(ms, obj); ms.Position = 0; return (T)dcs.ReadObject(ms); } } public static object GetPropValue(this object src, string propName) { try { return src.GetType().GetProperty(propName).GetValue(src, null); } catch { return string.Empty; } } public static string ToExcelColumn(this int columnIndex) { var columnString = ""; var columnNumber = columnIndex; while (columnNumber > 0) { var currentLetterNumber = (columnNumber - 1) % 26; var currentLetter = (char)(currentLetterNumber + 65); columnString = currentLetter + columnString; columnNumber = (columnNumber - (currentLetterNumber + 1)) / 26; } return columnString; } public static int ToColumnIndex(this string excelColumn) { var retVal = 0; var col = excelColumn.ToUpper(); for (var iChar = col.Length - 1; iChar >= 0; iChar--) { var colPiece = col[iChar]; var colNum = colPiece - 64; retVal = retVal + colNum * (int)Math.Pow(26, col.Length - (iChar + 1)); } return retVal; } public static string GetVariableName<T>(this Expression<Func<T>> expr) { return expr.Body.As<MemberExpression>().Member.Name; }
相关推荐
Z.ExtensionMethods, C# 扩展方法|. NET 开放源代码&免费库 使用超过 1000种扩展方法,增强了. NET 架构。下载完整版本 NuGetZ.ExtensionMethods ( 推荐推荐) Z.ExtensionMethods.WithObjectNamespace
How To Use Extension Methods_src
C#例子代码 A0016_ExtensionMethodsC#例子代码 A0016_ExtensionMethodsC#例子代码 A0016_ExtensionMethodsC#例子代码 A0016_ExtensionMethodsC#例子代码 A0016_ExtensionMethodsC#例子代码 A0016_ExtensionMethodsC#...
ComparereTreino1:Treinando Expresses Lambda,Compareson,ExtensionMethods和功能
C#扩展方法我的集合和POCO对象的C#扩展方法。 享受! :collision:您可以通过安装所有它们 :hammer:或最小包装。或必备包(首选)。目录:集合扩展方法(命名空间-Pylypeiev.Extensions):POCO扩展方法(名称空间-...
数据库的增删改查
MVC 3 – Razor View Engine By Jon Galloway|April 4, 2011 In this video you will learn the...In this video, you will learn how to use both extension methods and declarative @helper syntax in Razor views.
Methods and parameters–including extension methods, partial meth­ods, and C# 4.0’s optional and named parameters Generics, concurrent collections, and custom collections with iterators ...
•Examine .NET language extensions and work with extension methods, partial methods, lambda expressions, and query expressions •LINQ to DataSet operators, SQL server operations, XML API, or Active ...
Lm.Common.ExtensionMethods 一些使编码更加方便的扩展方法 Lm.Common.Security.Cryptography 加密 Lm.Common.Threading 同类任务线型、不同类任务并行 Lm.Common.Web web开发中比较便捷的代码 Lm.Common.Web....
Lm.Common.ExtensionMethods 一些使编码更加方便的扩展方法 Lm.Common.Security.Cryptography 加密 Lm.Common.Threading 同类任务线型、不同类任务并行 Lm.Common.Web web开发中比较便捷的代码 Lm.Common.Web....
Lm.Common.ExtensionMethods 一些使编码更加方便的扩展方法 Lm.Common.Security.Cryptography 加密 Lm.Common.Threading 同类任务线型、不同类任务并行 Lm.Common.Web web开发中比较便捷的代码 Lm.Common...
this book covers Visual C# 2008, Visual Studio 2008, and the .NET Framework 3.5, and teaches everything from language fundamentals to advanced topics including garbage collection, extension methods, ...
this book covers Visual C# 2008, Visual Studio 2008, and the .NET Framework 3.5, and teaches everything from language fundamentals to advanced topics including garbage collection, extension methods, ...
this book covers Visual C# 2008, Visual Studio 2008, and the .NET Framework 3.5, and teaches everything from language fundamentals to advanced topics including garbage collection, extension methods, ...
this book covers Visual C# 2008, Visual Studio 2008, and the .NET Framework 3.5, and teaches everything from language fundamentals to advanced topics including garbage collection, extension methods, ...
this book covers Visual C# 2008, Visual Studio 2008, and the .NET Framework 3.5, and teaches everything from language fundamentals to advanced topics including garbage collection, extension methods, ...
this book covers Visual C# 2008, Visual Studio 2008, and the .NET Framework 3.5, and teaches everything from language fundamentals to advanced topics including garbage collection, extension methods, ...
this book covers Visual C# 2008, Visual Studio 2008, and the .NET Framework 3.5, and teaches everything from language fundamentals to advanced topics including garbage collection, extension methods, ...