Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / DynamicActivityTypeDescriptor.cs / 1305376 / DynamicActivityTypeDescriptor.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities { using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Xml.Linq; class DynamicActivityTypeDescriptor : ICustomTypeDescriptor { PropertyDescriptorCollection cachedProperties; Activity owner; public DynamicActivityTypeDescriptor(Activity owner) { this.owner = owner; this.Properties = new ActivityPropertyCollection(this); } public string Name { get; set; } public KeyedCollectionProperties { get; private set; } public AttributeCollection GetAttributes() { return TypeDescriptor.GetAttributes(this.owner, true); } public string GetClassName() { if (this.Name != null) { return this.Name; } return TypeDescriptor.GetClassName(this.owner, true); } public string GetComponentName() { return TypeDescriptor.GetComponentName(this.owner, true); } public TypeConverter GetConverter() { return TypeDescriptor.GetConverter(this.owner, true); } public EventDescriptor GetDefaultEvent() { return TypeDescriptor.GetDefaultEvent(this.owner, true); } public PropertyDescriptor GetDefaultProperty() { return TypeDescriptor.GetDefaultProperty(this.owner, true); } public object GetEditor(Type editorBaseType) { return TypeDescriptor.GetEditor(this.owner, editorBaseType, true); } public EventDescriptorCollection GetEvents(Attribute[] attributes) { return TypeDescriptor.GetEvents(this.owner, attributes, true); } public EventDescriptorCollection GetEvents() { return TypeDescriptor.GetEvents(this.owner, true); } public PropertyDescriptorCollection GetProperties() { return GetProperties(null); } public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { PropertyDescriptorCollection result = this.cachedProperties; if (result != null) { return result; } PropertyDescriptorCollection dynamicProperties; if (attributes != null) { dynamicProperties = TypeDescriptor.GetProperties(this.owner, attributes, true); } else { dynamicProperties = TypeDescriptor.GetProperties(this.owner, true); } // initial capacity is Properties + Name + Body List propertyDescriptors = new List (this.Properties.Count + 2); for (int i = 0; i < dynamicProperties.Count; i++) { PropertyDescriptor dynamicProperty = dynamicProperties[i]; if (dynamicProperty.IsBrowsable) { propertyDescriptors.Add(dynamicProperty); } } foreach (DynamicActivityProperty property in Properties) { if (string.IsNullOrEmpty(property.Name)) { throw FxTrace.Exception.AsError(new ValidationException(SR.ActivityPropertyRequiresName(this.owner.DisplayName))); } if (property.Type == null) { throw FxTrace.Exception.AsError(new ValidationException(SR.ActivityPropertyRequiresType(this.owner.DisplayName))); } propertyDescriptors.Add(new DynamicActivityPropertyDescriptor(property, this.owner.GetType())); } result = new PropertyDescriptorCollection(propertyDescriptors.ToArray()); this.cachedProperties = result; return result; } public object GetPropertyOwner(PropertyDescriptor pd) { return this.owner; } class DynamicActivityPropertyDescriptor : PropertyDescriptor { AttributeCollection attributes; DynamicActivityProperty activityProperty; Type componentType; public DynamicActivityPropertyDescriptor(DynamicActivityProperty activityProperty, Type componentType) : base(activityProperty.Name, null) { this.activityProperty = activityProperty; this.componentType = componentType; } public override Type ComponentType { get { return this.componentType; } } public override AttributeCollection Attributes { get { if (this.attributes == null) { AttributeCollection inheritedAttributes = base.Attributes; Collection propertyAttributes = this.activityProperty.Attributes; Attribute[] totalAttributes = new Attribute[inheritedAttributes.Count + propertyAttributes.Count + 1]; inheritedAttributes.CopyTo(totalAttributes, 0); propertyAttributes.CopyTo(totalAttributes, inheritedAttributes.Count); totalAttributes[inheritedAttributes.Count + propertyAttributes.Count] = new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden); this.attributes = new AttributeCollection(totalAttributes); } return this.attributes; } } public override bool IsReadOnly { get { return false; } } public override Type PropertyType { get { return this.activityProperty.Type; } } public override object GetValue(object component) { IDynamicActivity owner = component as IDynamicActivity; if (owner == null || !owner.Properties.Contains(this.activityProperty)) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.InvalidDynamicActivityProperty(this.Name))); } return this.activityProperty.Value; } public override void SetValue(object component, object value) { IDynamicActivity owner = component as IDynamicActivity; if (owner == null || !owner.Properties.Contains(this.activityProperty)) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.InvalidDynamicActivityProperty(this.Name))); } this.activityProperty.Value = value; } public override bool CanResetValue(object component) { return false; } public override void ResetValue(object component) { } public override bool ShouldSerializeValue(object component) { return false; } protected override void FillAttributes(IList attributeList) { if (attributeList == null) { throw FxTrace.Exception.ArgumentNull("attributeList"); } attributeList.Add(new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)); } } class ActivityPropertyCollection : KeyedCollection { DynamicActivityTypeDescriptor parent; public ActivityPropertyCollection(DynamicActivityTypeDescriptor parent) : base() { this.parent = parent; } protected override void InsertItem(int index, DynamicActivityProperty item) { if (item == null) { throw FxTrace.Exception.ArgumentNull("item"); } if (this.Contains(item.Name)) { throw FxTrace.Exception.AsError(new ArgumentException(SR.DynamicActivityDuplicatePropertyDetected(item.Name), "item")); } InvalidateCache(); base.InsertItem(index, item); } protected override void SetItem(int index, DynamicActivityProperty item) { if (item == null) { throw FxTrace.Exception.ArgumentNull("item"); } // We don't want self-assignment to throw. Note that if this[index] has the same // name as item, no other element in the collection can. if (!this[index].Name.Equals(item.Name) && this.Contains(item.Name)) { throw FxTrace.Exception.AsError(new ArgumentException(SR.DynamicActivityDuplicatePropertyDetected(item.Name), "item")); } InvalidateCache(); base.SetItem(index, item); } protected override void RemoveItem(int index) { InvalidateCache(); base.RemoveItem(index); } protected override void ClearItems() { InvalidateCache(); base.ClearItems(); } protected override string GetKeyForItem(DynamicActivityProperty item) { return item.Name; } void InvalidateCache() { this.parent.cachedProperties = null; } } } } // 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
- QueryActivatableWorkflowsCommand.cs
- SuppressIldasmAttribute.cs
- WebBrowserPermission.cs
- FrameworkRichTextComposition.cs
- ContentType.cs
- XPathNode.cs
- HtmlElementErrorEventArgs.cs
- ConnectionString.cs
- ValidationErrorCollection.cs
- SchemaMapping.cs
- FormViewUpdateEventArgs.cs
- ToolStripLocationCancelEventArgs.cs
- AttributedMetaModel.cs
- HTMLTagNameToTypeMapper.cs
- SmiContextFactory.cs
- RootBuilder.cs
- TreeViewEvent.cs
- ContractNamespaceAttribute.cs
- ColumnTypeConverter.cs
- validationstate.cs
- Coordinator.cs
- IntegerFacetDescriptionElement.cs
- InvokeMethodActivityDesigner.cs
- XamlReaderHelper.cs
- QueryException.cs
- RecommendedAsConfigurableAttribute.cs
- DataColumnChangeEvent.cs
- RayMeshGeometry3DHitTestResult.cs
- PassportPrincipal.cs
- TileBrush.cs
- AutomationProperties.cs
- EventLog.cs
- TextOutput.cs
- SimpleHandlerFactory.cs
- XmlWriterDelegator.cs
- CustomGrammar.cs
- EventRoute.cs
- SpecialNameAttribute.cs
- KerberosRequestorSecurityToken.cs
- TextAutomationPeer.cs
- DbSource.cs
- HashMembershipCondition.cs
- PeerMaintainer.cs
- MappingSource.cs
- SchemaManager.cs
- Int16.cs
- StartFileNameEditor.cs
- SemanticResolver.cs
- WebPartCloseVerb.cs
- SqlRetyper.cs
- HttpClientCertificate.cs
- SafeTimerHandle.cs
- _ConnectStream.cs
- StatusBarItemAutomationPeer.cs
- WSHttpBindingElement.cs
- IIS7UserPrincipal.cs
- MailMessageEventArgs.cs
- BaseValidator.cs
- ShapingWorkspace.cs
- InvalidWMPVersionException.cs
- X509PeerCertificateElement.cs
- UIPermission.cs
- _NestedMultipleAsyncResult.cs
- Menu.cs
- PropertiesTab.cs
- DynamicControlParameter.cs
- ComplexPropertyEntry.cs
- NoResizeSelectionBorderGlyph.cs
- CompilerInfo.cs
- FormsAuthenticationCredentials.cs
- ImageKeyConverter.cs
- AutoGeneratedField.cs
- ConvertEvent.cs
- EventLogPermissionEntry.cs
- RegisterInfo.cs
- XmlUtil.cs
- FileChangesMonitor.cs
- OracleConnectionFactory.cs
- SecurityTokenAuthenticator.cs
- ZipFileInfoCollection.cs
- GeometryCollection.cs
- AssemblyInfo.cs
- ResourceProviderFactory.cs
- HwndAppCommandInputProvider.cs
- EventProperty.cs
- DataSysAttribute.cs
- WebMessageFormatHelper.cs
- SchemaSetCompiler.cs
- XXXInfos.cs
- IriParsingElement.cs
- StyleSheetComponentEditor.cs
- ListItem.cs
- DataSet.cs
- CompiledQueryCacheKey.cs
- EllipticalNodeOperations.cs
- DispatcherEventArgs.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- DelegateSerializationHolder.cs
- GreaterThanOrEqual.cs
- LongValidatorAttribute.cs