public static IXmlMapping Convert(
     IMapping mapping,
     MappingDictionary mDict,
     bool nameAsXPath)
 {
     if (nameAsXPath && string.IsNullOrWhiteSpace(mapping.GetProperty("XPath")))
     {
         string columnName = mapping.ColumnName;
         mapping.Properties["XPath"] = columnName;
         if (mapping is IXmlMapping)
         {
             (mapping as IXmlMapping).XPath = columnName;
         }
     }
     return(XmlMapping.Convert(mapping, mDict));
 }
 public override void InitRow(DataRow row)
 {
     base.InitRow(row);
     this.Format = !this.Properties.ContainsKey("Format") ? (!this.Properties.ContainsKey("Formatting") ? string.Empty : this.Properties["Formatting"]) : this.Properties["Format"];
     this.XPath  = XmlMapping.GetXPathByMapping((IMapping)this);
 }
        public static string GetXPathByMacro(string xpath, MappingDictionary mDict)
        {
            if (string.IsNullOrWhiteSpace(xpath))
            {
                throw new ArgumentNullException(nameof(xpath));
            }
            if (mDict == null)
            {
                throw new ArgumentNullException(nameof(mDict));
            }
            string[] parameters;
            string   name;

            if (Translator.ParseMacro(xpath, out name, out parameters, out string _))
            {
                object[] array = ((IEnumerable <string>)parameters).Select <string, object>((Func <string, object>)(p => XmlMapping.ProcessParameter(p))).ToArray <object>();
                if (mDict.InnerData.Tables.Contains("_XPathGroup"))
                {
                    string format = mDict.InnerData.Tables["_XPathGroup"].Rows.Cast <DataRow>().Where <DataRow>((Func <DataRow, bool>)(r => string.Format("{0}", r["Name"]) == name)).Select <DataRow, string>((Func <DataRow, string>)(r => string.Format("{0}", r["XPath"]))).FirstOrDefault <string>();
                    if (!string.IsNullOrWhiteSpace(format))
                    {
                        try
                        {
                            return(string.Format(format, array));
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            return(string.Empty);
        }
Example #4
0
 public override void InitRow(DataRow row)
 {
     base.InitRow(row);
     this.XPath = XmlMapping.GetXPathByMapping((IMapping)this);
 }
 public IDictionary <string, IXmlMapping> GetXmlMappings(
     string tableName,
     bool nameAsXPath)
 {
     if (string.IsNullOrWhiteSpace(nameof(tableName)))
     {
         throw new ArgumentNullException(nameof(tableName));
     }
     if (!this.InnerData.Tables.Contains(tableName))
     {
         throw new ArgumentException(string.Format("Invalid table name:{0}", (object)tableName));
     }
     return((IDictionary <string, IXmlMapping>) this.GetMappings(tableName).Cast <KeyValuePair <string, IMapping> >().ToDictionary <KeyValuePair <string, IMapping>, string, IXmlMapping>((Func <KeyValuePair <string, IMapping>, string>)(p => p.Key), (Func <KeyValuePair <string, IMapping>, IXmlMapping>)(p => XmlMapping.Convert(p.Value, this, nameAsXPath))));
 }