2016-09-09 112 views
0

是否可以从类扩展访问会话变量?从类扩展访问会话变量

我在会议设置此变量:

var offset = 3; 
HttpContext.Session.SetInt32("clienttimeoffset", offset); 

而在一个日期时间延长,我需要访问它:

public static DateTime? ToClientTime(this DateTime? value) 
{ 
    if (value == null) 
     return null; 

    var offset = get it here ..... 
    .... 
} 

回答

0

不要访问它的扩展中。将其作为参数传递给扩展方法:

public static DateTime? ToClientTime(this DateTime? value, int offset) 
{ 
    if (value == null) 
     return null; 

     .... 
}