示例#1
0
 internal static void VerifyThrowArgument(bool condition, Exception innerException, string resourceName, object arg0, object arg1, object arg2, object arg3)
 {
     if (condition)
     {
         return;
     }
     ErrorUtilities.ThrowArgument(innerException, resourceName, arg0, arg1, arg2, arg3);
 }
示例#2
0
 internal static void VerifyThrowArgument(bool condition, Exception innerException, string resourceName)
 {
     if (condition)
     {
         return;
     }
     ErrorUtilities.ThrowArgument(innerException, resourceName, (object[])null);
 }
示例#3
0
        /// <summary>
        /// Throws an <see cref="ArgumentException"/> if the given property's value is the empty string.
        /// </summary>
        /// <param name="property">The parameter to test.</param>
        /// <param name="propertyId">An identifier of the property to check.</param>
        internal static void VerifyThrowPropertyEmptyString(string property, string propertyId)
        {
            ErrorUtilities.VerifyThrowArgumentNull(property, "property");
            ErrorUtilities.VerifyThrowArgumentLength(propertyId, "propertyId");

            if (property.Length == 0)
            {
                ErrorUtilities.ThrowArgument(Strings.PropertyCannotBeSetToTheEmptyString, propertyId);
            }
        }
示例#4
0
        /// <summary>
        /// Throws an <see cref="ArgumentException"/> if the given list property has zero elements.
        /// </summary>
        /// <param name="listProperty"> The list parameter to test. </param>
        /// <param name="propertyId"> An identifier of the property to check. </param>
        internal static void VerifyThrowListPropertyEmpty(IList listProperty, string propertyId)
        {
            ErrorUtilities.VerifyThrowArgumentNull(listProperty, "listProperty");
            ErrorUtilities.VerifyThrowArgumentLength(propertyId, "propertyId");

            if (listProperty.Count == 0)
            {
                ErrorUtilities.ThrowArgument(Strings.ListPropertyShouldHaveAtLeastOneElement, propertyId);
            }
        }
示例#5
0
        /// <summary>
        /// Verifies that a name is valid for the name of an item, property, or piece of metadata.
        /// If it isn't, throws an ArgumentException indicating the invalid character.
        /// </summary>
        /// <remarks>
        /// Note that our restrictions are more stringent than the XML Standard's restrictions.
        /// </remarks>
        /// <throws>ArgumentException</throws>
        /// <param name="name">name to validate</param>
        internal static void VerifyThrowArgumentValidElementName(string name)
        {
            ErrorUtilities.VerifyThrowArgumentLength(name, nameof(name));

            int firstInvalidCharLocation = LocateFirstInvalidElementNameCharacter(name);

            if (-1 != firstInvalidCharLocation)
            {
                ErrorUtilities.ThrowArgument("OM_NameInvalid", name, name[firstInvalidCharLocation]);
            }
        }
示例#6
0
        /// <summary>
        /// Validates the properties of this object. This method should be called
        /// after initialization is complete.
        /// </summary>
        internal void Validate(this IntProperty type)
        {
            (type as BaseProperty).Validate();

            if (null != type.MaxValue && null != type.MinValue)
            {
                if (type.MinValue > type.MaxValue)
                {
                    string minValuePropertyId = GetPropertyId("MinValue", type.Name, type);
                    ErrorUtilities.ThrowArgument(Strings.MinValueShouldNotBeGreaterThanMaxValue, minValuePropertyId);
                }
            }
        }
示例#7
0
        /// <summary>
        /// Searches for a file based on the specified starting directory.
        /// </summary>
        /// <param name="file">The file to search for.</param>
        /// <param name="startingDirectory">An optional directory to start the search in.  The default location is the directory
        /// of the file containing the property function.</param>
        /// <returns>The full path of the file if it is found, otherwise an empty string.</returns>
        internal static string GetPathOfFileAbove(string file, string startingDirectory)
        {
            // This method does not accept a path, only a file name
            if (file.Any(i => i.Equals(Path.DirectorySeparatorChar) || i.Equals(Path.AltDirectorySeparatorChar)))
            {
                ErrorUtilities.ThrowArgument("InvalidGetPathOfFileAboveParameter", file);
            }

            // Search for a directory that contains that file
            string directoryName = GetDirectoryNameOfFileAbove(startingDirectory, file);

            return(String.IsNullOrEmpty(directoryName) ? String.Empty : NormalizePath(directoryName, file));
        }
示例#8
0
        /// <summary>
        /// Validates the properties of this object. This method should be called
        /// after initialization is complete.
        /// </summary>
        private void Validate(this EnumProperty type)
        {
            (type as BaseProperty).Validate();

            // Validate that the "Default" field is not set on this property.
            string defaultPropertyId = GetPropertyId("Default", type.Name, type);

            if (null != Default)
            {
                ErrorUtilities.ThrowArgument(Strings.CannotSetDefaultPropertyOnEnumProperty, typeof(EnumProperty).Name, typeof(EnumValue).Name);
            }

            // Make sure that at least one value was defined in AdmissibleValues.
            string admissibleValuesId = GetPropertyId("AdmissibleValues", type.Name, type);

            VerifyThrowListPropertyEmpty(type.AdmissibleValues, admissibleValuesId);

            // Validate that only one of the EnumValues under AdmissibleValues is marked IsDefault.
            string admissibleValuesPropertyId = GetPropertyId("AdmissibleValues", type.Name, type);

            bool seen = false;

            foreach (EnumValue enumValue in type.AdmissibleValues)
            {
                if (enumValue.IsDefault)
                {
                    if (!seen)
                    {
                        seen = true;
                    }
                    else
                    {
                        ErrorUtilities.ThrowArgument(Strings.OnlyOneEnumValueCanBeSetAsDefault, typeof(EnumValue).Name, admissibleValuesPropertyId);
                    }
                }
            }
        }
示例#9
0
        internal static string GetPathToDotNetFramework(Version version, DotNetFrameworkArchitecture architecture)
        {
            string str = version.Major + "." + version.Minor;

            switch (str)
            {
            case "1.1":
                return(GetPathToDotNetFrameworkV11(architecture));

            case "2.0":
                return(GetPathToDotNetFrameworkV20(architecture));

            case "3.0":
                return(GetPathToDotNetFrameworkV30(architecture));

            case "3.5":
                return(GetPathToDotNetFrameworkV35(architecture));

            case "4.0":
                return(GetPathToDotNetFrameworkV40(architecture));
            }
            ErrorUtilities.ThrowArgument("FrameworkLocationHelper.UnsupportedFrameworkVersion", new object[] { str });
            return(null);
        }
示例#10
0
        /// <summary>
        /// Validates the properties of this object. This method should be called
        /// after initialization is complete.
        /// </summary>
        internal void Validate(this Rule type)
        {
            // Validate "Name" property.
            string namePropertyId = GetPropertyId("Name", type);

            VerifyThrowPropertyNotSetOrEmptyString(type.Name, namePropertyId);

            // Make sure that at least one Property was defined in this Rule.
            string propertiesId = XamlErrorUtilities.GetPropertyId("Properties", Name, this);

            VerifyThrowListPropertyEmpty(type.Properties, propertiesId);

            // Validate the child objects
            foreach (BaseProperty property in type.Properties)
            {
                property.Validate();
            }

            foreach (Category category in type.Categories)
            {
                category.Validate();
            }

            // If the DataSource property is not defined on this Rule, check that a DataSource is
            // specified locally on every property.
            if (null == type.DataSource)
            {
                foreach (BaseProperty property in type.Properties)
                {
                    string dataSourcePropertyId = GetPropertyId("DataSource", property.Name, property);
                    VerifyThrowPropertyNotSet(property.DataSource, dataSourcePropertyId, Strings.DataSourceMustBeDefinedOnPropertyOrOnRule);
                }
            }
            else
            {
                type.DataSource.Validate();
            }

            // Create a HashSet for O(1) lookup.
            HashSet <string> propertyNames = new HashSet <string>();

            foreach (BaseProperty property in type.Properties)
            {
                if (!propertyNames.Contains(property.Name))
                {
                    propertyNames.Add(property.Name);
                }
            }

            // Validate that every argument refers to a valid property.
            foreach (BaseProperty property in type.Properties)
            {
                if (property.Arguments == null || property.Arguments.Count == 0)
                {
                    continue;
                }

                foreach (Argument argument in property.Arguments)
                {
                    if (!propertyNames.Contains(argument.Property))
                    {
                        ErrorUtilities.ThrowArgument(Strings.PropertyReferredToByArgumentDoesNotExist, argument.Property);
                    }
                }
            }
        }
示例#11
0
 internal static void ThrowArgument(string resourceName, params object[] args)
 {
     ErrorUtilities.ThrowArgument((Exception)null, resourceName, args);
 }