Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Framework / System / Windows / Markup / XamlBrushSerializer.cs / 1 / XamlBrushSerializer.cs
//----------------------------------------------------------------------------
//
// File: XamlBrushSerializer.cs
//
// Description:
// XamlSerializer used to persist Brush objects in Baml
//
// Copyright (C) 2004 by Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Xml;
using MS.Utility;
using MS.Internal;
#if PBTCOMPILER
using System.Reflection;
namespace MS.Internal.Markup
#else
using System.Windows;
using System.Windows.Media;
namespace System.Windows.Markup
#endif
{
///
/// XamlBrushSerializer is used to persist a Brush in Baml files
///
///
/// The brush serializer currently only handles solid color brushes. Other types of
/// are not persisted in a custom binary format.
///
internal class XamlBrushSerializer : XamlSerializer
{
#region Construction
///
/// Constructor for XamlBrushSerializer
///
///
/// This constructor will be used under
/// the following two scenarios
/// 1. Convert a string to a custom binary representation stored in BAML
/// 2. Convert a custom binary representation back into a Brush
///
public XamlBrushSerializer()
{
}
#endregion Construction
#region Conversions
///
/// Convert a string into a compact binary representation and write it out
/// to the passed BinaryWriter.
///
///
/// This is called ONLY from the Parser and is not a general public method.
/// This currently only works for SolidColorBrushes that are identified
/// by a known color name (eg - "Green" )
///
public override bool ConvertStringToCustomBinary (
BinaryWriter writer, // Writer into the baml stream
string stringValue) // String to convert
{
#if !PBTCOMPILER
return SolidColorBrush.SerializeOn(writer, stringValue.Trim());
#else
return SerializeOn(writer, stringValue.Trim());
#endif
}
#if !PBTCOMPILER
///
/// Convert a compact binary representation of a Brush into and instance
/// of Brush. The reader must be left pointing immediately after the object
/// data in the underlying stream.
///
///
/// This is called ONLY from the Parser and is not a general public method.
///
public override object ConvertCustomBinaryToObject(
BinaryReader reader)
{
// ********* VERY IMPORTANT NOTE *****************
// If this method is changed, then BamlPropertyCustomRecord.GetCustomValue() needs
// to be correspondingly changed as well
// ********* VERY IMPORTANT NOTE *****************
return SolidColorBrush.DeserializeFrom(reader);
}
#else
private static bool SerializeOn(BinaryWriter writer, string stringValue)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
KnownColor knownColor = KnownColors.ColorStringToKnownColor(stringValue);
if (knownColor != KnownColor.UnknownColor)
{
// Serialize values of the type "Red", "Blue" and other names
writer.Write((byte)SerializationBrushType.KnownSolidColor);
writer.Write((uint)knownColor);
return true;
}
else
{
// Serialize values of the type "#F00", "#0000FF" and other hex color values.
// We don't have a good way to check if this is valid without running the
// converter at this point, so just store the string if it has at least a
// minimum length of 4.
stringValue = stringValue.Trim();
if (stringValue.Length > 3)
{
writer.Write((byte)SerializationBrushType.OtherColor);
writer.Write(stringValue);
return true;
}
}
return false;
}
// This enum is used to identify brush types for deserialization in the
// ConvertCustomBinaryToObject method.
internal enum SerializationBrushType : byte
{
Unknown = 0,
KnownSolidColor = 1,
OtherColor = 2,
}
#endif
#endregion Conversions
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
// File: XamlBrushSerializer.cs
//
// Description:
// XamlSerializer used to persist Brush objects in Baml
//
// Copyright (C) 2004 by Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Xml;
using MS.Utility;
using MS.Internal;
#if PBTCOMPILER
using System.Reflection;
namespace MS.Internal.Markup
#else
using System.Windows;
using System.Windows.Media;
namespace System.Windows.Markup
#endif
{
///
/// XamlBrushSerializer is used to persist a Brush in Baml files
///
///
/// The brush serializer currently only handles solid color brushes. Other types of
/// are not persisted in a custom binary format.
///
internal class XamlBrushSerializer : XamlSerializer
{
#region Construction
///
/// Constructor for XamlBrushSerializer
///
///
/// This constructor will be used under
/// the following two scenarios
/// 1. Convert a string to a custom binary representation stored in BAML
/// 2. Convert a custom binary representation back into a Brush
///
public XamlBrushSerializer()
{
}
#endregion Construction
#region Conversions
///
/// Convert a string into a compact binary representation and write it out
/// to the passed BinaryWriter.
///
///
/// This is called ONLY from the Parser and is not a general public method.
/// This currently only works for SolidColorBrushes that are identified
/// by a known color name (eg - "Green" )
///
public override bool ConvertStringToCustomBinary (
BinaryWriter writer, // Writer into the baml stream
string stringValue) // String to convert
{
#if !PBTCOMPILER
return SolidColorBrush.SerializeOn(writer, stringValue.Trim());
#else
return SerializeOn(writer, stringValue.Trim());
#endif
}
#if !PBTCOMPILER
///
/// Convert a compact binary representation of a Brush into and instance
/// of Brush. The reader must be left pointing immediately after the object
/// data in the underlying stream.
///
///
/// This is called ONLY from the Parser and is not a general public method.
///
public override object ConvertCustomBinaryToObject(
BinaryReader reader)
{
// ********* VERY IMPORTANT NOTE *****************
// If this method is changed, then BamlPropertyCustomRecord.GetCustomValue() needs
// to be correspondingly changed as well
// ********* VERY IMPORTANT NOTE *****************
return SolidColorBrush.DeserializeFrom(reader);
}
#else
private static bool SerializeOn(BinaryWriter writer, string stringValue)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
KnownColor knownColor = KnownColors.ColorStringToKnownColor(stringValue);
if (knownColor != KnownColor.UnknownColor)
{
// Serialize values of the type "Red", "Blue" and other names
writer.Write((byte)SerializationBrushType.KnownSolidColor);
writer.Write((uint)knownColor);
return true;
}
else
{
// Serialize values of the type "#F00", "#0000FF" and other hex color values.
// We don't have a good way to check if this is valid without running the
// converter at this point, so just store the string if it has at least a
// minimum length of 4.
stringValue = stringValue.Trim();
if (stringValue.Length > 3)
{
writer.Write((byte)SerializationBrushType.OtherColor);
writer.Write(stringValue);
return true;
}
}
return false;
}
// This enum is used to identify brush types for deserialization in the
// ConvertCustomBinaryToObject method.
internal enum SerializationBrushType : byte
{
Unknown = 0,
KnownSolidColor = 1,
OtherColor = 2,
}
#endif
#endregion Conversions
}
}
// 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
- OpenTypeCommon.cs
- GuidelineCollection.cs
- InheritanceContextChangedEventManager.cs
- _NtlmClient.cs
- AccessKeyManager.cs
- TrackingStringDictionary.cs
- HtmlTable.cs
- DependencyPropertyKind.cs
- ContentDisposition.cs
- DrawingContextDrawingContextWalker.cs
- TextRange.cs
- LocationChangedEventArgs.cs
- DataTableMappingCollection.cs
- HtmlImageAdapter.cs
- PersonalizationEntry.cs
- HttpProfileGroupBase.cs
- NonSerializedAttribute.cs
- TemplateControlBuildProvider.cs
- ParallelSeparator.xaml.cs
- GradientBrush.cs
- sqlnorm.cs
- smtpconnection.cs
- DataColumnCollection.cs
- SafeRightsManagementPubHandle.cs
- XmlCollation.cs
- XmlConvert.cs
- BuildResult.cs
- AsymmetricSecurityBindingElement.cs
- LineServicesRun.cs
- WmlFormAdapter.cs
- FlowDocumentScrollViewer.cs
- TableHeaderCell.cs
- ObjectView.cs
- MarkupCompilePass1.cs
- PasswordRecovery.cs
- DispatcherOperation.cs
- GridViewRowEventArgs.cs
- sqlser.cs
- DataGridViewColumnConverter.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- BamlTreeNode.cs
- SecurityKeyEntropyMode.cs
- ProfileProvider.cs
- EndSelectCardRequest.cs
- ToolStripContainerActionList.cs
- SerializationInfoEnumerator.cs
- FixedFindEngine.cs
- AppDomainUnloadedException.cs
- GeneralTransform.cs
- ClientSideQueueItem.cs
- CheckBox.cs
- EventData.cs
- TagNameToTypeMapper.cs
- _ProxyRegBlob.cs
- ZipPackage.cs
- XhtmlBasicLabelAdapter.cs
- ContainerUtilities.cs
- sapiproxy.cs
- QilGeneratorEnv.cs
- SignatureConfirmationElement.cs
- ScopelessEnumAttribute.cs
- Axis.cs
- MasterPageBuildProvider.cs
- PeerApplicationLaunchInfo.cs
- FontInfo.cs
- DetailsViewRow.cs
- Missing.cs
- DataGridViewSelectedCellsAccessibleObject.cs
- HttpCachePolicyElement.cs
- HealthMonitoringSectionHelper.cs
- FontUnit.cs
- DropTarget.cs
- DelayedRegex.cs
- RSACryptoServiceProvider.cs
- HTMLTagNameToTypeMapper.cs
- NameSpaceExtractor.cs
- OracleTimeSpan.cs
- ListSortDescriptionCollection.cs
- QueryConverter.cs
- DtrList.cs
- PipelineDeploymentState.cs
- HttpGetClientProtocol.cs
- TextServicesManager.cs
- BooleanFunctions.cs
- WebEvents.cs
- TickBar.cs
- KeyConstraint.cs
- Type.cs
- ToolbarAUtomationPeer.cs
- ClientFormsAuthenticationCredentials.cs
- XPathBinder.cs
- BaseTemplateCodeDomTreeGenerator.cs
- ToolStripSeparator.cs
- DocumentEventArgs.cs
- AdapterUtil.cs
- NodeFunctions.cs
- Range.cs
- CursorInteropHelper.cs
- QilReference.cs
- InputManager.cs