{
public static class WebExtensions
{
+
public static string ReadToEnd(this HttpWebResponse response)
{
using (var stream = response.GetResponseStream())
}
}
- public static TextReader GetLoggedReader(this Stream stream, ILog log, long contentLength)
+ public static TextReader GetLoggedReader(this Stream stream, ILog log)
{
var reader = new StreamReader(stream);
if (!log.IsDebugEnabled)
using (reader)
{
- var buffer=new char[contentLength];
- var read=reader.Read(buffer, 0, (int)contentLength);
- var body = new string(buffer,0,read); //reader.ReadToEnd();
+ var body = reader.ReadToEnd();
log.DebugFormat("JSON response: {0}", body);
return new StringReader(body);
}
}
+
+
+ public static TOut NullSafe<TIn, TOut>(this TIn obj, Func<TIn, TOut> memberAction)
+ {
+ //Note we should not use obj != null because it can not test value types and also
+ //compiler has to lift the type to a nullable type for doing the comparision with null.
+ return (!EqualityComparer<TIn>.Default.Equals(obj, default(TIn))) ? memberAction(obj) : default(TOut);
+
+ }
+
+
+
+
}
}