-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathExtensions.cs
62 lines (54 loc) · 2.13 KB
/
Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System.Xml;
using System.Xml.Linq;
using System.IO;
namespace OpenKNXproducer
{
public static class ExtensionMethods
{
public static string NodeAttr(this XmlNode iNode, string iAttributeName, string iDefault = "")
{
string lResult = iDefault;
XmlNode lAttribute = iNode.Attributes.GetNamedItem(iAttributeName);
if (lAttribute != null) lResult = lAttribute.Value.ToString();
return lResult;
}
public static string SubId(this XmlNode iNode, string iAttributeName, string iIdSeparator)
{
string lValue = iNode.NodeAttr(iAttributeName, iIdSeparator).Split(iIdSeparator)[1];
return lValue;
}
public static XmlDocument ToXmlDocument(this XDocument xDocument)
{
var xmlDocument = new XmlDocument();
using (var xmlReader = xDocument.CreateReader())
{
xmlDocument.Load(xmlReader);
}
return xmlDocument;
}
public static XDocument ToXDocument(this XmlDocument xmlDocument)
{
using (var nodeReader = new XmlNodeReader(xmlDocument))
{
// nodeReader.MoveToContent();
return XDocument.Load(nodeReader);
}
}
public static void DeepCopy(this DirectoryInfo directory, string destinationDir)
{
Directory.CreateDirectory(destinationDir);
foreach (string dir in Directory.GetDirectories(directory.FullName, "*", SearchOption.AllDirectories))
{
string dirToCreate = dir.Replace(directory.FullName, destinationDir);
Directory.CreateDirectory(dirToCreate);
}
foreach (string newPath in Directory.GetFiles(directory.FullName, "*.*", SearchOption.AllDirectories))
{
string lTargetPath = newPath.Replace(directory.FullName, destinationDir);
if (lTargetPath.EndsWith(".md"))
lTargetPath = lTargetPath[..^3] + ".txt";
File.Copy(newPath, lTargetPath, true);
}
}
}
}