#define WEB

using System;
using System.Collections.Generic;
using System.Linq;
#if WEB
using System.Web;
#endif

namespace DesiredClassLibrary
{
    public class DesiredClass
    {
        private string _name;

        public static bool IsWeb()
        {
            #if WEB
                try
                {
                    return ((HttpContext.Current != null) && (HttpRuntime.AppDomainAppId != null));
                }
                catch
                {
                    //exception due to inexistence of HttpContext
                    return false;
                }
            #else
                return false;
            #endif
        }
        
        public virtual string Name 
        { 
            get
            {
                #if WEB
                    return IsWeb() ? System.Web.HttpContext.Current.Session["Name"].ToString() : _name;
                #else
                    return _name;
                #endif
            }
            set
            {
                #if WEB
                    if (IsWeb())
                    {
                        System.Web.HttpContext.Current.Session.Add("Name", value);
                    }
                    else
                    {
                        _name = value;
                    }
                #else
                    _name = value;
                #endif
            }
        }

        public virtual string GetHello()
        {
            return "Hello world, " + Name + "!";
        }
    }
}