Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Framework / System / Windows / Markup / XamlWriter.cs / 1 / XamlWriter.cs
//----------------------------------------------------------------------------
//
// File: XamlWriter.cs
//
// Description:
// base Parser class that parses XML markup into an Avalon Element Tree
//
//
// History:
// 6/06/01: rogerg Created as Parser.cs
// 5/29/03: peterost Ported to wcp as Parser.cs
// 8/04/05: a-neabbu Split Parser into XamlReader and XamlWriter
//
// Copyright (C) 2003 by Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System;
using System.Xml;
using System.IO;
using System.IO.Packaging;
using System.Windows;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Threading;
using MS.Utility;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
using System.Text;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Windows.Markup.Primitives;
using MS.Internal.IO.Packaging;
using MS.Internal.PresentationFramework;
namespace System.Windows.Markup
{
///
/// Parsing class used to create an Windows Presentation Platform Tree
///
public static class XamlWriter
{
#region Public Methods
///
/// Save gets the xml respresentation
/// for the given object instance
///
///
/// Object instance
///
///
/// XAML string representing object instance
///
///
/// We only allow Serialization in partial trust. Although we would throw an exception later anyways,
/// we throw one here so we know where to expect the exception. (
public static string Save(object obj)
{
// Must be in full trust
SecurityHelper.DemandUnmanagedCode();
// Validate input arguments
if (obj == null)
{
throw new ArgumentNullException("obj");
}
// Create TextWriter
StringBuilder sb = new StringBuilder();
TextWriter writer = new StringWriter(sb, XamlSerializerUtil.EnglishUSCulture);
try
{
Save(obj, writer);
}
finally
{
// Close writer
writer.Close();
}
return sb.ToString();
}
///
/// Save writes the xml respresentation
/// for the given object instance using the given writer
///
///
/// Object instance
///
///
/// Text Writer
///
///
/// We only allow Serialization in partial trust. Although we would throw an exception later anyways,
/// we throw one here so we know where to expect the exception. (
public static void Save(object obj, TextWriter writer)
{
// Must be in full trust
SecurityHelper.DemandUnmanagedCode();
// Validate input arguments
if (obj == null)
{
throw new ArgumentNullException("obj");
}
if (writer == null)
{
throw new ArgumentNullException("writer");
}
// Create XmlTextWriter
XmlTextWriter xmlWriter = new XmlTextWriter(writer);
MarkupWriter.SaveAsXml(xmlWriter, obj);
}
///
/// Save writes the xml respresentation
/// for the given object instance to the given stream
///
///
/// Object instance
///
///
/// Stream
///
///
/// We only allow Serialization in partial trust. Although we would throw an exception later anyways,
/// we throw one here so we know where to expect the exception. (
public static void Save(object obj, Stream stream)
{
// Must be in full trust
SecurityHelper.DemandUnmanagedCode();
// Validate input arguments
if (obj == null)
{
throw new ArgumentNullException("obj");
}
if (stream == null)
{
throw new ArgumentNullException("stream");
}
// Create XmlTextWriter
XmlTextWriter xmlWriter = new XmlTextWriter(stream, null);
MarkupWriter.SaveAsXml(xmlWriter, obj);
}
///
/// Save writes the xml respresentation
/// for the given object instance using the given
/// writer. In addition it also allows the designer
/// to participate in this conversion.
///
///
/// Object instance
///
///
/// XmlWriter
///
///
/// We only allow Serialization in partial trust. Although we would throw an exception later anyways,
/// we throw one here so we know where to expect the exception. (
public static void Save(object obj, XmlWriter xmlWriter)
{
// Must be in full trust
SecurityHelper.DemandUnmanagedCode();
// Validate input arguments
if (obj == null)
{
throw new ArgumentNullException("obj");
}
if (xmlWriter == null)
{
throw new ArgumentNullException("xmlWriter");
}
try
{
MarkupWriter.SaveAsXml(xmlWriter, obj);
}
finally
{
xmlWriter.Flush();
}
}
///
/// Save writes the xml respresentation
/// for the given object instance using the
/// given XmlTextWriter embedded in the manager.
///
///
/// Object instance
///
///
/// Serialization Manager
///
///
/// We only allow Serialization in partial trust. Although we would throw an exception later anyways,
/// we throw one here so we know where to expect the exception. (
public static void Save(object obj, XamlDesignerSerializationManager manager)
{
// Must be in full trust
SecurityHelper.DemandUnmanagedCode();
// Validate input arguments
if (obj == null)
{
throw new ArgumentNullException("obj");
}
if (manager == null)
{
throw new ArgumentNullException("manager");
}
MarkupWriter.SaveAsXml(manager.XmlWriter, obj, manager);
}
#endregion Public Methods
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
// File: XamlWriter.cs
//
// Description:
// base Parser class that parses XML markup into an Avalon Element Tree
//
//
// History:
// 6/06/01: rogerg Created as Parser.cs
// 5/29/03: peterost Ported to wcp as Parser.cs
// 8/04/05: a-neabbu Split Parser into XamlReader and XamlWriter
//
// Copyright (C) 2003 by Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System;
using System.Xml;
using System.IO;
using System.IO.Packaging;
using System.Windows;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Threading;
using MS.Utility;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
using System.Text;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Windows.Markup.Primitives;
using MS.Internal.IO.Packaging;
using MS.Internal.PresentationFramework;
namespace System.Windows.Markup
{
///
/// Parsing class used to create an Windows Presentation Platform Tree
///
public static class XamlWriter
{
#region Public Methods
///
/// Save gets the xml respresentation
/// for the given object instance
///
///
/// Object instance
///
///
/// XAML string representing object instance
///
///
/// We only allow Serialization in partial trust. Although we would throw an exception later anyways,
/// we throw one here so we know where to expect the exception. (
public static string Save(object obj)
{
// Must be in full trust
SecurityHelper.DemandUnmanagedCode();
// Validate input arguments
if (obj == null)
{
throw new ArgumentNullException("obj");
}
// Create TextWriter
StringBuilder sb = new StringBuilder();
TextWriter writer = new StringWriter(sb, XamlSerializerUtil.EnglishUSCulture);
try
{
Save(obj, writer);
}
finally
{
// Close writer
writer.Close();
}
return sb.ToString();
}
///
/// Save writes the xml respresentation
/// for the given object instance using the given writer
///
///
/// Object instance
///
///
/// Text Writer
///
///
/// We only allow Serialization in partial trust. Although we would throw an exception later anyways,
/// we throw one here so we know where to expect the exception. (
public static void Save(object obj, TextWriter writer)
{
// Must be in full trust
SecurityHelper.DemandUnmanagedCode();
// Validate input arguments
if (obj == null)
{
throw new ArgumentNullException("obj");
}
if (writer == null)
{
throw new ArgumentNullException("writer");
}
// Create XmlTextWriter
XmlTextWriter xmlWriter = new XmlTextWriter(writer);
MarkupWriter.SaveAsXml(xmlWriter, obj);
}
///
/// Save writes the xml respresentation
/// for the given object instance to the given stream
///
///
/// Object instance
///
///
/// Stream
///
///
/// We only allow Serialization in partial trust. Although we would throw an exception later anyways,
/// we throw one here so we know where to expect the exception. (
public static void Save(object obj, Stream stream)
{
// Must be in full trust
SecurityHelper.DemandUnmanagedCode();
// Validate input arguments
if (obj == null)
{
throw new ArgumentNullException("obj");
}
if (stream == null)
{
throw new ArgumentNullException("stream");
}
// Create XmlTextWriter
XmlTextWriter xmlWriter = new XmlTextWriter(stream, null);
MarkupWriter.SaveAsXml(xmlWriter, obj);
}
///
/// Save writes the xml respresentation
/// for the given object instance using the given
/// writer. In addition it also allows the designer
/// to participate in this conversion.
///
///
/// Object instance
///
///
/// XmlWriter
///
///
/// We only allow Serialization in partial trust. Although we would throw an exception later anyways,
/// we throw one here so we know where to expect the exception. (
public static void Save(object obj, XmlWriter xmlWriter)
{
// Must be in full trust
SecurityHelper.DemandUnmanagedCode();
// Validate input arguments
if (obj == null)
{
throw new ArgumentNullException("obj");
}
if (xmlWriter == null)
{
throw new ArgumentNullException("xmlWriter");
}
try
{
MarkupWriter.SaveAsXml(xmlWriter, obj);
}
finally
{
xmlWriter.Flush();
}
}
///
/// Save writes the xml respresentation
/// for the given object instance using the
/// given XmlTextWriter embedded in the manager.
///
///
/// Object instance
///
///
/// Serialization Manager
///
///
/// We only allow Serialization in partial trust. Although we would throw an exception later anyways,
/// we throw one here so we know where to expect the exception. (
public static void Save(object obj, XamlDesignerSerializationManager manager)
{
// Must be in full trust
SecurityHelper.DemandUnmanagedCode();
// Validate input arguments
if (obj == null)
{
throw new ArgumentNullException("obj");
}
if (manager == null)
{
throw new ArgumentNullException("manager");
}
MarkupWriter.SaveAsXml(manager.XmlWriter, obj, manager);
}
#endregion Public Methods
}
}
// 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
- ContainerVisual.cs
- CompilerGlobalScopeAttribute.cs
- ApplicationServiceHelper.cs
- PolyLineSegmentFigureLogic.cs
- ResourceReferenceExpressionConverter.cs
- SqlConnectionManager.cs
- SymLanguageType.cs
- RadioButtonStandardAdapter.cs
- log.cs
- UnescapedXmlDiagnosticData.cs
- PolyLineSegment.cs
- SerialPort.cs
- XmlDictionaryWriter.cs
- DbConnectionPoolGroupProviderInfo.cs
- Baml2006ReaderFrame.cs
- Invariant.cs
- NamedPipeTransportSecurity.cs
- AffineTransform3D.cs
- SecurityCriticalDataForSet.cs
- DataListItemCollection.cs
- ServicePointManager.cs
- CommandHelpers.cs
- SynchronizationContextHelper.cs
- UniqueConstraint.cs
- InvalidEnumArgumentException.cs
- SspiWrapper.cs
- BitmapEffectGeneralTransform.cs
- DesignerActionVerbList.cs
- TextRangeEditTables.cs
- OracleNumber.cs
- RequestCachePolicy.cs
- DbProviderFactoriesConfigurationHandler.cs
- ToolStripOverflowButton.cs
- XmlDataLoader.cs
- TreeNodeCollection.cs
- SystemParameters.cs
- UITypeEditor.cs
- UInt32Converter.cs
- TypeBuilder.cs
- HitTestParameters3D.cs
- ClrPerspective.cs
- MetadataCollection.cs
- StretchValidation.cs
- XmlObjectSerializerReadContextComplex.cs
- RectValueSerializer.cs
- BoundPropertyEntry.cs
- FixedFindEngine.cs
- FillErrorEventArgs.cs
- MemberRestriction.cs
- TransportReplyChannelAcceptor.cs
- HandlerWithFactory.cs
- Image.cs
- StrokeNodeEnumerator.cs
- ExpressionBuilderCollection.cs
- EntityCollection.cs
- IOException.cs
- Base64Encoder.cs
- XmlQueryContext.cs
- ExtendedPropertyCollection.cs
- WindowsFormsSynchronizationContext.cs
- DesignerRegionCollection.cs
- XmlCDATASection.cs
- GridViewCellAutomationPeer.cs
- InputReport.cs
- TimelineGroup.cs
- SqlProcedureAttribute.cs
- MenuEventArgs.cs
- WebConfigurationManager.cs
- SmiEventSink_DeferedProcessing.cs
- ConnectionsZone.cs
- XAMLParseException.cs
- listitem.cs
- SoapInteropTypes.cs
- ApplicationSettingsBase.cs
- AssemblyBuilderData.cs
- SizeLimitedCache.cs
- Events.cs
- TypefaceMetricsCache.cs
- BinaryObjectWriter.cs
- BaseTreeIterator.cs
- DataTemplateSelector.cs
- Int32.cs
- DodSequenceMerge.cs
- ImageSource.cs
- ListView.cs
- XmlHierarchicalEnumerable.cs
- WaitForChangedResult.cs
- _DomainName.cs
- RootBuilder.cs
- CacheOutputQuery.cs
- IListConverters.cs
- PagerSettings.cs
- basemetadatamappingvisitor.cs
- PlaceHolder.cs
- TypeInitializationException.cs
- Int32AnimationUsingKeyFrames.cs
- TiffBitmapEncoder.cs
- TraceHandlerErrorFormatter.cs
- LinqDataSourceDisposeEventArgs.cs
- NeutralResourcesLanguageAttribute.cs