summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml/XmlnsHelper.cs
blob: 778d2947a07809627326f1bdec780e151d592de8 (plain)
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
using System;

namespace Xamarin.Forms.Xaml
{
	internal static class XmlnsHelper
	{
		public static bool IsCustom(string ns)
		{
			switch (ns)
			{
				case "":
				case "http://xamarin.com/schemas/2014/forms":
					return false;
			}
			return true;
		}

		public static string ParseNamespaceFromXmlns(string xmlns)
		{
			string typeName;
			string ns;
			string asm;

			ParseXmlns(xmlns, out typeName, out ns, out asm);

			return ns;
		}

		public static void ParseXmlns(string xmlns, out string typeName, out string ns, out string asm)
		{
			typeName = ns = asm = null;

			foreach (var decl in xmlns.Split(';'))
			{
				if (decl.StartsWith("clr-namespace:", StringComparison.Ordinal))
				{
					ns = decl.Substring(14, decl.Length - 14);
					continue;
				}
				if (decl.StartsWith("assembly=", StringComparison.Ordinal))
				{
					asm = decl.Substring(9, decl.Length - 9);
					continue;
				}
				var nsind = decl.LastIndexOf(".", StringComparison.Ordinal);
				if (nsind > 0)
				{
					ns = decl.Substring(0, nsind);
					typeName = decl.Substring(nsind + 1, decl.Length - nsind - 1);
				}
				else
					typeName = decl;
			}
		}
	}
}