Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / UnSafeCharBuffer.cs / 1305376 / UnSafeCharBuffer.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: UnSafeBuffer ** ** Purpose: A class to detect incorrect usage of UnSafeBuffer ** ** ===========================================================*/ namespace System { using System.Diagnostics; using System.Diagnostics.Contracts; unsafe internal struct UnSafeCharBuffer{ char * m_buffer; int m_totalSize; int m_length; [System.Security.SecurityCritical] // auto-generated public UnSafeCharBuffer( char *buffer, int bufferSize) { Contract.Assert( buffer != null, "buffer pointer can't be null." ); Contract.Assert( bufferSize >= 0, "buffer size can't be negative." ); m_buffer = buffer; m_totalSize = bufferSize; m_length = 0; } [System.Security.SecuritySafeCritical] // auto-generated public void AppendString(string stringToAppend) { if( String.IsNullOrEmpty( stringToAppend ) ) { return; } if ( (m_totalSize - m_length) < stringToAppend.Length ) { throw new IndexOutOfRangeException(); } fixed( char* pointerToString = stringToAppend ) { Buffer.memcpyimpl( (byte *) pointerToString, (byte*) (m_buffer + m_length), stringToAppend.Length * sizeof(char)); } m_length += stringToAppend.Length; Contract.Assert(m_length <= m_totalSize, "Buffer has been overflowed!"); } public int Length { get { return m_length; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: UnSafeBuffer ** ** Purpose: A class to detect incorrect usage of UnSafeBuffer ** ** ===========================================================*/ namespace System { using System.Diagnostics; using System.Diagnostics.Contracts; unsafe internal struct UnSafeCharBuffer{ char * m_buffer; int m_totalSize; int m_length; [System.Security.SecurityCritical] // auto-generated public UnSafeCharBuffer( char *buffer, int bufferSize) { Contract.Assert( buffer != null, "buffer pointer can't be null." ); Contract.Assert( bufferSize >= 0, "buffer size can't be negative." ); m_buffer = buffer; m_totalSize = bufferSize; m_length = 0; } [System.Security.SecuritySafeCritical] // auto-generated public void AppendString(string stringToAppend) { if( String.IsNullOrEmpty( stringToAppend ) ) { return; } if ( (m_totalSize - m_length) < stringToAppend.Length ) { throw new IndexOutOfRangeException(); } fixed( char* pointerToString = stringToAppend ) { Buffer.memcpyimpl( (byte *) pointerToString, (byte*) (m_buffer + m_length), stringToAppend.Length * sizeof(char)); } m_length += stringToAppend.Length; Contract.Assert(m_length <= m_totalSize, "Buffer has been overflowed!"); } public int Length { get { return m_length; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SoapTypeAttribute.cs
- LocalizationParserHooks.cs
- ClientConvert.cs
- WebZone.cs
- HostExecutionContextManager.cs
- GifBitmapEncoder.cs
- BuildResult.cs
- counter.cs
- OleCmdHelper.cs
- XmlCharCheckingReader.cs
- Properties.cs
- BackStopAuthenticationModule.cs
- ping.cs
- MetadataArtifactLoaderFile.cs
- AttributeParameterInfo.cs
- XmlSchemaParticle.cs
- WeakReferenceEnumerator.cs
- MimeAnyImporter.cs
- DataGridViewComboBoxEditingControl.cs
- OleDbReferenceCollection.cs
- Transform.cs
- TableItemPattern.cs
- FixedSOMLineRanges.cs
- HMACSHA512.cs
- ParentQuery.cs
- ColorConvertedBitmapExtension.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- Socket.cs
- ExpanderAutomationPeer.cs
- DecimalConverter.cs
- HttpCacheVaryByContentEncodings.cs
- MailMessageEventArgs.cs
- LingerOption.cs
- TypeForwardedFromAttribute.cs
- OleDbCommandBuilder.cs
- XmlObjectSerializerReadContext.cs
- RC2CryptoServiceProvider.cs
- QilName.cs
- StateBag.cs
- MethodImplAttribute.cs
- MsmqBindingMonitor.cs
- Stopwatch.cs
- EventProxy.cs
- Drawing.cs
- TimeoutException.cs
- HttpWrapper.cs
- SystemIcmpV6Statistics.cs
- DataTableMapping.cs
- MetadataArtifactLoaderComposite.cs
- GridViewRowPresenter.cs
- EventLogEntry.cs
- PhysicalOps.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- RayMeshGeometry3DHitTestResult.cs
- ImmutableObjectAttribute.cs
- TdsParserStateObject.cs
- EntityTransaction.cs
- XmlSerializationWriter.cs
- DataColumn.cs
- WebPartConnectVerb.cs
- StylusPointProperties.cs
- BypassElement.cs
- AstNode.cs
- _NetworkingPerfCounters.cs
- EarlyBoundInfo.cs
- MimeObjectFactory.cs
- OperationBehaviorAttribute.cs
- TransformCollection.cs
- GatewayDefinition.cs
- BookmarkResumptionRecord.cs
- PerspectiveCamera.cs
- TabItemAutomationPeer.cs
- ReflectionHelper.cs
- ClaimComparer.cs
- UnSafeCharBuffer.cs
- RSAPKCS1SignatureDeformatter.cs
- TableLayoutStyleCollection.cs
- MexBindingBindingCollectionElement.cs
- PointCollection.cs
- Tile.cs
- TableItemProviderWrapper.cs
- ConsoleEntryPoint.cs
- DataKey.cs
- PreviewPrintController.cs
- MobileUserControl.cs
- DataViewSettingCollection.cs
- ToggleButtonAutomationPeer.cs
- SymDocumentType.cs
- AssemblyCollection.cs
- tooltip.cs
- CompilerTypeWithParams.cs
- DetailsViewPagerRow.cs
- RadioButton.cs
- SetStoryboardSpeedRatio.cs
- LocalIdKeyIdentifierClause.cs
- Int64KeyFrameCollection.cs
- EnumBuilder.cs
- ObjectFullSpanRewriter.cs
- BlockUIContainer.cs
- OleDbDataReader.cs