Saturday, June 27, 2015

Friday, June 26, 2015

Resharper - Surround code with etc.

https://www.jetbrains.com/resharper/documentation/help20/Templates/SurroundWith/predefSurroundWith.html

Ctrl + Alt + J

C# - Get Web.config Variable Value


Example value in web.config:

 <appSettings>  
    <add key="ClientId" value="123"/>  
    <add key ="webUrl" value="http://www.nasa.gov/"/>  
  </appSettings>  

C# Get:

 using System.Configuration;  
 string ClientId=ConfigurationManager.AppSettings["ClientId"] 
 string webUrl=ConfigurationManager.AppSettings["webUrl"] 

Jadda jadda null check on string ClientId and webUrl.

Monday, June 8, 2015

C# - Stripping all html from string fast!

Code example:


 /// <summary>  
     /// Compiled regular expression for performance.  
     /// </summary>  
     static Regex _htmlRegex = new Regex(@"(?></?\w+)(?>(?:[^>'""]+|'[^']*'|""[^""]*"")*)>", RegexOptions.Compiled);  
Alternavtive regex = static Regex _htmlRegex = new Regex(@"</?\w+((\s+\w+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)+\s*|\s*)/?>", RegexOptions.Compiled);

     /// <summary>  
     /// Remove HTML from string with compiled Regex.  
     /// </summary>  
     public static string StripTagsRegexCompiled(string source)  
     {  
       return _htmlRegex.Replace(source, string.Empty);  
     }