Convertir la valeur d’un attribut en ‘Int64’

Author:

Utilisation,de,la,classe,'XmlTextReader',pour,lire,un,document,XML
{filelink=16400}

/*
  Microsoft Public License (Ms-PL)
  http://dbmlmanager.codeplex.com/license
  */
#region using
using System;
using System.Xml;
#endregion

namespace DbmlManager.Lib.Utility
{
  #region Class Docs
  ///

  /// Summary description for XmlUtil.
  /// 

  #endregion

  public class XmlUtil
  {

    #region GetAttrib(XmlNode noeud, string attrib, string valDefaut)
    public static string GetAttrib(XmlNode noeud, string attrib, string valDefaut)
    {
      XmlAttribute xmlAttrib = noeud.Attributes[attrib];
      if (xmlAttrib == null)
        return valDefaut;

      string val = xmlAttrib.Value;
      return (val == null) ? valDefaut : val;
    }
    #endregion
    #region GetInt64Attrib(XmlNode noeud, string attrib, Int64 valDefaut)
    public static Int64 GetInt64Attrib(XmlNode noeud, string attrib, Int64 valDefaut)
    {
      XmlAttribute xmlAttrib = noeud.Attributes[attrib];
      if (xmlAttrib == null)
        return valDefaut;

      string val = xmlAttrib.Value;
      if (val == null || val == string.Empty)
        return valDefaut;

      Int64 returnVal = valDefaut;
      Int64.TryParse(val, out returnVal);

      return returnVal;
    }
    #endregion
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *