Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Core / CSharp / System / Windows / Media / textformatting / CharacterBufferReference.cs / 1 / CharacterBufferReference.cs
//------------------------------------------------------------------------
//
// Microsoft Windows Client Platform
// Copyright (C) Microsoft Corporation, 2003
//
// File: CharacterBufferReference.cs
//
// Contents: Text Character buffer reference
//
// Spec: http://team/sites/Avalon/Specs/Text%20Formatting%20API.doc
//
// Created: 2-5-2004 Worachai Chaoweeraprasit (wchao)
//
//-----------------------------------------------------------------------
using System;
using System.Diagnostics;
using MS.Internal;
using System.Security;
using System.Security.Permissions;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
namespace System.Windows.Media.TextFormatting
{
///
/// Text character buffer reference
///
public struct CharacterBufferReference : IEquatable
{
private CharacterBuffer _charBuffer;
private int _offsetToFirstChar;
#region Constructor
///
/// Construct character buffer reference from character array
///
/// character array
/// character buffer offset to the first character
public CharacterBufferReference(
char[] characterArray,
int offsetToFirstChar
)
: this(
new CharArrayCharacterBuffer(characterArray),
offsetToFirstChar
)
{}
///
/// Construct character buffer reference from string
///
/// character string
/// character buffer offset to the first character
public CharacterBufferReference(
string characterString,
int offsetToFirstChar
)
: this(
new StringCharacterBuffer(characterString),
offsetToFirstChar
)
{}
///
/// Construct character buffer reference from unsafe character string
///
/// pointer to character string
/// character length of unsafe string
///
/// Critical: This manipulates unsafe pointers and calls into the critical UnsafeStringCharacterBuffer ctor.
/// PublicOK: The caller needs unmanaged code permission in order to pass unsafe pointers to us.
///
[SecurityCritical]
[CLSCompliant(false)]
public unsafe CharacterBufferReference(
char* unsafeCharacterString,
int characterLength
)
: this(new UnsafeStringCharacterBuffer(unsafeCharacterString, characterLength), 0)
{}
///
/// Construct character buffer reference from memory buffer
///
internal CharacterBufferReference(
CharacterBuffer charBuffer,
int offsetToFirstChar
)
{
if (offsetToFirstChar < 0)
{
throw new ArgumentOutOfRangeException("offsetToFirstChar", SR.Get(SRID.ParameterCannotBeNegative));
}
// maximum offset is one less than CharacterBuffer.Count, except that zero is always a valid offset
// even in the case of an empty or null character buffer
int maxOffset = (charBuffer == null) ? 0 : Math.Max(0, charBuffer.Count - 1);
if (offsetToFirstChar > maxOffset)
{
throw new ArgumentOutOfRangeException("offsetToFirstChar", SR.Get(SRID.ParameterCannotBeGreaterThan, maxOffset));
}
_charBuffer = charBuffer;
_offsetToFirstChar = offsetToFirstChar;
}
#endregion
///
/// Compute hash code
///
public override int GetHashCode()
{
return _charBuffer != null ? _charBuffer.GetHashCode() ^ _offsetToFirstChar : 0;
}
///
/// Test equality with the input object
///
/// The object to test.
public override bool Equals(object obj)
{
if (obj is CharacterBufferReference)
{
return Equals((CharacterBufferReference)obj);
}
return false;
}
///
/// Test equality with the input CharacterBufferReference
///
/// The characterBufferReference value to test
public bool Equals(CharacterBufferReference value)
{
return _charBuffer == value._charBuffer
&& _offsetToFirstChar == value._offsetToFirstChar;
}
///
/// Compare two CharacterBufferReference for equality
///
/// left operand
/// right operand
/// whether or not two operands are equal
public static bool operator == (
CharacterBufferReference left,
CharacterBufferReference right
)
{
return left.Equals(right);
}
///
/// Compare two CharacterBufferReference for inequality
///
/// left operand
/// right operand
/// whether or not two operands are equal
public static bool operator != (
CharacterBufferReference left,
CharacterBufferReference right
)
{
return !(left == right);
}
internal CharacterBuffer CharacterBuffer
{
get { return _charBuffer; }
}
internal int OffsetToFirstChar
{
get { return _offsetToFirstChar; }
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------
//
// Microsoft Windows Client Platform
// Copyright (C) Microsoft Corporation, 2003
//
// File: CharacterBufferReference.cs
//
// Contents: Text Character buffer reference
//
// Spec: http://team/sites/Avalon/Specs/Text%20Formatting%20API.doc
//
// Created: 2-5-2004 Worachai Chaoweeraprasit (wchao)
//
//-----------------------------------------------------------------------
using System;
using System.Diagnostics;
using MS.Internal;
using System.Security;
using System.Security.Permissions;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
namespace System.Windows.Media.TextFormatting
{
///
/// Text character buffer reference
///
public struct CharacterBufferReference : IEquatable
{
private CharacterBuffer _charBuffer;
private int _offsetToFirstChar;
#region Constructor
///
/// Construct character buffer reference from character array
///
/// character array
/// character buffer offset to the first character
public CharacterBufferReference(
char[] characterArray,
int offsetToFirstChar
)
: this(
new CharArrayCharacterBuffer(characterArray),
offsetToFirstChar
)
{}
///
/// Construct character buffer reference from string
///
/// character string
/// character buffer offset to the first character
public CharacterBufferReference(
string characterString,
int offsetToFirstChar
)
: this(
new StringCharacterBuffer(characterString),
offsetToFirstChar
)
{}
///
/// Construct character buffer reference from unsafe character string
///
/// pointer to character string
/// character length of unsafe string
///
/// Critical: This manipulates unsafe pointers and calls into the critical UnsafeStringCharacterBuffer ctor.
/// PublicOK: The caller needs unmanaged code permission in order to pass unsafe pointers to us.
///
[SecurityCritical]
[CLSCompliant(false)]
public unsafe CharacterBufferReference(
char* unsafeCharacterString,
int characterLength
)
: this(new UnsafeStringCharacterBuffer(unsafeCharacterString, characterLength), 0)
{}
///
/// Construct character buffer reference from memory buffer
///
internal CharacterBufferReference(
CharacterBuffer charBuffer,
int offsetToFirstChar
)
{
if (offsetToFirstChar < 0)
{
throw new ArgumentOutOfRangeException("offsetToFirstChar", SR.Get(SRID.ParameterCannotBeNegative));
}
// maximum offset is one less than CharacterBuffer.Count, except that zero is always a valid offset
// even in the case of an empty or null character buffer
int maxOffset = (charBuffer == null) ? 0 : Math.Max(0, charBuffer.Count - 1);
if (offsetToFirstChar > maxOffset)
{
throw new ArgumentOutOfRangeException("offsetToFirstChar", SR.Get(SRID.ParameterCannotBeGreaterThan, maxOffset));
}
_charBuffer = charBuffer;
_offsetToFirstChar = offsetToFirstChar;
}
#endregion
///
/// Compute hash code
///
public override int GetHashCode()
{
return _charBuffer != null ? _charBuffer.GetHashCode() ^ _offsetToFirstChar : 0;
}
///
/// Test equality with the input object
///
/// The object to test.
public override bool Equals(object obj)
{
if (obj is CharacterBufferReference)
{
return Equals((CharacterBufferReference)obj);
}
return false;
}
///
/// Test equality with the input CharacterBufferReference
///
/// The characterBufferReference value to test
public bool Equals(CharacterBufferReference value)
{
return _charBuffer == value._charBuffer
&& _offsetToFirstChar == value._offsetToFirstChar;
}
///
/// Compare two CharacterBufferReference for equality
///
/// left operand
/// right operand
/// whether or not two operands are equal
public static bool operator == (
CharacterBufferReference left,
CharacterBufferReference right
)
{
return left.Equals(right);
}
///
/// Compare two CharacterBufferReference for inequality
///
/// left operand
/// right operand
/// whether or not two operands are equal
public static bool operator != (
CharacterBufferReference left,
CharacterBufferReference right
)
{
return !(left == right);
}
internal CharacterBuffer CharacterBuffer
{
get { return _charBuffer; }
}
internal int OffsetToFirstChar
{
get { return _offsetToFirstChar; }
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- GeometryModel3D.cs
- GenericRootAutomationPeer.cs
- AppSettingsExpressionBuilder.cs
- DropTarget.cs
- LiteralControl.cs
- DynamicMethod.cs
- Rules.cs
- MessageQueueAccessControlEntry.cs
- OutKeywords.cs
- ViewBase.cs
- BitSet.cs
- ComponentSerializationService.cs
- RegisteredHiddenField.cs
- SHA256.cs
- JsonReader.cs
- TreeNodeSelectionProcessor.cs
- TriggerActionCollection.cs
- TextEffect.cs
- DrawingBrush.cs
- IssuedTokenClientBehaviorsElement.cs
- CompiledRegexRunnerFactory.cs
- StylusEditingBehavior.cs
- KeyBinding.cs
- FamilyTypefaceCollection.cs
- AstTree.cs
- ObjectRef.cs
- AttributeCallbackBuilder.cs
- COM2IPerPropertyBrowsingHandler.cs
- BrowserCapabilitiesFactoryBase.cs
- TimeSpanOrInfiniteValidator.cs
- PersonalizableAttribute.cs
- followingquery.cs
- CodeTypeParameterCollection.cs
- ManagedWndProcTracker.cs
- ExpressionEditorAttribute.cs
- ConsoleKeyInfo.cs
- DataSourceExpressionCollection.cs
- InvalidOleVariantTypeException.cs
- LambdaCompiler.Binary.cs
- InvariantComparer.cs
- FragmentNavigationEventArgs.cs
- ListBoxAutomationPeer.cs
- ConditionalAttribute.cs
- AnyReturnReader.cs
- WeakReferenceList.cs
- BitStream.cs
- JsonClassDataContract.cs
- CompilerError.cs
- XmlSchemaComplexContent.cs
- AssemblyInfo.cs
- safemediahandle.cs
- HttpResponse.cs
- FontFamily.cs
- NativeMethods.cs
- BitmapEffectGeneralTransform.cs
- StructuredTypeEmitter.cs
- WebPartPersonalization.cs
- DelimitedListTraceListener.cs
- SiteMapPath.cs
- StylusPlugInCollection.cs
- ContractMethodParameterInfo.cs
- ThreadPool.cs
- DataGridViewSelectedCellCollection.cs
- DataTableExtensions.cs
- SupportingTokenBindingElement.cs
- ClickablePoint.cs
- ContentControl.cs
- DataGridViewCellValueEventArgs.cs
- ConstraintEnumerator.cs
- DataSetUtil.cs
- ValidatorCompatibilityHelper.cs
- DataSourceControl.cs
- SourceFileInfo.cs
- PaperSize.cs
- EntityDataSourceColumn.cs
- SocketException.cs
- BehaviorDragDropEventArgs.cs
- ItemList.cs
- XmlSchemaCollection.cs
- GeneralTransform3DTo2D.cs
- XmlSchemaSimpleTypeRestriction.cs
- TypeConvertions.cs
- XmlArrayItemAttribute.cs
- DrawingContextDrawingContextWalker.cs
- SiteMapNode.cs
- HtmlWindowCollection.cs
- LinearGradientBrush.cs
- BasePattern.cs
- securitymgrsite.cs
- SecurityKeyType.cs
- NumberFormatInfo.cs
- XmlNamespaceMappingCollection.cs
- initElementDictionary.cs
- TiffBitmapDecoder.cs
- InputReportEventArgs.cs
- xsdvalidator.cs
- CodeTypeDeclarationCollection.cs
- Point3DAnimationUsingKeyFrames.cs
- UInt32Storage.cs
- TextUtf8RawTextWriter.cs