Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / NamespaceListProperty.cs / 1438166 / NamespaceListProperty.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Presentation { using System.Collections; using System.Collections.Generic; using System.Runtime; using System.ComponentModel; using Microsoft.VisualBasic.Activities; using System.Activities.Presentation.View; class NamespaceListPropertyDescriptor : PropertyDescriptor { public const string ImportCollectionPropertyName = "Imports"; public const string AvailableNamespacesPropertyName = "AvailableNamespaces"; public const string NamespacePropertyName = "Namespace"; object instance; public NamespaceListPropertyDescriptor(object instance) : base(ImportCollectionPropertyName, null) { this.instance = instance; } public override Type ComponentType { get { return this.instance.GetType(); } } public override bool IsReadOnly { get { return true; } } public override Type PropertyType { get { return typeof(NamespaceList); } } public override bool IsBrowsable { get { return false; } } public override bool CanResetValue(object component) { return false; } public override object GetValue(object component) { VisualBasicSettings settings = VisualBasic.GetSettings(component); if (settings == null) { settings = new VisualBasicSettings(); VisualBasic.SetSettings(component, settings); } return new NamespaceList(settings.ImportReferences); } public override void ResetValue(object component) { VisualBasic.SetSettings(component, null); } public override void SetValue(object component, object value) { throw FxTrace.Exception.AsError(new NotSupportedException()); } public override bool ShouldSerializeValue(object component) { throw FxTrace.Exception.AsError(new NotSupportedException()); } protected override void FillAttributes(IList attributeList) { attributeList.Add(new BrowsableAttribute(false)); base.FillAttributes(attributeList); } } class NamespaceData { public string Namespace { get; set; } //Used by screen reader public override string ToString() { return this.Namespace; } } //an adaptor to adapt a VisualBasicImportReference set to a list with unique namespaces class NamespaceList : IList { //Since XAML generated by designer will almost always have some designer type in it, designer namespaces will appear in XAML. //And because Runtime design could not destinguish namespaces coming from XAML serialization between namespaces added by users, //designer namespaces will show up in import designer. This is bad user experience because most WF project won't reference designer //assembly. We could safely assume that customers won't use designer namespaces and type in their WF expressions, so we simply //---- designer namespaces out of the namespace list static readonly string[] ----edAssemblies = new string[] { typeof(ViewStateService).Assembly.GetName().FullName, typeof(ViewStateService).Assembly.GetName().Name, }; ISetimportReferences; //list of uniqueNamespaces, the element is a tuple of the namespace and a arbitary data for consumer to use List uniqueNamespaces = new List (); Dictionary > availableNamespaces; public NamespaceList(ISet importReferences) { this.importReferences = importReferences; foreach (string ----edAssembly in ----edAssemblies) { RemoveAssemblyFromSet(----edAssembly); } foreach (VisualBasicImportReference import in importReferences) { if (Lookup(import.Import) == -1) { uniqueNamespaces.Add(new NamespaceData { Namespace = import.Import }); } } } public Dictionary > AvailableNamespaces { get { if (availableNamespaces == null) { availableNamespaces = new Dictionary >(); } return availableNamespaces; } } IEnumerable GetVisualBasicImportReferences(string importNamespace) { List imports = new List (); List assemblies; //in rehost cases or when some assembiles are not referenced, we may not find that namespace if (!this.AvailableNamespaces.TryGetValue(importNamespace, out assemblies)) { return imports; } foreach (string assembly in assemblies) { imports.Add(new VisualBasicImportReference { Import = importNamespace, Assembly = assembly }); } return imports; } internal void UpdateAssemblyInfo(string importedNamespace) { if (this.Lookup(importedNamespace) != -1) { this.importReferences.UnionWith(GetVisualBasicImportReferences(importedNamespace)); } else { Fx.Assert ("UpdateAssemblyInfor should only be called for existed namespace"); } } internal int Lookup(string ns) { for (int i = 0; i < this.uniqueNamespaces.Count; i++) { if (this.uniqueNamespaces[i].Namespace == ns) { return i; } } return -1; } void RemoveNamespaceFromSet(string ns) { List toRemoves = new List (); foreach (VisualBasicImportReference import in this.importReferences) { if (import.Import == ns) { toRemoves.Add(import); } } foreach (VisualBasicImportReference toRemove in toRemoves) { this.importReferences.Remove(toRemove); } } void RemoveAssemblyFromSet(string assembly) { List toRemoves = new List (); foreach (VisualBasicImportReference import in this.importReferences) { if (import.Assembly == assembly) { toRemoves.Add(import); } } foreach (VisualBasicImportReference toRemove in toRemoves) { this.importReferences.Remove(toRemove); } } public int Add(object value) { NamespaceData ns = value as NamespaceData; if (ns == null) { throw FxTrace.Exception.AsError(new ArgumentException(SR.NamespaceListArgumentMustBeNamespaceData, "value")); } if (Lookup(ns.Namespace) == -1) { this.importReferences.UnionWith(GetVisualBasicImportReferences(ns.Namespace)); return ((IList)this.uniqueNamespaces).Add(ns); } else { return -1; } } public void Clear() { this.importReferences.Clear(); this.uniqueNamespaces.Clear(); } public bool Contains(object value) { return ((IList)this.uniqueNamespaces).Contains(value); } public int IndexOf(object value) { return ((IList)this.uniqueNamespaces).IndexOf(value); } public void Insert(int index, object value) { NamespaceData ns = value as NamespaceData; if (ns == null) { throw FxTrace.Exception.AsError(new ArgumentException(SR.NamespaceListArgumentMustBeNamespaceData, "value")); } if (Lookup(ns.Namespace) == -1) { this.uniqueNamespaces.Insert(index, ns); this.importReferences.UnionWith(GetVisualBasicImportReferences(ns.Namespace)); } else { throw FxTrace.Exception.AsError(new InvalidOperationException()); } } public bool IsFixedSize { get { return false; } } public bool IsReadOnly { get { return false; } } public void Remove(object value) { NamespaceData ns = value as NamespaceData; if (ns == null) { throw FxTrace.Exception.AsError(new ArgumentException(SR.NamespaceListArgumentMustBeNamespaceData, "value")); } int index = this.Lookup(ns.Namespace); if (index != -1) { RemoveAt(index); } } public void RemoveAt(int index) { NamespaceData ns = this.uniqueNamespaces[index]; RemoveNamespaceFromSet(ns.Namespace); this.uniqueNamespaces.RemoveAt(index); } public object this[int index] { get { return this.uniqueNamespaces[index]; } set { NamespaceData ns = value as NamespaceData; if (ns == null) { throw FxTrace.Exception.AsError(new ArgumentException(SR.NamespaceListArgumentMustBeNamespaceData, "value")); } if (Lookup(ns.Namespace) == -1) { RemoveNamespaceFromSet(this.uniqueNamespaces[index].Namespace); this.uniqueNamespaces[index] = ns; this.importReferences.UnionWith(GetVisualBasicImportReferences(ns.Namespace)); } else { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.NamespaceListNoDuplicate)); } } } public void CopyTo(Array array, int index) { ((IList)this.uniqueNamespaces).CopyTo(array, index); } public int Count { get { return this.uniqueNamespaces.Count; } } public bool IsSynchronized { get { return false; } } public object SyncRoot { get { return null; } } public IEnumerator GetEnumerator() { return this.uniqueNamespaces.GetEnumerator(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Presentation { using System.Collections; using System.Collections.Generic; using System.Runtime; using System.ComponentModel; using Microsoft.VisualBasic.Activities; using System.Activities.Presentation.View; class NamespaceListPropertyDescriptor : PropertyDescriptor { public const string ImportCollectionPropertyName = "Imports"; public const string AvailableNamespacesPropertyName = "AvailableNamespaces"; public const string NamespacePropertyName = "Namespace"; object instance; public NamespaceListPropertyDescriptor(object instance) : base(ImportCollectionPropertyName, null) { this.instance = instance; } public override Type ComponentType { get { return this.instance.GetType(); } } public override bool IsReadOnly { get { return true; } } public override Type PropertyType { get { return typeof(NamespaceList); } } public override bool IsBrowsable { get { return false; } } public override bool CanResetValue(object component) { return false; } public override object GetValue(object component) { VisualBasicSettings settings = VisualBasic.GetSettings(component); if (settings == null) { settings = new VisualBasicSettings(); VisualBasic.SetSettings(component, settings); } return new NamespaceList(settings.ImportReferences); } public override void ResetValue(object component) { VisualBasic.SetSettings(component, null); } public override void SetValue(object component, object value) { throw FxTrace.Exception.AsError(new NotSupportedException()); } public override bool ShouldSerializeValue(object component) { throw FxTrace.Exception.AsError(new NotSupportedException()); } protected override void FillAttributes(IList attributeList) { attributeList.Add(new BrowsableAttribute(false)); base.FillAttributes(attributeList); } } class NamespaceData { public string Namespace { get; set; } //Used by screen reader public override string ToString() { return this.Namespace; } } //an adaptor to adapt a VisualBasicImportReference set to a list with unique namespaces class NamespaceList : IList { //Since XAML generated by designer will almost always have some designer type in it, designer namespaces will appear in XAML. //And because Runtime design could not destinguish namespaces coming from XAML serialization between namespaces added by users, //designer namespaces will show up in import designer. This is bad user experience because most WF project won't reference designer //assembly. We could safely assume that customers won't use designer namespaces and type in their WF expressions, so we simply //---- designer namespaces out of the namespace list static readonly string[] ----edAssemblies = new string[] { typeof(ViewStateService).Assembly.GetName().FullName, typeof(ViewStateService).Assembly.GetName().Name, }; ISet importReferences; //list of uniqueNamespaces, the element is a tuple of the namespace and a arbitary data for consumer to use List uniqueNamespaces = new List (); Dictionary > availableNamespaces; public NamespaceList(ISet importReferences) { this.importReferences = importReferences; foreach (string ----edAssembly in ----edAssemblies) { RemoveAssemblyFromSet(----edAssembly); } foreach (VisualBasicImportReference import in importReferences) { if (Lookup(import.Import) == -1) { uniqueNamespaces.Add(new NamespaceData { Namespace = import.Import }); } } } public Dictionary > AvailableNamespaces { get { if (availableNamespaces == null) { availableNamespaces = new Dictionary >(); } return availableNamespaces; } } IEnumerable GetVisualBasicImportReferences(string importNamespace) { List imports = new List (); List assemblies; //in rehost cases or when some assembiles are not referenced, we may not find that namespace if (!this.AvailableNamespaces.TryGetValue(importNamespace, out assemblies)) { return imports; } foreach (string assembly in assemblies) { imports.Add(new VisualBasicImportReference { Import = importNamespace, Assembly = assembly }); } return imports; } internal void UpdateAssemblyInfo(string importedNamespace) { if (this.Lookup(importedNamespace) != -1) { this.importReferences.UnionWith(GetVisualBasicImportReferences(importedNamespace)); } else { Fx.Assert ("UpdateAssemblyInfor should only be called for existed namespace"); } } internal int Lookup(string ns) { for (int i = 0; i < this.uniqueNamespaces.Count; i++) { if (this.uniqueNamespaces[i].Namespace == ns) { return i; } } return -1; } void RemoveNamespaceFromSet(string ns) { List toRemoves = new List (); foreach (VisualBasicImportReference import in this.importReferences) { if (import.Import == ns) { toRemoves.Add(import); } } foreach (VisualBasicImportReference toRemove in toRemoves) { this.importReferences.Remove(toRemove); } } void RemoveAssemblyFromSet(string assembly) { List toRemoves = new List (); foreach (VisualBasicImportReference import in this.importReferences) { if (import.Assembly == assembly) { toRemoves.Add(import); } } foreach (VisualBasicImportReference toRemove in toRemoves) { this.importReferences.Remove(toRemove); } } public int Add(object value) { NamespaceData ns = value as NamespaceData; if (ns == null) { throw FxTrace.Exception.AsError(new ArgumentException(SR.NamespaceListArgumentMustBeNamespaceData, "value")); } if (Lookup(ns.Namespace) == -1) { this.importReferences.UnionWith(GetVisualBasicImportReferences(ns.Namespace)); return ((IList)this.uniqueNamespaces).Add(ns); } else { return -1; } } public void Clear() { this.importReferences.Clear(); this.uniqueNamespaces.Clear(); } public bool Contains(object value) { return ((IList)this.uniqueNamespaces).Contains(value); } public int IndexOf(object value) { return ((IList)this.uniqueNamespaces).IndexOf(value); } public void Insert(int index, object value) { NamespaceData ns = value as NamespaceData; if (ns == null) { throw FxTrace.Exception.AsError(new ArgumentException(SR.NamespaceListArgumentMustBeNamespaceData, "value")); } if (Lookup(ns.Namespace) == -1) { this.uniqueNamespaces.Insert(index, ns); this.importReferences.UnionWith(GetVisualBasicImportReferences(ns.Namespace)); } else { throw FxTrace.Exception.AsError(new InvalidOperationException()); } } public bool IsFixedSize { get { return false; } } public bool IsReadOnly { get { return false; } } public void Remove(object value) { NamespaceData ns = value as NamespaceData; if (ns == null) { throw FxTrace.Exception.AsError(new ArgumentException(SR.NamespaceListArgumentMustBeNamespaceData, "value")); } int index = this.Lookup(ns.Namespace); if (index != -1) { RemoveAt(index); } } public void RemoveAt(int index) { NamespaceData ns = this.uniqueNamespaces[index]; RemoveNamespaceFromSet(ns.Namespace); this.uniqueNamespaces.RemoveAt(index); } public object this[int index] { get { return this.uniqueNamespaces[index]; } set { NamespaceData ns = value as NamespaceData; if (ns == null) { throw FxTrace.Exception.AsError(new ArgumentException(SR.NamespaceListArgumentMustBeNamespaceData, "value")); } if (Lookup(ns.Namespace) == -1) { RemoveNamespaceFromSet(this.uniqueNamespaces[index].Namespace); this.uniqueNamespaces[index] = ns; this.importReferences.UnionWith(GetVisualBasicImportReferences(ns.Namespace)); } else { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.NamespaceListNoDuplicate)); } } } public void CopyTo(Array array, int index) { ((IList)this.uniqueNamespaces).CopyTo(array, index); } public int Count { get { return this.uniqueNamespaces.Count; } } public bool IsSynchronized { get { return false; } } public object SyncRoot { get { return null; } } public IEnumerator GetEnumerator() { return this.uniqueNamespaces.GetEnumerator(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- KeyboardEventArgs.cs
- ALinqExpressionVisitor.cs
- DataException.cs
- HandoffBehavior.cs
- TypeCacheManager.cs
- InputGestureCollection.cs
- UrlMappingCollection.cs
- MenuEventArgs.cs
- Odbc32.cs
- Baml2006ReaderSettings.cs
- RequiredFieldValidator.cs
- MetafileHeader.cs
- DesignerOptionService.cs
- ConcatQueryOperator.cs
- ExpressionVisitor.cs
- CheckableControlBaseAdapter.cs
- connectionpool.cs
- ErrorWebPart.cs
- RoleManagerEventArgs.cs
- ObjectNotFoundException.cs
- HScrollProperties.cs
- IgnoreDataMemberAttribute.cs
- TemplateEditingFrame.cs
- CatalogZone.cs
- ColorAnimationUsingKeyFrames.cs
- LayoutTableCell.cs
- Msec.cs
- CompilerLocalReference.cs
- ContentPropertyAttribute.cs
- InternalSafeNativeMethods.cs
- Repeater.cs
- BamlTreeNode.cs
- CodeMemberMethod.cs
- JpegBitmapDecoder.cs
- ClientRoleProvider.cs
- FileSystemInfo.cs
- DPTypeDescriptorContext.cs
- OracleConnectionFactory.cs
- ActivityTypeDesigner.xaml.cs
- TransactionBehavior.cs
- DocumentGridPage.cs
- TextEncodedRawTextWriter.cs
- CuspData.cs
- FacetChecker.cs
- EdmEntityTypeAttribute.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- BooleanFacetDescriptionElement.cs
- PassportAuthenticationModule.cs
- ParentUndoUnit.cs
- RenderDataDrawingContext.cs
- JapaneseLunisolarCalendar.cs
- TextLineResult.cs
- NavigatorInvalidBodyAccessException.cs
- Message.cs
- RoutedEventHandlerInfo.cs
- XPathDescendantIterator.cs
- XpsPackagingPolicy.cs
- XmlDigitalSignatureProcessor.cs
- AtomPub10ServiceDocumentFormatter.cs
- ServiceMetadataBehavior.cs
- TreeBuilderXamlTranslator.cs
- FilterableAttribute.cs
- WebBrowserHelper.cs
- ProfileSection.cs
- Pair.cs
- MetadataItemCollectionFactory.cs
- EntityDataSourceViewSchema.cs
- XmlUTF8TextReader.cs
- FixedSchema.cs
- Cursors.cs
- CaseCqlBlock.cs
- XmlSyndicationContent.cs
- WindowsRegion.cs
- RegexTree.cs
- SerialPinChanges.cs
- Listbox.cs
- TypeUsageBuilder.cs
- EllipticalNodeOperations.cs
- DataObjectCopyingEventArgs.cs
- StylusPointDescription.cs
- ClipboardData.cs
- SqlFileStream.cs
- XsltArgumentList.cs
- ApplicationInfo.cs
- messageonlyhwndwrapper.cs
- DCSafeHandle.cs
- DataPagerField.cs
- MethodBuilderInstantiation.cs
- UndirectedGraph.cs
- PiiTraceSource.cs
- LinqDataSourceEditData.cs
- SecurityTokenParameters.cs
- SqlRowUpdatingEvent.cs
- ReliableMessagingHelpers.cs
- XmlLanguageConverter.cs
- WorkflowElementDialog.cs
- ColorKeyFrameCollection.cs
- NullExtension.cs
- XmlSchemaInclude.cs
- AuthStoreRoleProvider.cs