Ejemplo n.º 1
0
        FieldMetadata CalcExpression(String expression)
        {
            if (String.IsNullOrEmpty(expression))
            {
                return(null);
            }
            if (expression.StartsWith("Parent."))
            {
                return(null);
            }
            if (expression.StartsWith("."))
            {
                return(null);                // inner context (DataGrid ?)
            }
            if (expression.Contains(".$selected"))
            {
                return(null);
            }
            if (expression.StartsWith("-"))
            {
                expression = expression.Substring(1);
            }
            var segments    = expression.Split('.');
            var currentType = _mm["TRoot"];
            var len         = segments.Length;

            for (var i = 0; i < len; i++)
            {
                var seg = segments[i];
                if (seg == "Root")
                {
                    currentType = _mm["TRoot"];
                    continue;
                }
                if (!currentType.ContainsKey(seg))
                {
                    throw new TypeCheckerException($"Xaml. Field not found '{expression}'");
                }
                if (i != len - 1)
                {
                    var typeName = currentType[seg];
                    var typeMeta = _mm.FindType(typeName.Type.RealType);
                    currentType = typeMeta ?? throw new TypeCheckerException($"Xaml. Field not found '{expression}'");
                }
                else
                {
                    return(currentType[seg]);
                }
            }
            return(null);
        }