当前位置: 首页>>代码示例>>C#>>正文


C# ArgumentException.GetType方法代码示例

本文整理汇总了C#中System.ArgumentException.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ArgumentException.GetType方法的具体用法?C# ArgumentException.GetType怎么用?C# ArgumentException.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ArgumentException的用法示例。


在下文中一共展示了ArgumentException.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Increment_WithException_AddReadingDataForTheSpecificException

        public void Increment_WithException_AddReadingDataForTheSpecificException()
        {
            var sensor = new ExceptionSensor();

            ArgumentException exception = new ArgumentException();
            sensor.AddError(exception);

            Reading reading = null;
            ReadingPublisher.Readings.TryDequeue(out reading); // TotalExceptions
            ReadingPublisher.Readings.TryDequeue(out reading);

            Assert.That(reading.Data.Name, Is.EqualTo(exception.GetType().Name));
        }
开发者ID:aqueduct,项目名称:Aqueduct.Monitoring,代码行数:13,代码来源:ExceptionSensorTests.cs

示例2: TestCompareEndpointsMethod50316

        public void TestCompareEndpointsMethod50316(TestCaseAttribute testCase)
        {
            HeaderComment(testCase);

            ArgumentException ex = new ArgumentException("Unused, just need an instance for GetType() below");

            CompareEndpointsHelper(SampleText.Random256, TargetRangeType.DocumentRange, TargetRangeType.DifferentTextPattern,
                   ValueComparison.Equals, ValueComparison.Equals, ValueComparison.Equals, ValueComparison.Equals, ex.GetType());
        }
开发者ID:sergeyDyadenchuk,项目名称:Testing,代码行数:9,代码来源:TextTests.cs

示例3: ClaseDeRuta

        public void PruebaConstructorConLímiteDeVelocidadClaseDeRutaBoolArray()
        {
            #region Caso 1: Caso normal.
              {
            // Preparación.
            LímiteDeVelocidad límiteDeVelocidad = new LímiteDeVelocidad(2);
            ClaseDeRuta claseDeRuta = new ClaseDeRuta(3);
            bool[] otrosParámetros = new bool[] { true, false, true, false, false, false, true, true, false, true };

            // Llama al constructor en prueba.
            CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(límiteDeVelocidad, claseDeRuta, otrosParámetros);

            // Prueba Propiedades.
            Assert.That(objectoEnPrueba.Identificador, Is.EqualTo(CampoParámetrosDeRuta.IdentificadorDeParámetrosDeRuta), "Identificador");
            Assert.That(objectoEnPrueba.ClaseDeRuta, Is.EqualTo(claseDeRuta), "ClaseDeRuta");
            Assert.That(objectoEnPrueba.LímiteDeVelocidad, Is.EqualTo(límiteDeVelocidad), "LímiteDeVelocidad");
            Assert.That(objectoEnPrueba.OtrosParámetros, Is.EqualTo(otrosParámetros), "OtrosParámetros");
              }
              #endregion

              #region Caso 2: Muy pocos elementos en Otros Parámetros.
              {
            // Preparación.
            LímiteDeVelocidad límiteDeVelocidad = new LímiteDeVelocidad(2);
            ClaseDeRuta claseDeRuta = new ClaseDeRuta(3);
            bool[] otrosParámetros = new bool[] { true, true, false, false, false, true, true, false, true };
            bool lanzóExcepción = false;
            ArgumentException excepciónEsperada = new ArgumentException(
              "El números de Otrós Parámetros debe ser 10 pero es 9\r\nParameter name: losOtrosParámetros");

            // Llama al constructor en prueba.
            try
            {
              CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(límiteDeVelocidad, claseDeRuta, otrosParámetros);
            }
            catch (Exception e)
            {
              // Prueba las propiedades de la excepción.
              Assert.That(e.GetType(), Is.EqualTo(excepciónEsperada.GetType()), "Tipo de Excepción");
              Assert.That(e.Message, Is.EqualTo(excepciónEsperada.Message), "Excepción.Message");

              lanzóExcepción = true;
            }

            Assert.That(lanzóExcepción, Is.True, "No se lanzó la excepción.");
              }
              #endregion

              #region Caso 3: Muchos elementos en Otros Parámetros.
              {
            // Preparación.
            LímiteDeVelocidad límiteDeVelocidad = new LímiteDeVelocidad(2);
            ClaseDeRuta claseDeRuta = new ClaseDeRuta(3);
            bool[] otrosParámetros = new bool[] { true, true, false, true, false, false, false, true, true, false, true };
            bool lanzóExcepción = false;
            ArgumentException excepciónEsperada = new ArgumentException(
              "El números de Otrós Parámetros debe ser 10 pero es 11\r\nParameter name: losOtrosParámetros");

            // Llama al constructor en prueba.
            try
            {
              CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(límiteDeVelocidad, claseDeRuta, otrosParámetros);
            }
            catch (Exception e)
            {
              // Prueba las propiedades de la excepción.
              Assert.That(e.GetType(), Is.EqualTo(excepciónEsperada.GetType()), "Tipo de Excepción");
              Assert.That(e.Message, Is.EqualTo(excepciónEsperada.Message), "Excepción.Message");

              lanzóExcepción = true;
            }

            Assert.That(lanzóExcepción, Is.True, "No se lanzó la excepción.");
              }
              #endregion
        }
开发者ID:PatricioVidal,项目名称:GpsMapTools,代码行数:76,代码来源:PruebaCampoParámetrosDeRuta.cs

示例4: PruebaConstructorConString

        public void PruebaConstructorConString()
        {
            #region Caso 1: Indice en rango válido.
              {
            // Preparación.
            LímiteDeVelocidad límiteDeVelocidad = new LímiteDeVelocidad (2);
            ClaseDeRuta claseDeRuta = new ClaseDeRuta (3);
            string parámetrosDeRuta = "2,3,0,1,0,0,0,0,0,0,0,1";
            bool[] otrosParámetrosEsperados = new bool[] { false, true, false, false, false, false, false, false, false, true };

            // Llama al constructor en prueba.
            CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(parámetrosDeRuta);

            // Prueba Propiedades.
            Assert.That(objectoEnPrueba.Identificador, Is.EqualTo(CampoParámetrosDeRuta.IdentificadorDeParámetrosDeRuta), "Identificador");
            Assert.That(objectoEnPrueba.ClaseDeRuta, Is.EqualTo(claseDeRuta), "ClaseDeRuta");
            Assert.That(objectoEnPrueba.LímiteDeVelocidad, Is.EqualTo(límiteDeVelocidad), "LímiteDeVelocidad");
            Assert.That(objectoEnPrueba.OtrosParámetros, Is.EqualTo(otrosParámetrosEsperados), "OtrosParámetros");
              }
              #endregion

              #region Caso 2: Parametros de Tuta con muy pocos elementos.
              {
            // Preparación.
            string parametrosDeRutaInválidos = "2";
            bool lanzóExcepción = false;
            ArgumentException excepciónEsperada = new ArgumentException(
              "Los parámetros de rutas deben tener 12 elementos separados por coma, pero es: 2");

            // Llama al constructor en prueba.
            try
            {
              CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(parametrosDeRutaInválidos);
            }
            catch (Exception e)
            {
              // Prueba las propiedades de la excepción.
              Assert.That(e.GetType(), Is.EqualTo(excepciónEsperada.GetType()), "Tipo de Excepción");
              Assert.That(e.Message, Is.EqualTo(excepciónEsperada.Message), "Excepción.Message");

              lanzóExcepción = true;
            }

            Assert.That(lanzóExcepción, Is.True, "No se lanzó la excepción.");
              }
              #endregion

              #region Caso 3: Otros Parámetros con valores diferente de 0 ó 1.
              {
            // Preparación.
            string parametrosDeRutaInválidos = "2,3,0,5,0,0,0,0,0,0,0,1";
            bool lanzóExcepción = false;
            ArgumentException excepciónEsperada = new ArgumentException(
              "El números de los parámetros de ruta para el tercer elemento en adelante tiene que ser 0 ó 1:" +
              " 2,3,0,5,0,0,0,0,0,0,0,1\r\nParameter name: elTextoDeParámetrosDeRuta");

            // Llama al constructor en prueba.
            try
            {
              CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(parametrosDeRutaInválidos);
            }
            catch (Exception e)
            {
              // Prueba las propiedades de la excepción.
              Assert.That(e.GetType(), Is.EqualTo(excepciónEsperada.GetType()), "Tipo de Excepción");
              Assert.That(e.Message, Is.EqualTo(excepciónEsperada.Message), "Excepción.Message");

              lanzóExcepción = true;
            }

            Assert.That(lanzóExcepción, Is.True, "No se lanzó la excepción.");
              }
              #endregion
        }
开发者ID:PatricioVidal,项目名称:GpsMapTools,代码行数:74,代码来源:PruebaCampoParámetrosDeRuta.cs

示例5: ErrorIfDestinationIsSourceOrChildOfSource

        } // CopyRegistryKey

        private bool ErrorIfDestinationIsSourceOrChildOfSource(
            string sourcePath,
            string destinationPath)
        {
            s_tracer.WriteLine("destinationPath = {0}", destinationPath);

            // Note the paths have already been normalized so case-insensitive
            // comparisons should be sufficient

            bool result = false;

            do
            {
                // See if the paths are equal

                if (String.Compare(
                        sourcePath,
                        destinationPath,
                        StringComparison.OrdinalIgnoreCase) == 0)
                {
                    result = true;
                    break;
                }

                string newDestinationPath = GetParentPath(destinationPath, null);

                if (String.IsNullOrEmpty(newDestinationPath))
                {
                    // We reached the root so the destination must not be a child
                    // of the source
                    break;
                }

                if (String.Compare(
                        newDestinationPath,
                        destinationPath,
                        StringComparison.OrdinalIgnoreCase) == 0)
                {
                    // We reached the root so the destination must not be a child
                    // of the source
                    break;
                }

                destinationPath = newDestinationPath;
            } while (true);

            if (result)
            {
                Exception e =
                    new ArgumentException(
                        RegistryProviderStrings.DestinationChildOfSource);
                WriteError(new ErrorRecord(
                    e,
                    e.GetType().FullName,
                    ErrorCategory.InvalidArgument,
                    destinationPath));
            }
            return result;
        } // ErrorIfDestinationIsSourceOrChildOfSource
开发者ID:40a,项目名称:PowerShell,代码行数:61,代码来源:RegistryProvider.cs

示例6: TS_ThrowTextPatternExceptions

        private void TS_ThrowTextPatternExceptions()
        {
            TextPatternRange returnedRange = null;
            Point screenLocation = new Point();
            ArgumentException aeEx = new ArgumentException("<<Fake argument>>");
            ArgumentNullException anEx = new ArgumentNullException("<<Fake null argument>>");

            //----------------
            // RangeFromPoint
            //----------------

            screenLocation.X = Int32.MaxValue;
            screenLocation.Y = Int32.MinValue;

            // ArgumentException – if given point is outside of AutomationElement of the control
            _tth.Pattern_RangeFromPoint(_pattern, ref returnedRange, screenLocation, aeEx.GetType(), CheckType.Verification);

            //----------------
            // RangeFromChild
            //----------------

            // ArgumentNullException – if returnedRange is null 
            _tth.Pattern_RangeFromChild(_pattern, ref returnedRange, null, anEx.GetType(), CheckType.Verification);

            //// InvalidOperationException – if the child could not have come from this container.
            // Bug 1199703: Spec bug: RangeFromChild returns incorrect exception when passed an automation element from another container
            //_tth.Pattern_RangeFromChild(_pattern, ref returnedRange, differentautoElement, ioeEx.GetType(), CheckType.Verification);

            m_TestStep++;
        }
开发者ID:geeksree,项目名称:cSharpGeeks,代码行数:30,代码来源:Text.cs

示例7: TS_Coverage_FindText

        private void TS_Coverage_FindText()
        {
            Type type = null;
            ArgumentException aeEx = new ArgumentException("FAKE Argument");
            TextPatternRange callingRange = _pattern.DocumentRange;
            TextPatternRange returnedRange = null;
            string text = callingRange.GetText(-1);

            TextTestsHelper.TrimTrailingCRLF(m_le, ref text);

            if (string.IsNullOrEmpty(text) == true)
            {
                type = aeEx.GetType();
            }

            // Empty text
            _tth.Range_FindText(callingRange, ref returnedRange, "", true, true, aeEx.GetType(), CheckType.Verification);
            _tth.Range_FindText(callingRange, ref returnedRange, "", true, false, aeEx.GetType(), CheckType.Verification);
            _tth.Range_FindText(callingRange, ref returnedRange, "", false, true, aeEx.GetType(), CheckType.Verification);
            _tth.Range_FindText(callingRange, ref returnedRange, "", false, true, aeEx.GetType(), CheckType.Verification);

            // Non-matching text
            _tth.Range_FindText(callingRange, ref returnedRange, "ATG", true, true, null, CheckType.Verification);
            _tth.Range_FindText(callingRange, ref returnedRange, "ATG", true, false, null, CheckType.Verification);
            _tth.Range_FindText(callingRange, ref returnedRange, "ATG", false, true, null, CheckType.Verification);
            _tth.Range_FindText(callingRange, ref returnedRange, "ATG", false, true, null, CheckType.Verification);

            // Matching Text with matching case
            text = text.Substring(0, ((text.Length / 2)));
            _tth.Range_FindText(callingRange, ref returnedRange, text, true, true, type, CheckType.Verification);
            _tth.Range_FindText(callingRange, ref returnedRange, text, true, false, type, CheckType.Verification);
            _tth.Range_FindText(callingRange, ref returnedRange, text, false, true, type, CheckType.Verification);
            _tth.Range_FindText(callingRange, ref returnedRange, text, false, true, type, CheckType.Verification);

            // Matching Text with mis-matched case
            text = text.ToUpperInvariant();
            _tth.Range_FindText(callingRange, ref returnedRange, text, true, true, type, CheckType.Verification);
            _tth.Range_FindText(callingRange, ref returnedRange, text, true, false, type, CheckType.Verification);
            _tth.Range_FindText(callingRange, ref returnedRange, text, false, true, type, CheckType.Verification);
            _tth.Range_FindText(callingRange, ref returnedRange, text, false, true, type, CheckType.Verification);

            Comment("Called FindText kitchen sink");
            m_TestStep++;
        }
开发者ID:geeksree,项目名称:cSharpGeeks,代码行数:44,代码来源:Text.cs

示例8: Bug1106920

        //-------------------------------------------------------------------
        // Regress Bug
        //-------------------------------------------------------------------
        internal void Bug1106920( string bugID, string controls, string bugTitle )
        {
            TextPatternRange range  = null;

            TS_RegressionTest(bugID, controls, bugTitle);

            try
            {
                string actualText = "";
                SetText(SampleText.String1, out actualText, CheckType.IncorrectElementConfiguration);
                range = Pattern_DocumentRange(CheckType.Verification);

                ArgumentException     aeEx  = new ArgumentException();
                ArgumentNullException aneEx = new ArgumentNullException();
                TextPatternRange targetRange = null;

                Range_FindText( range, ref targetRange, null, false, false, aneEx.GetType(), CheckType.IncorrectElementConfiguration );
                
                Range_FindText( range, ref targetRange, "",   false, false, aeEx.GetType(), CheckType.IncorrectElementConfiguration );

                Comment("FindText raised correct exceptions");
            }
            catch (Exception ex)
            {
                if (IsUIVerifyException(ex))  // Don't interfere with legitimate ThrowMe(...)
                    throw;

                ThrowMe(CheckType.Verification, "Unexpected exception encountered:\n" + ex.ToString());
            }
        }
开发者ID:sergeyDyadenchuk,项目名称:Testing,代码行数:33,代码来源:TextTestsHelper.cs

示例9: NewDrive

 protected override PSDriveInfo NewDrive(PSDriveInfo drive)
 {
     if (drive == null)
     {
         throw PSTraceSource.NewArgumentNullException("drive");
     }
     if (!this.ItemExists(drive.Root))
     {
         Exception exception = new ArgumentException(RegistryProviderStrings.NewDriveRootDoesNotExist);
         base.WriteError(new ErrorRecord(exception, exception.GetType().FullName, ErrorCategory.InvalidArgument, drive.Root));
     }
     return drive;
 }
开发者ID:nickchal,项目名称:pash,代码行数:13,代码来源:RegistryProvider.cs

示例10: RenameItem

        } // EscapeChildName

        /// <summary>
        /// Renames the key at the specified <paramref name="path"/> to <paramref name="newName"/>.
        /// </summary>
        ///
        /// <param name="path">
        /// The path to the key to rename.
        /// </param>
        ///
        /// <param name="newName">
        /// The new name of the key.
        /// </param>
        protected override void RenameItem(
            string path,
            string newName)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw PSTraceSource.NewArgumentException("path");
            }

            if (String.IsNullOrEmpty(newName))
            {
                throw PSTraceSource.NewArgumentException("newName");
            }

            s_tracer.WriteLine("newName = {0}", newName);

            string parentPath = GetParentPath(path, null);
            string newPath = MakePath(parentPath, newName);

            // Make sure we aren't going to overwrite an existing item

            bool exists = ItemExists(newPath);

            if (exists)
            {
                Exception e = new ArgumentException(RegistryProviderStrings.RenameItemAlreadyExists);
                WriteError(new ErrorRecord(
                    e,
                    e.GetType().FullName,
                    ErrorCategory.InvalidArgument,
                    newPath));

                return;
            }
            // Confirm the rename item with the user

            string action = RegistryProviderStrings.RenameItemAction;

            string resourceTemplate = RegistryProviderStrings.RenameItemResourceTemplate;

            string resource =
                String.Format(
                    Host.CurrentCulture,
                    resourceTemplate,
                    path,
                    newPath);

            if (ShouldProcess(resource, action))
            {
                // Implement rename as a move operation

                MoveRegistryItem(path, newPath);
            } // ShouldProcess
        } // RenameItem
开发者ID:40a,项目名称:PowerShell,代码行数:67,代码来源:RegistryProvider.cs

示例11: ParseKind

        } // WriteRegistryItemObject

        /// <summary>
        /// Takes a string and tries to parse it into a RegistryValueKind enum
        /// type.
        /// If the conversion fails, WriteError() is called
        /// </summary>
        /// 
        /// <param name="type">
        /// The type as specified by the user that should be parsed into a RegistryValueKind enum.
        /// </param>
        /// 
        /// <param name="kind"> output for the RegistryValueKind for the string</param>
        /// <returns>
        /// true if the conversion succeeded
        /// </returns>
        private bool ParseKind(string type, out RegistryValueKind kind)
        {
            kind = RegistryValueKind.Unknown;

            if (String.IsNullOrEmpty(type))
            {
                return true;
            }

            bool success = true;
            Exception innerException = null;
            try
            {
                // Convert the parameter to a RegistryValueKind
                kind = (RegistryValueKind)Enum.Parse(typeof(RegistryValueKind), type, true);
            }
            catch (InvalidCastException invalidCast)
            {
                innerException = invalidCast;
            }
            catch (ArgumentException argException)
            {
                innerException = argException;
            }

            if (innerException != null)
            {
                success = false;

                string formatString =
                    RegistryProviderStrings.TypeParameterBindingFailure;
                Exception e =
                    new ArgumentException(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            formatString,
                            type,
                            typeof(RegistryValueKind).FullName),
                        innerException);
                WriteError(new ErrorRecord(
                    e,
                    e.GetType().FullName,
                    ErrorCategory.InvalidArgument,
                    type));
            }

            return success;
        } // ParseKind
开发者ID:40a,项目名称:PowerShell,代码行数:64,代码来源:RegistryProvider.cs

示例12: GetRegkeyForPathWriteIfError

        /// <summary>
        /// A private helper method that retrieves a RegistryKey for the specified
        /// path and if an exception is thrown retrieving the key, an error is written
        /// and null is returned.
        /// </summary>
        ///
        /// <param name="path">
        /// The path to the registry key to retrieve.
        /// </param>
        ///
        /// <param name="writeAccess">
        /// If write access is required the key then this should be true. If false,
        /// the key will be opened with read access only.
        /// </param>
        ///
        /// <returns>
        /// The RegistryKey associated with the specified path.
        /// </returns>
        ///
        private IRegistryWrapper GetRegkeyForPathWriteIfError(string path, bool writeAccess)
        {
            IRegistryWrapper result = null;
            try
            {
                result = GetRegkeyForPath(path, writeAccess);

                if (result == null)
                {
                    // The key was not found, write out an error.

                    ArgumentException exception =
                        new ArgumentException(
                        RegistryProviderStrings.KeyDoesNotExist);
                    WriteError(new ErrorRecord(exception, exception.GetType().FullName, ErrorCategory.InvalidArgument, path));

                    return null;
                }
            }
            catch (ArgumentException argumentException)
            {
                WriteError(new ErrorRecord(argumentException, argumentException.GetType().FullName, ErrorCategory.OpenError, path));
                return result;
            }
            catch (System.IO.IOException ioException)
            {
                // An exception occurred while trying to get the key. Write
                // out the error.

                WriteError(new ErrorRecord(ioException, ioException.GetType().FullName, ErrorCategory.OpenError, path));
                return result;
            }
            catch (System.Security.SecurityException securityException)
            {
                // An exception occurred while trying to get the key. Write
                // out the error.

                WriteError(new ErrorRecord(securityException, securityException.GetType().FullName, ErrorCategory.PermissionDenied, path));
                return result;
            }
            catch (System.UnauthorizedAccessException unauthorizedAccessException)
            {
                // An exception occurred while trying to get the key. Write
                // out the error.

                WriteError(new ErrorRecord(unauthorizedAccessException, unauthorizedAccessException.GetType().FullName, ErrorCategory.PermissionDenied, path));
                return result;
            }
            return result;
        }
开发者ID:40a,项目名称:PowerShell,代码行数:69,代码来源:RegistryProvider.cs

示例13: AddPropertyValueAt

        } // RemovePropertyValueAt        

        /// <summary>
        /// Adds a property value on the item specified by the path.
        /// </summary>
        /// 
        /// <param name="path">
        /// The path to the item on which the property should be added.
        /// </param>
        /// 
        /// <param name="at">
        /// The position of the property to add.
        /// </param>
        ///
        /// <param name="propertyValue">
        /// The property to add the value on.
        /// </param>
        /// 
        /// <returns>
        /// Nothing. A PSObject representing the property and value that was 
        /// added should be passed to the WriteObject() method.
        /// </returns>
        /// 
        /// <remarks>
        /// Implement this method when you are providing access to a data store
        /// that allows multivalued properties.
        /// </remarks>
        /// 
        public void AddPropertyValueAt(
            string path,
            object at,
            PSObject propertyValue)
        {
            if (path == null)
            {
                throw tracer.NewArgumentNullException("path");
            }

            if (!CheckOperationNotAllowedOnHiveContainer(path))
            {
                return;
            }

            if (propertyValue == null)
            {
                throw tracer.NewArgumentNullException("propertyValue");
            }

            // Convert the at parameter to an int
            int index = GetIndexFromAt(at);

            IRegistryWrapper key = GetRegkeyForPathWriteIfError(path, true);

            if (key == null)
            {
                return;
            }

            string action = RegistryProviderStrings.AddPropertyValueAtAction;
            
            string resourceTemplate = RegistryProviderStrings.AddPropertyValueAtResourceTemplate;

            PSMemberInfoCollection properties = null;

            try
            {
                properties = propertyValue.Properties;
            }
            catch (System.IO.IOException ioException)
            {
                // An exception occurred while trying to get the key. Write
                // out the error.

                WriteError (new ErrorRecord (ioException, ioException.GetType().FullName, ErrorCategory.ReadError, path));
                return;
            }
            catch (System.Security.SecurityException securityException)
            {
                // An exception occurred while trying to get the key. Write
                // out the error.

                WriteError (new ErrorRecord (securityException, securityException.GetType().FullName, ErrorCategory.PermissionDenied, path));
                return;
            }
            catch (System.UnauthorizedAccessException unauthorizedAccessException)
            {
                // An exception occurred while trying to get the key. Write
                // out the error.

                WriteError (new ErrorRecord (unauthorizedAccessException, unauthorizedAccessException.GetType().FullName, ErrorCategory.PermissionDenied, path));
                return;
            }


            foreach (PSMemberInfo property in properties)
            {
                object newPropertyValue = property.Value;

                string resource = 
                    String.Format(
//.........这里部分代码省略.........
开发者ID:40a,项目名称:PowerShell,代码行数:101,代码来源:RegistryProvider.cs

示例14: RemovePropertyValueAt

        /// <summary>
        /// Removes the specified value of a property on the item specified by the path.
        /// </summary>
        /// 
        /// <param name="path">
        /// The path to the item from which the property value should be removed.
        /// </param>
        /// 
        /// <param name="propertyName">
        /// The property to remove the value from.
        /// </param>
        /// 
        /// <param name="at">
        /// The position of the property value to remove.
        /// </param>
        ///
        /// <returns>
        /// Nothing. A PSObject representing the property and value that was 
        /// removed should be passed to the WriteObject() method.
        /// </returns>
        /// 
        /// <remarks>
        /// Implement this method when you are providing access to a data store
        /// that allows multivalued properties.
        /// </remarks>
        /// 
        public void RemovePropertyValueAt(
            string path,
            string propertyName,
            object at)
        {
            if (path == null)
            {
                throw tracer.NewArgumentNullException("path");
            }

            if (!CheckOperationNotAllowedOnHiveContainer(path))
            {
                return;
            }

            // Convert the at parameter to an int
            int index = GetIndexFromAt(at);

            if (index == -1)
            {
                // The key was not found, write out an error.

                ArgumentException exception = 
                    new ArgumentException(
                    RegistryProviderStrings.BadAtParam);
                WriteError (new ErrorRecord (exception, exception.GetType().FullName, ErrorCategory.InvalidArgument, path));

                return;
            }

            IRegistryWrapper key = GetRegkeyForPathWriteIfError(path, true);

            if (key == null)
            {
                return;
            }

            string action = RegistryProviderStrings.RemovePropertyValueAtAction;
            
            string resourceTemplate = RegistryProviderStrings.RemovePropertyValueAtResourceTemplate;

            string resource = 
                String.Format(
                    Host.CurrentCulture, 
                    resourceTemplate,
                    path,
                    propertyName,
                    at);

            if (ShouldProcess(resource, action))
            {
                try
                {
                    string propertyNameToRemove = GetPropertyName(propertyName);

                    // First get the current value

                    object currentValue = key.GetValue(propertyNameToRemove);

                    if (currentValue != null &&
                        currentValue is string[])
                    {
                        ArrayList newValueArrayList = new ArrayList((string[])currentValue);
                        newValueArrayList.RemoveAt(index);
                        currentValue = newValueArrayList.ToArray(typeof(string));
                    }
                    else if (currentValue != null &&
                        currentValue is byte[])
                    {
                        ArrayList newValueArrayList = new ArrayList((byte[])currentValue);
                        newValueArrayList.RemoveAt(index);
                        currentValue = newValueArrayList.ToArray(typeof(byte));
                    }
                    else
//.........这里部分代码省略.........
开发者ID:40a,项目名称:PowerShell,代码行数:101,代码来源:RegistryProvider.cs

示例15: TestFindAttributeMethod50513

        public void TestFindAttributeMethod50513(TestCaseAttribute testCase)
        {
            HeaderComment(testCase);

            ArgumentException ex = new ArgumentException("Unused, just need an instance for GetType() below");

            FindAttributeHelper(SampleText.Empty, TypeValue.WrongTypeAndValue, AttributeType.SupportedAttributes, false, FindResults.Exception, ex.GetType());
        }
开发者ID:sergeyDyadenchuk,项目名称:Testing,代码行数:8,代码来源:TextTests.cs


注:本文中的System.ArgumentException.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。