﻿// Decompiled with JetBrains decompiler
// Type: MongoDB.Bson.Serialization.BsonClassMap`1
// Assembly: MongoDB.Bson, Version=1.6.1.21837, Culture=neutral, PublicKeyToken=f686731cfb9cc103
// MVID: 93880221-3735-46FB-8891-84D897158E28
// Assembly location: C:\Users\CGA Computer\Desktop\LEGO Universe Stuff\LOCO Server\Unity Web Player Extractor\Saved Files\LOCO Server.unity3d_unpacked\MongoDB.Bson.dll

using MongoDB.Bson;
using System;
using System.Linq.Expressions;
using System.Reflection;

namespace MongoDB.Bson.Serialization
{
  public class BsonClassMap<TClass> : BsonClassMap
  {
    public BsonClassMap()
      : base(typeof (TClass))
    {
    }

    public BsonClassMap(Action<BsonClassMap<TClass>> classMapInitializer)
      : base(typeof (TClass))
    {
      classMapInitializer(this);
    }

    public BsonMemberMap GetMemberMap<TMember>(Expression<Func<TClass, TMember>> memberLambda)
    {
      return this.GetMemberMap(BsonClassMap<TClass>.GetMemberNameFromLambda<TMember>(memberLambda));
    }

    public BsonMemberMap MapExtraElementsField<TMember>(Expression<Func<TClass, TMember>> fieldLambda)
    {
      BsonMemberMap memberMap = this.MapField<TMember>(fieldLambda);
      this.SetExtraElementsMember(memberMap);
      return memberMap;
    }

    public BsonMemberMap MapExtraElementsMember<TMember>(Expression<Func<TClass, TMember>> memberLambda)
    {
      BsonMemberMap memberMap = this.MapMember<TMember>(memberLambda);
      this.SetExtraElementsMember(memberMap);
      return memberMap;
    }

    public BsonMemberMap MapExtraElementsProperty<TMember>(Expression<Func<TClass, TMember>> propertyLambda)
    {
      BsonMemberMap memberMap = this.MapProperty<TMember>(propertyLambda);
      this.SetExtraElementsMember(memberMap);
      return memberMap;
    }

    public BsonMemberMap MapField<TMember>(Expression<Func<TClass, TMember>> fieldLambda)
    {
      return this.MapMember<TMember>(fieldLambda);
    }

    public BsonMemberMap MapIdField<TMember>(Expression<Func<TClass, TMember>> fieldLambda)
    {
      BsonMemberMap memberMap = this.MapField<TMember>(fieldLambda);
      this.SetIdMember(memberMap);
      return memberMap;
    }

    public BsonMemberMap MapIdMember<TMember>(Expression<Func<TClass, TMember>> memberLambda)
    {
      BsonMemberMap memberMap = this.MapMember<TMember>(memberLambda);
      this.SetIdMember(memberMap);
      return memberMap;
    }

    public BsonMemberMap MapIdProperty<TMember>(Expression<Func<TClass, TMember>> propertyLambda)
    {
      BsonMemberMap memberMap = this.MapProperty<TMember>(propertyLambda);
      this.SetIdMember(memberMap);
      return memberMap;
    }

    public BsonMemberMap MapMember<TMember>(Expression<Func<TClass, TMember>> memberLambda)
    {
      return this.MapMember(BsonClassMap<TClass>.GetMemberInfoFromLambda<TMember>(memberLambda));
    }

    public BsonMemberMap MapProperty<TMember>(Expression<Func<TClass, TMember>> propertyLambda)
    {
      return this.MapMember<TMember>(propertyLambda);
    }

    public void UnmapField<TMember>(Expression<Func<TClass, TMember>> fieldLambda)
    {
      this.UnmapMember<TMember>(fieldLambda);
    }

    public void UnmapMember<TMember>(Expression<Func<TClass, TMember>> memberLambda)
    {
      this.UnmapMember(BsonClassMap<TClass>.GetMemberInfoFromLambda<TMember>(memberLambda));
    }

    public void UnmapProperty<TMember>(Expression<Func<TClass, TMember>> propertyLambda)
    {
      this.UnmapMember<TMember>(propertyLambda);
    }

    private static MemberInfo GetMemberInfoFromLambda<TMember>(Expression<Func<TClass, TMember>> memberLambda)
    {
      Expression body = memberLambda.Body;
      MemberExpression memberExpression;
      switch (body.NodeType)
      {
        case ExpressionType.Convert:
          memberExpression = (MemberExpression) ((UnaryExpression) body).Operand;
          break;
        case ExpressionType.MemberAccess:
          memberExpression = (MemberExpression) body;
          break;
        default:
          throw new BsonSerializationException("Invalid lambda expression");
      }
      MemberInfo member = memberExpression.Member;
      switch (member.MemberType)
      {
        case MemberTypes.Field:
        case MemberTypes.Property:
          return member;
        default:
          throw new BsonSerializationException("Invalid lambda expression");
      }
    }

    private static string GetMemberNameFromLambda<TMember>(Expression<Func<TClass, TMember>> memberLambda)
    {
      return BsonClassMap<TClass>.GetMemberInfoFromLambda<TMember>(memberLambda).Name;
    }
  }
}
