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 ListxmlnsMappings = 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
- MouseGesture.cs
- TimeZoneInfo.cs
- ToolStripLocationCancelEventArgs.cs
- MsmqIntegrationBindingElement.cs
- SHA512Managed.cs
- CompilerScopeManager.cs
- SystemWebCachingSectionGroup.cs
- SoapExtension.cs
- Transform.cs
- SafeThreadHandle.cs
- DNS.cs
- DataSetUtil.cs
- SelectionRange.cs
- WindowInteropHelper.cs
- PackUriHelper.cs
- PlanCompilerUtil.cs
- LinqDataSourceValidationException.cs
- StringBuilder.cs
- HttpPostProtocolReflector.cs
- ValidationResult.cs
- SymbolPair.cs
- coordinatorscratchpad.cs
- NamespaceMapping.cs
- MultiBinding.cs
- AnnotationService.cs
- ObjectDataSourceFilteringEventArgs.cs
- UpdateException.cs
- ConfigurationStrings.cs
- InstancePersistenceException.cs
- InstanceOwner.cs
- RectangleGeometry.cs
- ImplicitInputBrush.cs
- DataServices.cs
- BaseParaClient.cs
- EditorPart.cs
- Point.cs
- FormViewCommandEventArgs.cs
- XmlnsDefinitionAttribute.cs
- RegexCompiler.cs
- DispatchWrapper.cs
- WinInetCache.cs
- RegexGroupCollection.cs
- ArcSegment.cs
- cookieexception.cs
- PrintDialog.cs
- GradientSpreadMethodValidation.cs
- BufferedGraphicsManager.cs
- DoubleConverter.cs
- MergePropertyDescriptor.cs
- ConfigXmlCDataSection.cs
- RequestTimeoutManager.cs
- EdmError.cs
- TriState.cs
- TextEmbeddedObject.cs
- OutputCacheProfileCollection.cs
- ProjectionCamera.cs
- Pair.cs
- WebBrowserContainer.cs
- DataBoundLiteralControl.cs
- XmlConvert.cs
- TimeSpanOrInfiniteValidator.cs
- DesignTimeVisibleAttribute.cs
- Enumerable.cs
- IdentityModelDictionary.cs
- HybridObjectCache.cs
- GC.cs
- OptionUsage.cs
- WebPartMenu.cs
- TdsParserStaticMethods.cs
- LinearGradientBrush.cs
- ObjectReaderCompiler.cs
- QueryContinueDragEventArgs.cs
- InputGestureCollection.cs
- HierarchicalDataTemplate.cs
- DataSourceIDConverter.cs
- XmlSchemaSubstitutionGroup.cs
- errorpatternmatcher.cs
- AuthenticationModuleElement.cs
- PrintPreviewControl.cs
- DateTimeFormatInfo.cs
- ProcessThread.cs
- MsmqException.cs
- LassoSelectionBehavior.cs
- GroupStyle.cs
- XmlSchemaCompilationSettings.cs
- FormatConvertedBitmap.cs
- PropertyEmitter.cs
- TextTreeDeleteContentUndoUnit.cs
- PTConverter.cs
- DragEvent.cs
- StickyNoteAnnotations.cs
- ConstructorNeedsTagAttribute.cs
- Graph.cs
- COSERVERINFO.cs
- CompositeFontFamily.cs
- ParagraphVisual.cs
- LazyTextWriterCreator.cs
- Imaging.cs
- GradientSpreadMethodValidation.cs
- TextTreeInsertUndoUnit.cs