Exemple #1
0
        /// <summary>
        /// Gets the category editor by attributes.
        /// </summary>
        /// <param name="declaringType">Type of the declaring.</param>
        /// <param name="categoryName">Name of the category.</param>
        /// <returns>Editor for Category</returns>
        public static Editor GetCategoryEditorByAttributes(Type declaringType, string categoryName)
        {
            if (declaringType == null || string.IsNullOrEmpty(categoryName))
            {
                return(null);
            }

            string name = categoryName.ToUpperInvariant();

            CategoryEditorAttribute attribute = declaringType
                                                .GetCustomAttributes(KnownTypes.Attributes.CategoryEditorAttribute, true)
                                                .OfType <CategoryEditorAttribute>()
                                                .FirstOrDefault(attr => attr.CategoryName == name);

            if (attribute == null)
            {
                return(null);
            }

            try
            {
                Type editorType = Type.GetType(attribute.EditorType);
                if (editorType == null || !KnownTypes.Wpg.Editor.IsAssignableFrom(editorType))
                {
                    return(null);
                }
                return((Editor)Activator.CreateInstance(editorType));
            }
            catch
            {
                return(null);
            }
        }
Exemple #2
0
        public void ShouldCompareTwoInstances()
        {
            CategoryEditorAttribute attribute1 = new CategoryEditorAttribute("category", "type");
            CategoryEditorAttribute attribute2 = new CategoryEditorAttribute("category", "type");

            Assert.IsTrue(attribute1.Equals(attribute2));

            attribute2 = new CategoryEditorAttribute("category2", "type");
            Assert.IsFalse(attribute1.Equals(attribute2));

            attribute2 = new CategoryEditorAttribute("category", "type2");
            Assert.IsFalse(attribute1.Equals(attribute2));
        }
Exemple #3
0
        public void ShouldCompareSameInstance()
        {
            CategoryEditorAttribute attribute = new CategoryEditorAttribute("category", "type");

            Assert.IsTrue(attribute.Equals(attribute));
        }