コード例 #1
0
        public static Type Locate(string componentName)
        {
            var xmlns         = XmlnsDictionary.Current;
            var xamlNamespace = xmlns.GetXamlNamespace(componentName);

            return(ComponentTypeLocator.Locate(xamlNamespace, componentName));
        }
コード例 #2
0
        private void Init(string path)
        {
            if (path.StartsWith("Strings."))
            {
                var resourceKey = path.Substring("Strings.".Length);
                _expression = GetLanguageExpression(string.Empty, resourceKey);
            }
            else if (path.IndexOf(":Strings.") > -1)
            {
                var pos         = path.IndexOf(":Strings.");
                var prefixName  = path.Substring(0, pos);
                var resourceKey = path.Substring(pos + ":Strings.".Length);
                _expression = GetLanguageExpression(prefixName, resourceKey);
            }
            else
            {
                var index         = path.IndexOf('.');
                var ownerTypeName = path.Substring(0, index);
                var memberName    = path.Substring(index + 1, (path.Length - index) - 1);

                var ownerType = ComponentTypeLocator.Locate(ownerTypeName);
                if (ownerType == null)
                {
                    throw new XamlException("没有找到类型" + ownerTypeName);
                }

                _expression = new StaticReferenceExpression(path, ownerType, memberName);
            }
        }
コード例 #3
0
        /// <summary>
        /// 通过标记扩展表达式,创建标记扩展对象
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public static MarkupExtension Create(string expression)
        {
            if (!IsExpressionFormat(expression))
            {
                return(null);
            }
            var context       = LoadContext.Current;
            var componentName = string.Format("{0}Extension", GetComponentName(expression));
            var type          = ComponentTypeLocator.Locate(componentName);

            if (type == null)
            {
                return(null);
            }
            if (!type.IsImplementOrEquals(_markupExtensionType))
            {
                throw new XamlException(type.FullName + "不是标记扩展元素");
            }
            var converter = TypeConverterAttribute.CreateConverter(type);

            if (converter == null)
            {
                throw new XamlException("没有找到标记扩展" + componentName + "的类型转换器");
            }
            return(converter.ConvertTo(expression, _markupExtensionType) as MarkupExtension);
        }
コード例 #4
0
        public object CreateComponent(string componentName)
        {
            var type = ComponentTypeLocator.Locate(componentName) ?? HtmlElement.Type;

            if (type == null)
            {
                throw new XamlException("没有找到" + componentName + "的定义");
            }
            if (DataUtil.IsPrimitiveType(type))
            {
                return(type); //如果是基础类型,那么直接返回类型本身
            }
            return(SafeAccessAttribute.CreateInstance(type));
        }