Example #1
0
        /// <summary>
        /// Initializes a new instance of the PropertyValue class.
        /// </summary>
        /// <param name="propertyContainer">The container of this property.</param>
        /// <param name="propertyName">The name of the property.</param>
        protected PropertyValue(IPropertyContainer propertyContainer, string propertyName)
        {
            Param.RequireNotNull(propertyContainer, "propertyContainer");
            Param.RequireValidString(propertyName, "propertyName");

            PropertyDescriptor descriptor = propertyContainer.PropertyDescriptors[propertyName];
            if (descriptor == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.PropertyDescriptorDoesNotExist, propertyName));
            }

            this.propertyDescriptor = descriptor;
        }
Example #2
0
        private StyleCopAddIn InitializeAddIn(Type addInType, bool isKnownAssembly)
        {
            Param.AssertNotNull(addInType, "addInType");
            Param.Ignore(isKnownAssembly);

            // Get the add-in attribute from the type, if it exists.
            object attributeObject;
            Type typeContainingAttribute = GetNextAddInAttributeType(
                addInType, typeof(StyleCopAddInAttribute), out attributeObject);
            if (typeContainingAttribute == null)
            {
                // This is not a valid add-in type.
                return null;
            }

            // Create the add-in instance.
            StyleCopAddIn addInObject = (StyleCopAddIn)Activator.CreateInstance(addInType);

            // Load the add-in xml.
            StyleCopAddInAttribute attribute = (StyleCopAddInAttribute)attributeObject;
            XmlDocument addInXml = LoadAddInResourceXml(addInType, attribute.AddInXmlId);
            if (addInXml == null)
            {
                // The initialization xml was not valid.
                return null;
            }

            // Initialize the add-in.
            addInObject.Initialize(this, addInXml, true, isKnownAssembly);

            // Now load any other initialization xml from parent types.
            while (true)
            {
                typeContainingAttribute = GetNextAddInAttributeType(
                    typeContainingAttribute.BaseType, typeof(StyleCopAddInAttribute), out attributeObject);

                if (typeContainingAttribute == null)
                {
                    break;
                }

                attribute = (StyleCopAddInAttribute)attributeObject;
                addInXml = LoadAddInResourceXml(typeContainingAttribute, attribute.AddInXmlId);
                if (addInXml != null)
                {
                    addInObject.Initialize(this, addInXml, false, isKnownAssembly);
                }
            }

            // Allow the add-in inheritors to initialize themselves.
            addInObject.InitializeAddIn();

            // Add a default "Enabled" property descriptor for every rule exposed by this add-in.
            foreach (Rule rule in addInObject.AddInRules)
            {
                PropertyDescriptor<bool> ruleEnabledPropertyDescriptor = new PropertyDescriptor<bool>(
                    rule.Name + "#Enabled", PropertyType.Boolean, string.Empty, string.Empty, true, false, rule.EnabledByDefault);
                addInObject.PropertyDescriptors.AddPropertyDescriptor(ruleEnabledPropertyDescriptor);
            }

            return addInObject;
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the PropertyValue class.
 /// </summary>
 /// <param name="propertyDescriptor">The property descriptor that this value represents.</param>
 protected PropertyValue(PropertyDescriptor propertyDescriptor)
 {
     Param.RequireNotNull(propertyDescriptor, "propertyDescriptor");
     this.propertyDescriptor = propertyDescriptor;
 }