コード例 #1
0
        public void Defaults()
        {
            TemplatePartAttribute attr = new TemplatePartAttribute();

            Assert.IsNull(attr.Name, "Name");
            Assert.IsNull(attr.Type, "Type");
        }
コード例 #2
0
        public void Setters()
        {
            TemplatePartAttribute attr = new TemplatePartAttribute();

            attr.Name = String.Empty;
            attr.Type = typeof(object);
            Assert.AreEqual(String.Empty, attr.Name, "Name");
            Assert.AreEqual(typeof(object), attr.Type, "Type");
            attr.Name = null;
            attr.Type = null;
            Assert.IsNull(attr.Name, "Name/Null");
            Assert.IsNull(attr.Type, "Type/Null");
        }
コード例 #3
0
        /// <summary>
        /// Get the template parts declared on a type.
        /// </summary>
        /// <param name="controlType">Type with template parts defined.</param>
        /// <returns>Template parts defined on the type.</returns>
        public static IDictionary <string, Type> GetTemplateParts(this Type controlType)
        {
            Dictionary <string, Type> templateParts = new Dictionary <string, Type>();

            foreach (Attribute attribute in controlType.GetCustomAttributes(typeof(TemplatePartAttribute), false))
            {
                TemplatePartAttribute templatePart = attribute as TemplatePartAttribute;
                if (templatePart != null)
                {
                    templateParts.Add(templatePart.Name, templatePart.Type);
                }
            }
            return(templateParts);
        }