2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
21 namespace Tizen.NUI.Xaml
23 internal static class TypeArgumentsParser
25 public static IList<XmlType> ParseExpression(string expression, IXmlNamespaceResolver resolver, IXmlLineInfo lineInfo)
27 var typeList = new List<XmlType>();
28 while (!string.IsNullOrWhiteSpace(expression))
30 var match = expression;
31 typeList.Add(Parse(match, ref expression, resolver, lineInfo));
36 static XmlType Parse(string match, ref string remaining, IXmlNamespaceResolver resolver, IXmlLineInfo lineinfo)
41 bool isGeneric = false;
43 for (pos = 0; pos < match.Length; pos++)
45 if (match[pos] == '(')
50 else if (match[pos] == ')')
52 else if (match[pos] == ',' && parensCount == 0)
54 remaining = match.Substring(pos + 1);
58 var type = match.Substring(0, pos).Trim();
60 IList<XmlType> typeArguments = null;
63 typeArguments = ParseExpression(
64 type.Substring(type.IndexOf('(') + 1, type.LastIndexOf(')') - type.IndexOf('(') - 1), resolver, lineinfo);
65 type = type.Substring(0, type.IndexOf('('));
68 var split = type.Split(':');
73 if (split.Length == 2)
84 var namespaceuri = resolver.LookupNamespace(prefix);
85 if (namespaceuri == null)
86 throw new XamlParseException($"No xmlns declaration for prefix '{prefix}'.", lineinfo, null);
87 return new XmlType(namespaceuri, name, typeArguments);