Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / View / TypeKeyValue.cs / 1305376 / TypeKeyValue.cs
namespace System.Activities.Presentation.View { using System; using System.Collections.ObjectModel; using System.ComponentModel; using System.Windows; using System.Windows.Automation.Peers; using System.Windows.Input; //helper class, used to resolve generics. supports cascading generic type arguments (i.e. IList< IList < int > >) internal class TypeKeyValue : INotifyPropertyChanged { string errorText; //generic type Type genericType; bool isValid = true; //generic's type generic parameters ObservableCollection < TypeKeyValue > subTypes = new ObservableCollection < TypeKeyValue >(); //target type Type targetType; //type resolver reference Action < TypeKeyValue > typeChangedCallBack; //if this type is selected bool isSelected; Funcfilter; ObservableCollection mostRecentlyUsedTypes; //if type presenter should skip the drop down list bool browseTypeDirectly = true; public TypeKeyValue(Type genericType, Action < TypeKeyValue > typeChangedCallBack) { this.GenericType = genericType; this.typeChangedCallBack = typeChangedCallBack; } public event PropertyChangedEventHandler PropertyChanged; public string ErrorText { get { return this.errorText; } set { this.errorText = value; OnPropertyChanged("ErrorText"); } } public Type GenericType { get { return this.genericType; } set { this.genericType = value; OnPropertyChanged("GenericType"); } } public bool IsSelected { get { return this.isSelected; } set { this.isSelected = value; OnPropertyChanged("IsSelected"); } } public Func Filter { get { return this.filter; } set { this.filter = value; OnPropertyChanged("Filter"); } } public ObservableCollection MostRecentlyUsedTypes { get { return this.mostRecentlyUsedTypes; } set { this.mostRecentlyUsedTypes = value; OnPropertyChanged("MostRecentlyUsedTypes"); } } public bool BrowseTypeDirectly { get { return this.browseTypeDirectly; } set { this.browseTypeDirectly = value; OnPropertyChanged("BrowseTypeDirectly"); } } public bool IsValid { get { return this.isValid; } set { this.isValid = value; OnPropertyChanged("IsValid"); } } public ObservableCollection < TypeKeyValue > SubTypes { get { return this.subTypes; } } public Type TargetType { get { return this.targetType; } set { this.targetType = value; //whenever target type changes, check if there are some generic parameters required LoadGenericTypes(); OnPropertyChanged("TargetType"); if (typeChangedCallBack != null) { typeChangedCallBack(this); } } } public Type GetConcreteType() { Type result = null; if (null != this.targetType) { //do we have generic? if (this.targetType.IsGenericTypeDefinition) { //resolve all generic arguments Type[] arguments = new Type[this.subTypes.Count]; bool isValid = true; for (int i = 0; i < this.subTypes.Count && isValid; ++i) { arguments[i] = this.subTypes[i].GetConcreteType(); isValid = (null != arguments[i]); } if (isValid) { //and create target type result = this.targetType.MakeGenericType(arguments); } } else { result = targetType; } } return result; } void LoadGenericTypes() { this.subTypes.Clear(); if (null != this.targetType && this.targetType.IsGenericTypeDefinition) { Type[] generics = this.targetType.GetGenericArguments(); foreach (Type t in generics) { TypeKeyValue entry = new TypeKeyValue(t, typeChangedCallBack); this.subTypes.Add(entry); typeChangedCallBack(entry); } } } void OnPropertyChanged(string propertyName) { if (null != PropertyChanged) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. namespace System.Activities.Presentation.View { using System; using System.Collections.ObjectModel; using System.ComponentModel; using System.Windows; using System.Windows.Automation.Peers; using System.Windows.Input; //helper class, used to resolve generics. supports cascading generic type arguments (i.e. IList< IList < int > >) internal class TypeKeyValue : INotifyPropertyChanged { string errorText; //generic type Type genericType; bool isValid = true; //generic's type generic parameters ObservableCollection < TypeKeyValue > subTypes = new ObservableCollection < TypeKeyValue >(); //target type Type targetType; //type resolver reference Action < TypeKeyValue > typeChangedCallBack; //if this type is selected bool isSelected; Func filter; ObservableCollection mostRecentlyUsedTypes; //if type presenter should skip the drop down list bool browseTypeDirectly = true; public TypeKeyValue(Type genericType, Action < TypeKeyValue > typeChangedCallBack) { this.GenericType = genericType; this.typeChangedCallBack = typeChangedCallBack; } public event PropertyChangedEventHandler PropertyChanged; public string ErrorText { get { return this.errorText; } set { this.errorText = value; OnPropertyChanged("ErrorText"); } } public Type GenericType { get { return this.genericType; } set { this.genericType = value; OnPropertyChanged("GenericType"); } } public bool IsSelected { get { return this.isSelected; } set { this.isSelected = value; OnPropertyChanged("IsSelected"); } } public Func Filter { get { return this.filter; } set { this.filter = value; OnPropertyChanged("Filter"); } } public ObservableCollection MostRecentlyUsedTypes { get { return this.mostRecentlyUsedTypes; } set { this.mostRecentlyUsedTypes = value; OnPropertyChanged("MostRecentlyUsedTypes"); } } public bool BrowseTypeDirectly { get { return this.browseTypeDirectly; } set { this.browseTypeDirectly = value; OnPropertyChanged("BrowseTypeDirectly"); } } public bool IsValid { get { return this.isValid; } set { this.isValid = value; OnPropertyChanged("IsValid"); } } public ObservableCollection < TypeKeyValue > SubTypes { get { return this.subTypes; } } public Type TargetType { get { return this.targetType; } set { this.targetType = value; //whenever target type changes, check if there are some generic parameters required LoadGenericTypes(); OnPropertyChanged("TargetType"); if (typeChangedCallBack != null) { typeChangedCallBack(this); } } } public Type GetConcreteType() { Type result = null; if (null != this.targetType) { //do we have generic? if (this.targetType.IsGenericTypeDefinition) { //resolve all generic arguments Type[] arguments = new Type[this.subTypes.Count]; bool isValid = true; for (int i = 0; i < this.subTypes.Count && isValid; ++i) { arguments[i] = this.subTypes[i].GetConcreteType(); isValid = (null != arguments[i]); } if (isValid) { //and create target type result = this.targetType.MakeGenericType(arguments); } } else { result = targetType; } } return result; } void LoadGenericTypes() { this.subTypes.Clear(); if (null != this.targetType && this.targetType.IsGenericTypeDefinition) { Type[] generics = this.targetType.GetGenericArguments(); foreach (Type t in generics) { TypeKeyValue entry = new TypeKeyValue(t, typeChangedCallBack); this.subTypes.Add(entry); typeChangedCallBack(entry); } } } void OnPropertyChanged(string propertyName) { if (null != PropertyChanged) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } } // 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
- EventSourceCreationData.cs
- CodeDomDecompiler.cs
- IIS7UserPrincipal.cs
- QueryAccessibilityHelpEvent.cs
- CacheForPrimitiveTypes.cs
- ContextQuery.cs
- formatter.cs
- IPAddressCollection.cs
- WebDescriptionAttribute.cs
- GiveFeedbackEvent.cs
- UshortList2.cs
- TableItemPatternIdentifiers.cs
- FloaterParagraph.cs
- EntityContainerEmitter.cs
- SelectorItemAutomationPeer.cs
- NameValueSectionHandler.cs
- ToolStripItemTextRenderEventArgs.cs
- InputLanguageCollection.cs
- SqlDataSourceConfigureFilterForm.cs
- HTTPNotFoundHandler.cs
- DataPagerFieldCommandEventArgs.cs
- RefExpr.cs
- InfocardClientCredentials.cs
- WebConfigurationFileMap.cs
- TrustManagerMoreInformation.cs
- FolderLevelBuildProvider.cs
- ImportedPolicyConversionContext.cs
- x509utils.cs
- WebPartEditorCancelVerb.cs
- CodeAttributeDeclaration.cs
- HttpTransportSecurityElement.cs
- _BufferOffsetSize.cs
- SqlOuterApplyReducer.cs
- EventsTab.cs
- SQLByte.cs
- MembershipPasswordException.cs
- SqlDataSourceCache.cs
- WebChannelFactory.cs
- ChtmlTextWriter.cs
- TypeGeneratedEventArgs.cs
- WindowsComboBox.cs
- PartitionResolver.cs
- XmlSchemaExporter.cs
- SortFieldComparer.cs
- PeerApplication.cs
- HitTestDrawingContextWalker.cs
- PrinterSettings.cs
- TextRunCacheImp.cs
- ProgressBarAutomationPeer.cs
- ItemCheckedEvent.cs
- TrackingWorkflowEventArgs.cs
- WebHttpBehavior.cs
- PartitionerQueryOperator.cs
- WebPartConnectionsConfigureVerb.cs
- TriggerBase.cs
- EventSetter.cs
- InternalUserCancelledException.cs
- WebPageTraceListener.cs
- PtsPage.cs
- SpecularMaterial.cs
- MaskedTextBoxDesigner.cs
- UnauthorizedWebPart.cs
- EntityClientCacheKey.cs
- TypeElementCollection.cs
- XhtmlBasicValidatorAdapter.cs
- SizeAnimationClockResource.cs
- FontWeights.cs
- PropertyValueUIItem.cs
- QuarticEase.cs
- Pen.cs
- TypeToken.cs
- KnownTypesHelper.cs
- XslCompiledTransform.cs
- KnowledgeBase.cs
- HtmlTernaryTree.cs
- Line.cs
- MessageLoggingElement.cs
- DispatcherExceptionEventArgs.cs
- BoundColumn.cs
- InputReport.cs
- ExpressionVisitor.cs
- XAMLParseException.cs
- BindingValueChangedEventArgs.cs
- PerformanceCounter.cs
- StrokeNodeData.cs
- MimeMapping.cs
- RandomDelayQueuedSendsAsyncResult.cs
- AsyncResult.cs
- DataListComponentEditor.cs
- SymbolEqualComparer.cs
- ConnectionManagementElement.cs
- VirtualizingStackPanel.cs
- HyperLinkStyle.cs
- ToolStripStatusLabel.cs
- MainMenu.cs
- MessageEventSubscriptionService.cs
- ConfigViewGenerator.cs
- StorageEntityContainerMapping.cs
- TextTreeText.cs
- CodeTryCatchFinallyStatement.cs