Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Common / AuthoringOM / Serializer / XamlInterfaces.cs / 1305376 / XamlInterfaces.cs
using System;
using System.Collections;
using System.Workflow.ComponentModel.Compiler;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Workflow.ComponentModel.Serialization;
using System.ComponentModel.Design;
using System.Xml;
using System.Diagnostics;
using System.Collections.Generic;
namespace System.Workflow.ComponentModel.Serialization
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class XmlnsDefinitionAttribute : Attribute
{
public XmlnsDefinitionAttribute(string xmlNamespace, string clrNamespace)
{
if (xmlNamespace == null)
throw new ArgumentNullException("xmlNamespace");
if (clrNamespace == null)
throw new ArgumentNullException("clrNamespace");
this.xmlNamespace = xmlNamespace;
this.clrNamespace = clrNamespace;
}
public string XmlNamespace
{
get { return this.xmlNamespace; }
}
public string ClrNamespace
{
get { return this.clrNamespace; }
}
public string AssemblyName
{
get { return this.assemblyName; }
set { this.assemblyName = value; }
}
private string xmlNamespace;
private string clrNamespace;
private string assemblyName;
}
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class XmlnsPrefixAttribute : Attribute
{
private string xmlNamespace;
private string prefix;
public XmlnsPrefixAttribute(string xmlNamespace, string prefix)
{
if (xmlNamespace == null)
throw new ArgumentNullException("xmlNamespace");
if (prefix == null)
throw new ArgumentNullException("prefix");
this.xmlNamespace = xmlNamespace;
this.prefix = prefix;
}
public string XmlNamespace
{
get { return this.xmlNamespace; }
}
public string Prefix
{
get { return this.prefix; }
}
}
[AttributeUsage(AttributeTargets.Class)]
public sealed class RuntimeNamePropertyAttribute : Attribute
{
private string name = null;
public RuntimeNamePropertyAttribute(string name)
{
this.name = name;
}
public string Name
{
get
{
return this.name;
}
}
}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class ContentPropertyAttribute : Attribute
{
private string name;
public ContentPropertyAttribute(){}
public ContentPropertyAttribute(string name)
{
this.name = name;
}
public string Name
{
get { return this.name; }
}
}
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public sealed class ConstructorArgumentAttribute : Attribute
{
private string argumentName;
public ConstructorArgumentAttribute(string argumentName)
{
this.argumentName = argumentName;
}
public string ArgumentName
{
get { return this.argumentName; }
}
}
public abstract class MarkupExtension
{
public abstract object ProvideValue(IServiceProvider provider);
}
[DesignerSerializer(typeof(MarkupExtensionSerializer), typeof(WorkflowMarkupSerializer))]
internal sealed class NullExtension : MarkupExtension
{
public NullExtension(){}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return null;
}
}
[DesignerSerializer(typeof(TypeExtensionSerializer), typeof(WorkflowMarkupSerializer))]
internal sealed class TypeExtension : MarkupExtension
{
private string typeName;
private Type type;
public TypeExtension(){}
public TypeExtension(string type)
{
if (type == null)
throw new ArgumentNullException("typeName");
this.typeName = type;
}
public TypeExtension(Type type)
{
if (type == null)
throw new ArgumentNullException("type");
this.type = type;
}
public override object ProvideValue(IServiceProvider provider)
{
if (this.type != null)
return this.type;
if (provider == null)
throw new ArgumentNullException("provider");
if (this.typeName == null)
throw new InvalidOperationException("typename");
WorkflowMarkupSerializationManager manager = provider as WorkflowMarkupSerializationManager;
if (manager == null)
throw new ArgumentNullException("provider");
XmlReader reader = manager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader;
if (reader == null)
{
Debug.Assert(false);
return this.typeName;
}
string typename = this.typeName.Trim();
string prefix = String.Empty;
int typeIndex = typename.IndexOf(':');
if (typeIndex >= 0)
{
prefix = typename.Substring(0, typeIndex);
typename = typename.Substring(typeIndex + 1);
type = manager.GetType(new XmlQualifiedName(typename, reader.LookupNamespace(prefix)));
if (type != null)
return type;
// To Support types whose assembly is not available, we need to still resolve the clr namespace
List xmlnsMappings = null;
if (manager.XmlNamespaceBasedMappings.TryGetValue(reader.LookupNamespace(prefix), out xmlnsMappings) && xmlnsMappings != null && xmlnsMappings.Count > 0)
return xmlnsMappings[0].ClrNamespace + "." + typename;
else
return typename;
}
type = manager.GetType(new XmlQualifiedName(typename, reader.LookupNamespace(string.Empty)));
// To Support Beta2 format
if (type == null)
{
ITypeProvider typeProvider = provider.GetService(typeof(ITypeProvider)) as ITypeProvider;
if (typeProvider != null)
type = typeProvider.GetType(typename);
// If not design mode, get the value from serialization manager
// At design time, we need to get the type from ITypeProvider else
// we need to store the string in the hashtable we maintain internally
if (type == null && manager.GetService(typeof(ITypeResolutionService)) == null)
type = manager.SerializationManager.GetType(typename);
}
if (type != null)
return type;
return this.typeName;
}
[DefaultValue(null)]
[ConstructorArgument("type")]
public string TypeName
{
get
{
if (this.type != null)
return this.type.FullName;
return this.typeName;
}
set
{
if (value == null)
throw new ArgumentNullException("value");
this.typeName = value;
}
}
internal Type Type
{
get { return this.type; }
}
}
[ContentProperty("Items")]
internal sealed class ArrayExtension : MarkupExtension
{
private ArrayList arrayElementList = new ArrayList();
private Type arrayType;
public ArrayExtension()
{
}
public ArrayExtension(Type arrayType)
{
if (arrayType == null)
throw new ArgumentNullException("arrayType");
this.arrayType = arrayType;
}
public ArrayExtension(Array elements)
{
if (elements == null)
throw new ArgumentNullException("elements");
arrayElementList.AddRange(elements);
this.arrayType = elements.GetType().GetElementType();
}
//
public Type Type
{
get
{
return this.arrayType;
}
set
{
this.arrayType = value;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public IList Items
{
get
{
return arrayElementList;
}
}
public override object ProvideValue(IServiceProvider provider)
{
if (provider == null)
throw new ArgumentNullException("provider");
if (this.arrayType == null)
throw new InvalidOperationException("ArrayType needs to be set.");
object retArray = null;
try
{
retArray = arrayElementList.ToArray(this.arrayType);
}
catch (System.InvalidCastException)
{
//
throw new InvalidOperationException();
}
return retArray;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.Collections;
using System.Workflow.ComponentModel.Compiler;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Workflow.ComponentModel.Serialization;
using System.ComponentModel.Design;
using System.Xml;
using System.Diagnostics;
using System.Collections.Generic;
namespace System.Workflow.ComponentModel.Serialization
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class XmlnsDefinitionAttribute : Attribute
{
public XmlnsDefinitionAttribute(string xmlNamespace, string clrNamespace)
{
if (xmlNamespace == null)
throw new ArgumentNullException("xmlNamespace");
if (clrNamespace == null)
throw new ArgumentNullException("clrNamespace");
this.xmlNamespace = xmlNamespace;
this.clrNamespace = clrNamespace;
}
public string XmlNamespace
{
get { return this.xmlNamespace; }
}
public string ClrNamespace
{
get { return this.clrNamespace; }
}
public string AssemblyName
{
get { return this.assemblyName; }
set { this.assemblyName = value; }
}
private string xmlNamespace;
private string clrNamespace;
private string assemblyName;
}
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class XmlnsPrefixAttribute : Attribute
{
private string xmlNamespace;
private string prefix;
public XmlnsPrefixAttribute(string xmlNamespace, string prefix)
{
if (xmlNamespace == null)
throw new ArgumentNullException("xmlNamespace");
if (prefix == null)
throw new ArgumentNullException("prefix");
this.xmlNamespace = xmlNamespace;
this.prefix = prefix;
}
public string XmlNamespace
{
get { return this.xmlNamespace; }
}
public string Prefix
{
get { return this.prefix; }
}
}
[AttributeUsage(AttributeTargets.Class)]
public sealed class RuntimeNamePropertyAttribute : Attribute
{
private string name = null;
public RuntimeNamePropertyAttribute(string name)
{
this.name = name;
}
public string Name
{
get
{
return this.name;
}
}
}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class ContentPropertyAttribute : Attribute
{
private string name;
public ContentPropertyAttribute(){}
public ContentPropertyAttribute(string name)
{
this.name = name;
}
public string Name
{
get { return this.name; }
}
}
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public sealed class ConstructorArgumentAttribute : Attribute
{
private string argumentName;
public ConstructorArgumentAttribute(string argumentName)
{
this.argumentName = argumentName;
}
public string ArgumentName
{
get { return this.argumentName; }
}
}
public abstract class MarkupExtension
{
public abstract object ProvideValue(IServiceProvider provider);
}
[DesignerSerializer(typeof(MarkupExtensionSerializer), typeof(WorkflowMarkupSerializer))]
internal sealed class NullExtension : MarkupExtension
{
public NullExtension(){}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return null;
}
}
[DesignerSerializer(typeof(TypeExtensionSerializer), typeof(WorkflowMarkupSerializer))]
internal sealed class TypeExtension : MarkupExtension
{
private string typeName;
private Type type;
public TypeExtension(){}
public TypeExtension(string type)
{
if (type == null)
throw new ArgumentNullException("typeName");
this.typeName = type;
}
public TypeExtension(Type type)
{
if (type == null)
throw new ArgumentNullException("type");
this.type = type;
}
public override object ProvideValue(IServiceProvider provider)
{
if (this.type != null)
return this.type;
if (provider == null)
throw new ArgumentNullException("provider");
if (this.typeName == null)
throw new InvalidOperationException("typename");
WorkflowMarkupSerializationManager manager = provider as WorkflowMarkupSerializationManager;
if (manager == null)
throw new ArgumentNullException("provider");
XmlReader reader = manager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader;
if (reader == null)
{
Debug.Assert(false);
return this.typeName;
}
string typename = this.typeName.Trim();
string prefix = String.Empty;
int typeIndex = typename.IndexOf(':');
if (typeIndex >= 0)
{
prefix = typename.Substring(0, typeIndex);
typename = typename.Substring(typeIndex + 1);
type = manager.GetType(new XmlQualifiedName(typename, reader.LookupNamespace(prefix)));
if (type != null)
return type;
// To Support types whose assembly is not available, we need to still resolve the clr namespace
List xmlnsMappings = null;
if (manager.XmlNamespaceBasedMappings.TryGetValue(reader.LookupNamespace(prefix), out xmlnsMappings) && xmlnsMappings != null && xmlnsMappings.Count > 0)
return xmlnsMappings[0].ClrNamespace + "." + typename;
else
return typename;
}
type = manager.GetType(new XmlQualifiedName(typename, reader.LookupNamespace(string.Empty)));
// To Support Beta2 format
if (type == null)
{
ITypeProvider typeProvider = provider.GetService(typeof(ITypeProvider)) as ITypeProvider;
if (typeProvider != null)
type = typeProvider.GetType(typename);
// If not design mode, get the value from serialization manager
// At design time, we need to get the type from ITypeProvider else
// we need to store the string in the hashtable we maintain internally
if (type == null && manager.GetService(typeof(ITypeResolutionService)) == null)
type = manager.SerializationManager.GetType(typename);
}
if (type != null)
return type;
return this.typeName;
}
[DefaultValue(null)]
[ConstructorArgument("type")]
public string TypeName
{
get
{
if (this.type != null)
return this.type.FullName;
return this.typeName;
}
set
{
if (value == null)
throw new ArgumentNullException("value");
this.typeName = value;
}
}
internal Type Type
{
get { return this.type; }
}
}
[ContentProperty("Items")]
internal sealed class ArrayExtension : MarkupExtension
{
private ArrayList arrayElementList = new ArrayList();
private Type arrayType;
public ArrayExtension()
{
}
public ArrayExtension(Type arrayType)
{
if (arrayType == null)
throw new ArgumentNullException("arrayType");
this.arrayType = arrayType;
}
public ArrayExtension(Array elements)
{
if (elements == null)
throw new ArgumentNullException("elements");
arrayElementList.AddRange(elements);
this.arrayType = elements.GetType().GetElementType();
}
//
public Type Type
{
get
{
return this.arrayType;
}
set
{
this.arrayType = value;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public IList Items
{
get
{
return arrayElementList;
}
}
public override object ProvideValue(IServiceProvider provider)
{
if (provider == null)
throw new ArgumentNullException("provider");
if (this.arrayType == null)
throw new InvalidOperationException("ArrayType needs to be set.");
object retArray = null;
try
{
retArray = arrayElementList.ToArray(this.arrayType);
}
catch (System.InvalidCastException)
{
//
throw new InvalidOperationException();
}
return retArray;
}
}
}
// 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
- SimpleType.cs
- BindingEntityInfo.cs
- Html32TextWriter.cs
- OdbcPermission.cs
- Conditional.cs
- ToolboxCategory.cs
- TextRangeBase.cs
- FactoryGenerator.cs
- HttpCapabilitiesSectionHandler.cs
- WorkItem.cs
- DataRecordObjectView.cs
- HttpContext.cs
- DefinitionProperties.cs
- ShutDownListener.cs
- MenuItemCollection.cs
- CharacterHit.cs
- TileBrush.cs
- GridViewDeletedEventArgs.cs
- CheckableControlBaseAdapter.cs
- QueryOperator.cs
- ProviderCollection.cs
- BufferBuilder.cs
- Timer.cs
- EventLogPermissionEntry.cs
- ContentType.cs
- GZipDecoder.cs
- ApplicationInfo.cs
- EntityParameterCollection.cs
- SmtpDateTime.cs
- XmlSchemaSimpleTypeRestriction.cs
- BamlRecordWriter.cs
- Configuration.cs
- PageRanges.cs
- AuthenticationService.cs
- ListViewItemSelectionChangedEvent.cs
- TableMethodGenerator.cs
- HtmlEmptyTagControlBuilder.cs
- GridViewDeleteEventArgs.cs
- AudioException.cs
- PbrsForward.cs
- VisualTreeUtils.cs
- ProcessStartInfo.cs
- CodeGenerator.cs
- sitestring.cs
- SqlInternalConnection.cs
- Comparer.cs
- WebConfigurationManager.cs
- EnumBuilder.cs
- JsonFormatReaderGenerator.cs
- GlyphingCache.cs
- BooleanStorage.cs
- EdmRelationshipNavigationPropertyAttribute.cs
- FtpCachePolicyElement.cs
- storagemappingitemcollection.viewdictionary.cs
- CompilerGeneratedAttribute.cs
- KeySplineConverter.cs
- FtpCachePolicyElement.cs
- ObjectReferenceStack.cs
- ListControl.cs
- ReadOnlyCollectionBuilder.cs
- DebugView.cs
- RegexWorker.cs
- ObjectSecurity.cs
- VisualTarget.cs
- BitArray.cs
- ConditionBrowserDialog.cs
- PopupEventArgs.cs
- HMACSHA512.cs
- PageCache.cs
- AdCreatedEventArgs.cs
- QfeChecker.cs
- prefixendpointaddressmessagefiltertable.cs
- DataGridPagerStyle.cs
- XmlChildEnumerator.cs
- FlowDocumentPaginator.cs
- OracleParameterCollection.cs
- CodeTypeMemberCollection.cs
- mansign.cs
- RefType.cs
- TextElementCollection.cs
- XPathConvert.cs
- CorrelationManager.cs
- ZipIOEndOfCentralDirectoryBlock.cs
- PrivateFontCollection.cs
- Durable.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- Message.cs
- UdpDuplexChannel.cs
- AutoCompleteStringCollection.cs
- CachedTypeface.cs
- TreeNodeCollection.cs
- IChannel.cs
- HwndProxyElementProvider.cs
- RuntimeHelpers.cs
- CodeGeneratorOptions.cs
- Material.cs
- TimeEnumHelper.cs
- SecurityDocument.cs
- ComplexPropertyEntry.cs
- ProjectionCamera.cs