Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / ActivityLocationReferenceEnvironment.cs / 1305376 / ActivityLocationReferenceEnvironment.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities { using System.Activities.Validation; using System.Collections.Generic; using System.Runtime; [Fx.Tag.XamlVisible(false)] sealed class ActivityLocationReferenceEnvironment : LocationReferenceEnvironment { Dictionarydeclarations; List unnamedDeclarations; public ActivityLocationReferenceEnvironment() { } public ActivityLocationReferenceEnvironment(LocationReferenceEnvironment parent) { this.Parent = parent; if (this.Parent != null) { this.InternalRoot = parent.Root; } } public override Activity Root { get { return this.InternalRoot; } } public Activity InternalRoot { get; set; } Dictionary Declarations { get { if (this.declarations == null) { this.declarations = new Dictionary (); } return this.declarations; } } public override bool IsVisible(LocationReference locationReference) { if (locationReference == null) { throw FxTrace.Exception.ArgumentNull("locationReference"); } LocationReferenceEnvironment currentScope = this; while (currentScope != null) { ActivityLocationReferenceEnvironment activityEnvironment = currentScope as ActivityLocationReferenceEnvironment; if (activityEnvironment != null) { if (activityEnvironment.declarations != null) { foreach (LocationReference declaration in activityEnvironment.declarations.Values) { if (locationReference == declaration) { return true; } } } if (activityEnvironment.unnamedDeclarations != null) { for (int i = 0; i < activityEnvironment.unnamedDeclarations.Count; i++) { if (locationReference == activityEnvironment.unnamedDeclarations[i]) { return true; } } } } else { return currentScope.IsVisible(locationReference); } currentScope = currentScope.Parent; } return false; } public void Declare(LocationReference locationReference, Activity owner, ref IList validationErrors) { Fx.Assert(locationReference != null, "Must not be null"); if (locationReference.Name == null) { if (this.unnamedDeclarations == null) { this.unnamedDeclarations = new List (); } this.unnamedDeclarations.Add(locationReference); } else { if (this.Declarations.ContainsKey(locationReference.Name)) { string id = null; if (owner != null) { id = owner.Id; } ValidationError validationError = new ValidationError(SR.SymbolNamesMustBeUnique(locationReference.Name)) { Source = owner, Id = id }; ActivityUtilities.Add(ref validationErrors, validationError); } else { this.Declarations.Add(locationReference.Name, locationReference); } } } public override bool TryGetLocationReference(string name, out LocationReference result) { if (name == null) { // We don't allow null names in our LocationReferenceEnvironment but // a custom declared environment might. We need to walk up // to the root and see if it chains to a // non-ActivityLocationReferenceEnvironment implementation LocationReferenceEnvironment currentEnvironment = this.Parent; while (currentEnvironment is ActivityLocationReferenceEnvironment) { currentEnvironment = currentEnvironment.Parent; } if (currentEnvironment != null) { Fx.Assert(!(currentEnvironment is ActivityLocationReferenceEnvironment), "We must be at a non-ActivityLocationReferenceEnvironment implementation."); return currentEnvironment.TryGetLocationReference(name, out result); } } else { if (this.declarations != null && this.declarations.TryGetValue(name, out result)) { return true; } bool found = false; LocationReferenceEnvironment currentEnvironment = this.Parent; LocationReferenceEnvironment rootEnvironment = this; // Loop through all of the ActivityLocationReferenceEnvironments we have chained together while (currentEnvironment != null && currentEnvironment is ActivityLocationReferenceEnvironment) { ActivityLocationReferenceEnvironment activityEnvironment = (ActivityLocationReferenceEnvironment)currentEnvironment; if (activityEnvironment.declarations != null && activityEnvironment.declarations.TryGetValue(name, out result)) { return true; } rootEnvironment = currentEnvironment; currentEnvironment = currentEnvironment.Parent; } if (!found) { if (currentEnvironment != null) { // Looks like we have a non-ActivityLocationReferenceEnvironment at the root Fx.Assert(!(currentEnvironment is ActivityLocationReferenceEnvironment), "We should have some other host environment at this point."); if (currentEnvironment.TryGetLocationReference(name, out result)) { return true; } } } } result = null; return false; } public override IEnumerable GetLocationReferences() { return this.Declarations.Values; } } } // 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
- UrlAuthFailedErrorFormatter.cs
- DbInsertCommandTree.cs
- ClientSponsor.cs
- input.cs
- ProjectedSlot.cs
- OrthographicCamera.cs
- SslStream.cs
- HashCodeCombiner.cs
- UnsafeNativeMethods.cs
- RSAOAEPKeyExchangeFormatter.cs
- FuncCompletionCallbackWrapper.cs
- BitmapCodecInfoInternal.cs
- KeyGesture.cs
- ConnectionProviderAttribute.cs
- XmlSchemaCollection.cs
- DynamicDataRoute.cs
- Label.cs
- XamlSerializationHelper.cs
- _RequestCacheProtocol.cs
- Events.cs
- TypeUtil.cs
- WindowsIPAddress.cs
- OdbcFactory.cs
- ContentWrapperAttribute.cs
- HeaderUtility.cs
- MexServiceChannelBuilder.cs
- EncryptedKeyIdentifierClause.cs
- SimpleApplicationHost.cs
- log.cs
- SchemaElementLookUpTable.cs
- StringValueSerializer.cs
- Brush.cs
- LongAverageAggregationOperator.cs
- SelfIssuedAuthRSACryptoProvider.cs
- EntityContainerEmitter.cs
- Win32MouseDevice.cs
- HashCodeCombiner.cs
- NonParentingControl.cs
- UriScheme.cs
- PersistenceTypeAttribute.cs
- DrawingState.cs
- BaseCollection.cs
- DataServiceQueryException.cs
- WebResourceAttribute.cs
- TextSerializer.cs
- ReferencedCollectionType.cs
- FilterQuery.cs
- clipboard.cs
- CounterSample.cs
- DataComponentMethodGenerator.cs
- QuotedStringWriteStateInfo.cs
- ArrangedElementCollection.cs
- XmlSortKeyAccumulator.cs
- ConnectionPointCookie.cs
- ChineseLunisolarCalendar.cs
- COM2ExtendedTypeConverter.cs
- XamlStream.cs
- ComplexLine.cs
- SortedSetDebugView.cs
- PositiveTimeSpanValidator.cs
- Table.cs
- AlignmentYValidation.cs
- HtmlLink.cs
- ScrollViewerAutomationPeer.cs
- OdbcEnvironmentHandle.cs
- XmlQueryStaticData.cs
- SchemaElementLookUpTable.cs
- ZipIOExtraFieldPaddingElement.cs
- DiscardableAttribute.cs
- CodeNamespaceImport.cs
- Int32CAMarshaler.cs
- DataSourceExpressionCollection.cs
- WindowsButton.cs
- XmlCodeExporter.cs
- EventPrivateKey.cs
- HtmlInputRadioButton.cs
- userdatakeys.cs
- SingleConverter.cs
- ToolbarAUtomationPeer.cs
- ThreadAttributes.cs
- ExpressionUtilities.cs
- AssociationTypeEmitter.cs
- TypeLoader.cs
- VerificationAttribute.cs
- UdpChannelFactory.cs
- DependencyObjectProvider.cs
- WindowsTokenRoleProvider.cs
- ExpressionVisitor.cs
- ConfigurationProperty.cs
- PerformanceCounterPermission.cs
- CacheOutputQuery.cs
- SystemUdpStatistics.cs
- SqlHelper.cs
- SqlBuilder.cs
- DataServiceKeyAttribute.cs
- CreateUserErrorEventArgs.cs
- IImplicitResourceProvider.cs
- ClientBuildManagerTypeDescriptionProviderBridge.cs
- DetailsViewInsertedEventArgs.cs
- ListBoxItemWrapperAutomationPeer.cs