﻿// Decompiled with JetBrains decompiler
// Type: log4net.ObjectRenderer.RendererMap
// Assembly: log4net_webplayer, Version=1.2.10.9, Culture=neutral, PublicKeyToken=null
// MVID: 264EA252-48EC-47A6-AEFF-91CFCAAFCFCB
// Assembly location: C:\Users\CGA Computer\Desktop\LEGO Universe Stuff\LOCO Server\Unity Web Player Extractor\Saved Files\LOCO Server.unity3d_unpacked\log4net_webplayer.dll

using log4net.Util;
using System;
using System.Collections;
using System.Globalization;
using System.IO;

namespace log4net.ObjectRenderer
{
  public class RendererMap
  {
    private static IObjectRenderer s_defaultRenderer = (IObjectRenderer) new log4net.ObjectRenderer.DefaultRenderer();
    private Hashtable m_cache = new Hashtable();
    private Hashtable m_map;

    public IObjectRenderer DefaultRenderer
    {
      get
      {
        return RendererMap.s_defaultRenderer;
      }
    }

    public RendererMap()
    {
      this.m_map = Hashtable.Synchronized(new Hashtable());
    }

    public string FindAndRender(object obj)
    {
      string str = obj as string;
      if (str != null)
        return str;
      StringWriter stringWriter = new StringWriter((IFormatProvider) CultureInfo.InvariantCulture);
      this.FindAndRender(obj, (TextWriter) stringWriter);
      return stringWriter.ToString();
    }

    public void FindAndRender(object obj, TextWriter writer)
    {
      if (obj == null)
      {
        writer.Write(SystemInfo.NullText);
      }
      else
      {
        string str1 = obj as string;
        if (str1 != null)
        {
          writer.Write(str1);
        }
        else
        {
          try
          {
            this.Get(obj.GetType()).RenderObject(this, obj, writer);
          }
          catch (Exception ex)
          {
            LogLog.Error("RendererMap: Exception while rendering object of type [" + obj.GetType().FullName + "]", ex);
            string str2 = "";
            if (obj != null && obj.GetType() != null)
              str2 = obj.GetType().FullName;
            writer.Write("<log4net.Error>Exception rendering object type [" + str2 + "]");
            if (ex != null)
            {
              string str3 = (string) null;
              try
              {
                str3 = ex.ToString();
              }
              catch
              {
              }
              writer.Write("<stackTrace>" + str3 + "</stackTrace>");
            }
            writer.Write("</log4net.Error>");
          }
        }
      }
    }

    public IObjectRenderer Get(object obj)
    {
      if (obj == null)
        return (IObjectRenderer) null;
      return this.Get(obj.GetType());
    }

    public IObjectRenderer Get(Type type)
    {
      if (type == null)
        throw new ArgumentNullException("type");
      IObjectRenderer objectRenderer = (IObjectRenderer) this.m_cache[(object) type];
      if (objectRenderer == null)
      {
        for (Type type1 = type; type1 != null; type1 = type1.BaseType)
        {
          objectRenderer = this.SearchTypeAndInterfaces(type1);
          if (objectRenderer != null)
            break;
        }
        if (objectRenderer == null)
          objectRenderer = RendererMap.s_defaultRenderer;
        this.m_cache[(object) type] = (object) objectRenderer;
      }
      return objectRenderer;
    }

    private IObjectRenderer SearchTypeAndInterfaces(Type type)
    {
      IObjectRenderer objectRenderer1 = (IObjectRenderer) this.m_map[(object) type];
      if (objectRenderer1 != null)
        return objectRenderer1;
      foreach (Type type1 in type.GetInterfaces())
      {
        IObjectRenderer objectRenderer2 = this.SearchTypeAndInterfaces(type1);
        if (objectRenderer2 != null)
          return objectRenderer2;
      }
      return (IObjectRenderer) null;
    }

    public void Clear()
    {
      this.m_map.Clear();
      this.m_cache.Clear();
    }

    public void Put(Type typeToRender, IObjectRenderer renderer)
    {
      this.m_cache.Clear();
      if (typeToRender == null)
        throw new ArgumentNullException("typeToRender");
      if (renderer == null)
        throw new ArgumentNullException("renderer");
      this.m_map[(object) typeToRender] = (object) renderer;
    }
  }
}
