Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Caching;
- using System.Web.Mvc;
- namespace Core.Web {
- public static class HttpContextExtentions {
- public static T GetOrAdd<T>(this HttpContext context,object key,Func<T> notFoundFunc = null) {
- if(key == null)
- throw new ArgumentNullException("object key");
- T result = (T)context.Items[key];
- if(result == null) {
- if(notFoundFunc != null) {
- result = notFoundFunc();
- context.Items.Add(key,result);
- return result;
- }
- return default(T);
- }
- return result;
- }
- }
- public static class HtmlHelperExtentions {
- public static IDictionary<string,object> GetClassAttribute(this HtmlHelper html,string className,IDictionary<string,object> additionalAttributes = null) {
- IDictionary<string,object> dict = null;
- if(additionalAttributes != null)
- dict = new Dictionary<string,object>(additionalAttributes);
- else
- dict = new Dictionary<string,object>();
- object previousClassName = null;
- if(dict.TryGetValue("class",out previousClassName)) {
- dict["class"] = previousClassName.ToStringEmpty() + " " + className;
- }
- else {
- dict.Add("class",className);
- }
- return dict;
- }
- public static MvcHtmlString WrapEmailAnchor(this HtmlHelper html,string innerHtml,string nameAndId = null,string title = null) {
- TagBuilder anchor = new TagBuilder("a");
- anchor.GenerateId(nameAndId);
- anchor.MergeAttribute("href","mailto:{0}".FormatString(innerHtml));
- anchor.MergeAttribute("title",title);
- anchor.InnerHtml = innerHtml;
- return MvcHtmlString.Create(anchor.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment