Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / Model / ModelPropertyCollectionImpl.cs / 1305376 / ModelPropertyCollectionImpl.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Presentation.Model { using System.Collections.Generic; using System.Activities.Presentation.View; using System.ComponentModel; using System.IO; using System.Linq; // This provides a container for model properties of a modelItem. // This uses the TypeDescriptor.GetProperties() instead of using reflection // to get the properties of a model item. So any model instance implementing ICustomTypeProvider // is automatically taken care of. class ModelPropertyCollectionImpl : ModelPropertyCollection { ModelItem parent; bool createFakeModelProperties; public ModelPropertyCollectionImpl(ModelItem parent) { this.parent = parent; createFakeModelProperties = this.parent is FakeModelItemImpl; } public override IEnumeratorGetEnumerator() { foreach (PropertyDescriptor propertyDescriptor in GetPropertyDescriptors()) { yield return CreateProperty(parent, propertyDescriptor); } } protected override ModelProperty Find(System.Windows.DependencyProperty value, bool throwOnError ) { // We dont support dependency properties. if (throwOnError) { throw FxTrace.Exception.AsError(new NotSupportedException()); } else { return null; } } protected override ModelProperty Find(string name, bool throwOnError) { PropertyDescriptor propertyDescriptor = GetPropertyDescriptors()[name]; if (propertyDescriptor != null) { return CreateProperty(parent, propertyDescriptor); } return null; } ModelProperty CreateProperty(ModelItem parent, PropertyDescriptor propertyDescriptor) { bool isAttached = propertyDescriptor is AttachedPropertyDescriptor; return this.createFakeModelProperties ? (ModelProperty)(new FakeModelPropertyImpl((FakeModelItemImpl)parent, propertyDescriptor)) : (ModelProperty)(new ModelPropertyImpl(parent, propertyDescriptor,isAttached)); } PropertyDescriptorCollection GetPropertyDescriptors() { PropertyDescriptorCollection propertyDescriptors = PropertyDescriptorCollection.Empty; try { object instance = parent.GetCurrentValue(); if (instance != null) { if (!(instance is ICustomTypeDescriptor)) { Type instanceType = instance.GetType(); if (instanceType.IsValueType) { propertyDescriptors = TypeDescriptor.GetProvider(instanceType).GetTypeDescriptor(instanceType).GetProperties(); } else { propertyDescriptors = TypeDescriptor.GetProvider(instance).GetTypeDescriptor(instance).GetProperties(); } } else { propertyDescriptors = TypeDescriptor.GetProperties(instance); } } // Add browsable attached properties AttachedPropertiesService AttachedPropertiesService = this.parent.GetEditingContext().Services.GetService (); if (AttachedPropertiesService != null) { var browsableAttachedProperties = from attachedProperty in AttachedPropertiesService.GetAttachedProperties(this.parent.ItemType) where attachedProperty.IsBrowsable select new AttachedPropertyDescriptor(attachedProperty, this.parent); List mergedProperties = new List (); foreach (PropertyDescriptor propertyDescriptor in propertyDescriptors) { mergedProperties.Add(propertyDescriptor); } propertyDescriptors = new PropertyDescriptorCollection(mergedProperties.Concat(browsableAttachedProperties).ToArray(), true); } } catch (FileNotFoundException e) { EditingContext context = parent.GetEditingContext(); if (context.Items.GetValue () == null) { context.Items.SetValue(new ErrorItem { Message = e.Message, Details = e.ToString() }); } } return propertyDescriptors; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Presentation.Model { using System.Collections.Generic; using System.Activities.Presentation.View; using System.ComponentModel; using System.IO; using System.Linq; // This provides a container for model properties of a modelItem. // This uses the TypeDescriptor.GetProperties() instead of using reflection // to get the properties of a model item. So any model instance implementing ICustomTypeProvider // is automatically taken care of. class ModelPropertyCollectionImpl : ModelPropertyCollection { ModelItem parent; bool createFakeModelProperties; public ModelPropertyCollectionImpl(ModelItem parent) { this.parent = parent; createFakeModelProperties = this.parent is FakeModelItemImpl; } public override IEnumerator GetEnumerator() { foreach (PropertyDescriptor propertyDescriptor in GetPropertyDescriptors()) { yield return CreateProperty(parent, propertyDescriptor); } } protected override ModelProperty Find(System.Windows.DependencyProperty value, bool throwOnError ) { // We dont support dependency properties. if (throwOnError) { throw FxTrace.Exception.AsError(new NotSupportedException()); } else { return null; } } protected override ModelProperty Find(string name, bool throwOnError) { PropertyDescriptor propertyDescriptor = GetPropertyDescriptors()[name]; if (propertyDescriptor != null) { return CreateProperty(parent, propertyDescriptor); } return null; } ModelProperty CreateProperty(ModelItem parent, PropertyDescriptor propertyDescriptor) { bool isAttached = propertyDescriptor is AttachedPropertyDescriptor; return this.createFakeModelProperties ? (ModelProperty)(new FakeModelPropertyImpl((FakeModelItemImpl)parent, propertyDescriptor)) : (ModelProperty)(new ModelPropertyImpl(parent, propertyDescriptor,isAttached)); } PropertyDescriptorCollection GetPropertyDescriptors() { PropertyDescriptorCollection propertyDescriptors = PropertyDescriptorCollection.Empty; try { object instance = parent.GetCurrentValue(); if (instance != null) { if (!(instance is ICustomTypeDescriptor)) { Type instanceType = instance.GetType(); if (instanceType.IsValueType) { propertyDescriptors = TypeDescriptor.GetProvider(instanceType).GetTypeDescriptor(instanceType).GetProperties(); } else { propertyDescriptors = TypeDescriptor.GetProvider(instance).GetTypeDescriptor(instance).GetProperties(); } } else { propertyDescriptors = TypeDescriptor.GetProperties(instance); } } // Add browsable attached properties AttachedPropertiesService AttachedPropertiesService = this.parent.GetEditingContext().Services.GetService (); if (AttachedPropertiesService != null) { var browsableAttachedProperties = from attachedProperty in AttachedPropertiesService.GetAttachedProperties(this.parent.ItemType) where attachedProperty.IsBrowsable select new AttachedPropertyDescriptor(attachedProperty, this.parent); List mergedProperties = new List (); foreach (PropertyDescriptor propertyDescriptor in propertyDescriptors) { mergedProperties.Add(propertyDescriptor); } propertyDescriptors = new PropertyDescriptorCollection(mergedProperties.Concat(browsableAttachedProperties).ToArray(), true); } } catch (FileNotFoundException e) { EditingContext context = parent.GetEditingContext(); if (context.Items.GetValue () == null) { context.Items.SetValue(new ErrorItem { Message = e.Message, Details = e.ToString() }); } } return propertyDescriptors; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EmptyEnumerator.cs
- DefaultClaimSet.cs
- WriteFileContext.cs
- MemoryFailPoint.cs
- Win32Native.cs
- CodeDomConfigurationHandler.cs
- RIPEMD160Managed.cs
- AutoGeneratedFieldProperties.cs
- StatusStrip.cs
- ScrollChangedEventArgs.cs
- GuidConverter.cs
- ColorContextHelper.cs
- XmlSchemaSet.cs
- ManagedIStream.cs
- CLSCompliantAttribute.cs
- ControlCollection.cs
- EncodingDataItem.cs
- BeginStoryboard.cs
- DesignTimeParseData.cs
- Boolean.cs
- OrthographicCamera.cs
- CompositionAdorner.cs
- XmlAnyElementAttribute.cs
- SelectingProviderEventArgs.cs
- Image.cs
- StringSorter.cs
- ObjectDataSourceSelectingEventArgs.cs
- VerifyHashRequest.cs
- DataGridAddNewRow.cs
- QuaternionValueSerializer.cs
- columnmapkeybuilder.cs
- LoginDesignerUtil.cs
- ProjectionPruner.cs
- IdentitySection.cs
- DeviceOverridableAttribute.cs
- AuthenticationService.cs
- Decimal.cs
- OptimizedTemplateContentHelper.cs
- initElementDictionary.cs
- ToolBarTray.cs
- SelectionRange.cs
- SafeCryptContextHandle.cs
- SqlException.cs
- UserNameSecurityTokenProvider.cs
- DoubleCollection.cs
- WindowAutomationPeer.cs
- Label.cs
- DataGridViewColumnConverter.cs
- ToolTipAutomationPeer.cs
- DynamicActivityTypeDescriptor.cs
- AutoResetEvent.cs
- QilList.cs
- WorkflowMessageEventHandler.cs
- EdmRelationshipNavigationPropertyAttribute.cs
- SqlNodeAnnotations.cs
- MethodInfo.cs
- ImageList.cs
- CategoryGridEntry.cs
- ResourceReader.cs
- ReachSerializationUtils.cs
- DataTableMapping.cs
- Win32SafeHandles.cs
- CodeNamespace.cs
- Win32Exception.cs
- PanelContainerDesigner.cs
- ArcSegment.cs
- SqlCacheDependencyDatabase.cs
- EventListenerClientSide.cs
- SystemInfo.cs
- RelationshipType.cs
- ComponentGuaranteesAttribute.cs
- InputProviderSite.cs
- ConfigurationSchemaErrors.cs
- ScriptResourceInfo.cs
- EventSchemaTraceListener.cs
- RowsCopiedEventArgs.cs
- GlobalDataBindingHandler.cs
- ObjectTypeMapping.cs
- FontStretches.cs
- SimpleWebHandlerParser.cs
- SqlCacheDependencySection.cs
- SafeHandle.cs
- FormViewUpdatedEventArgs.cs
- _UriTypeConverter.cs
- CompiledRegexRunner.cs
- UncommonField.cs
- Control.cs
- WorkflowWebHostingModule.cs
- AssociationSetMetadata.cs
- PrePrepareMethodAttribute.cs
- EmbeddedMailObjectCollectionEditor.cs
- ScriptResourceHandler.cs
- CustomTypeDescriptor.cs
- ToolZoneDesigner.cs
- SqlDataSourceConfigureFilterForm.cs
- NamespaceTable.cs
- InfoCardAsymmetricCrypto.cs
- NavigationPropertySingletonExpression.cs
- CatalogZoneBase.cs
- X509Certificate.cs