Extension Methods are great C# feature and I will share some of my own extension methods that will help you in your applications. This repository will be constantly updated.
Extension Methods are a C# feature where is possible to add other methods to existing types without any effort (string, int, objects) and do not need to inheriate from those types. To use Extension Methods is necessary to reference the corresponding namespace.
What is in the source code?
– FSLBrowserCapabilitiesExtension – Extensions for check browser version;
– FSLCollectionExtension – Extensions to work with collections;
– FSLEnumExtension – Extensions for Enum;
– FSLIsNullExtension – Extensions to check nullable objects;
– FSLQueryStringExtension – Extensions to work with query string;
– FSLSerializationExtension – Extensions to serialize objects;
– FSLStringExtension – Extensions for string type;
var name = someVariableName.IsNull("fabio"); //if someVariableName is null returns "fabio" var obj = someObject.IsNull(); //if someObject is null returns a new instance of someObject var strEnum = "September".ToEnum<Months>(); //will convert "September" string to Months Enum var qs = Request.QueryString.GetSecure("culture").IsNull("en-US"); //will return the value of querystring "culture" in secure mode. If is null, returns "en-US" as default var xml = someObject.ToXml(); //serializes someObject to XML; var xml = someObject.ToJson(); //serializes someObject to Json; var instance = someList.FirstOrNew(); //return the first item of collection, if there is no item, returns a new instance;
This is it. I hope it helped.
C# Useful Extension Methods – part 1
Extension Methods in C#: Questions, suggestions and feedbacks will be appreciated. Good luck!
|Do complete download of the source code on github.|