﻿// Decompiled with JetBrains decompiler
// Type: System.Xml.Serialization.XmlMapping
// Assembly: System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 50ABAB51-7DC3-4F0A-A797-0D0C2D124D60
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Xml.dll

using System;
using System.Reflection;
using System.Runtime;
using System.Xml;

namespace System.Xml.Serialization
{
  /// <summary>
  /// Supports mappings between .NET Framework types and XML Schema data types.
  /// </summary>
  [__DynamicallyInvokable]
  public abstract class XmlMapping
  {
    private TypeScope scope;
    private bool generateSerializer;
    private bool isSoap;
    private ElementAccessor accessor;
    private string key;
    private bool shallow;
    private XmlMappingAccess access;

    internal ElementAccessor Accessor
    {
      [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get
      {
        return this.accessor;
      }
    }

    internal TypeScope Scope
    {
      [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get
      {
        return this.scope;
      }
    }

    /// <summary>
    /// Get the name of the mapped element.
    /// </summary>
    /// 
    /// <returns>
    /// The name of the mapped element.
    /// </returns>
    [__DynamicallyInvokable]
    public string ElementName
    {
      [__DynamicallyInvokable] get
      {
        return System.Xml.Serialization.Accessor.UnescapeName(this.Accessor.Name);
      }
    }

    /// <summary>
    /// Gets the name of the XSD element of the mapping.
    /// </summary>
    /// 
    /// <returns>
    /// The XSD element name.
    /// </returns>
    [__DynamicallyInvokable]
    public string XsdElementName
    {
      [__DynamicallyInvokable] get
      {
        return this.Accessor.Name;
      }
    }

    /// <summary>
    /// Gets the namespace of the mapped element.
    /// </summary>
    /// 
    /// <returns>
    /// The namespace of the mapped element.
    /// </returns>
    [__DynamicallyInvokable]
    public string Namespace
    {
      [__DynamicallyInvokable] get
      {
        return this.accessor.Namespace;
      }
    }

    internal bool GenerateSerializer
    {
      [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get
      {
        return this.generateSerializer;
      }
      [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] set
      {
        this.generateSerializer = value;
      }
    }

    internal bool IsReadable
    {
      get
      {
        return (this.access & XmlMappingAccess.Read) != XmlMappingAccess.None;
      }
    }

    internal bool IsWriteable
    {
      get
      {
        return (this.access & XmlMappingAccess.Write) != XmlMappingAccess.None;
      }
    }

    internal bool IsSoap
    {
      [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get
      {
        return this.isSoap;
      }
      [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] set
      {
        this.isSoap = value;
      }
    }

    internal string Key
    {
      [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get
      {
        return this.key;
      }
    }

    [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
    internal XmlMapping(TypeScope scope, ElementAccessor accessor)
      : this(scope, accessor, XmlMappingAccess.Read | XmlMappingAccess.Write)
    {
    }

    internal XmlMapping(TypeScope scope, ElementAccessor accessor, XmlMappingAccess access)
    {
      this.scope = scope;
      this.accessor = accessor;
      this.access = access;
      this.shallow = scope == null;
    }

    /// <summary>
    /// Sets the key used to look up the mapping.
    /// </summary>
    /// <param name="key">A <see cref="T:System.String"/> that contains the lookup key.</param>
    [__DynamicallyInvokable]
    [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
    public void SetKey(string key)
    {
      this.SetKeyInternal(key);
    }

    internal void SetKeyInternal(string key)
    {
      this.key = key;
    }

    internal static string GenerateKey(Type type, XmlRootAttribute root, string ns)
    {
      if (root == null)
        root = (XmlRootAttribute) XmlAttributes.GetAttr((ICustomAttributeProvider) type, typeof (XmlRootAttribute));
      return type.FullName + ":" + (root == null ? string.Empty : root.Key) + ":" + (ns == null ? string.Empty : ns);
    }

    internal void CheckShallow()
    {
      if (this.shallow)
        throw new InvalidOperationException(Res.GetString("XmlMelformMapping"));
    }

    internal static bool IsShallow(XmlMapping[] mappings)
    {
      for (int index = 0; index < mappings.Length; ++index)
      {
        if (mappings[index] == null || mappings[index].shallow)
          return true;
      }
      return false;
    }
  }
}
