Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / ExecutionProperties.cs / 1305376 / ExecutionProperties.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities
{
using System;
using System.Activities.Runtime;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime;
[SuppressMessage(FxCop.Category.Naming, FxCop.Rule.IdentifiersShouldHaveCorrectSuffix)]
[Fx.Tag.XamlVisible(false)]
public sealed class ExecutionProperties : IEnumerable>
{
static IEnumerable> emptyKeyValues;
ActivityContext context;
ActivityInstance scope;
ExecutionPropertyManager properties;
IdSpace currentIdSpace;
internal ExecutionProperties(ActivityContext currentContext, ActivityInstance scope, ExecutionPropertyManager properties)
{
this.context = currentContext;
this.scope = scope;
this.properties = properties;
if (this.context != null)
{
this.currentIdSpace = this.context.Activity.MemberOf;
}
}
public bool IsEmpty
{
get
{
return (this.properties == null);
}
}
static IEnumerable> EmptyKeyValues
{
get
{
if (emptyKeyValues == null)
{
emptyKeyValues = new KeyValuePair[0];
}
return emptyKeyValues;
}
}
[Fx.Tag.InheritThrows(From = "Register", FromDeclaringType = typeof(IPropertyRegistrationCallback))]
public void Add(string name, object property)
{
Add(name, property, false, false);
}
[Fx.Tag.InheritThrows(From = "Add")]
public void Add(string name, object property, bool onlyVisibleToPublicChildren)
{
Add(name, property, false, onlyVisibleToPublicChildren);
}
internal void Add(string name, object property, bool skipValidations, bool onlyVisibleToPublicChildren)
{
if (!skipValidations)
{
if (string.IsNullOrEmpty(name))
{
throw FxTrace.Exception.ArgumentNullOrEmpty("name");
}
if (property == null)
{
throw FxTrace.Exception.ArgumentNull("property");
}
ThrowIfActivityExecutionContextDisposed();
ThrowIfChildrenAreExecuting();
}
if (this.properties != null)
{
this.properties.ThrowIfAlreadyDefined(name, this.scope);
}
IPropertyRegistrationCallback registrationCallback = property as IPropertyRegistrationCallback;
if (registrationCallback != null)
{
registrationCallback.Register(new RegistrationContext(this.properties, this.currentIdSpace));
}
if (this.properties == null)
{
this.properties = new ExecutionPropertyManager(this.scope);
}
else if (!this.properties.IsOwner(this.scope))
{
//
this.properties = new ExecutionPropertyManager(this.scope, this.properties);
}
IdSpace visibility = null;
if (onlyVisibleToPublicChildren)
{
Fx.Assert(this.currentIdSpace != null, "We should never call OnlyVisibleToPublicChildren when we don't have a currentIdSpace");
visibility = this.currentIdSpace;
}
this.properties.Add(name, property, visibility);
}
[Fx.Tag.InheritThrows(From = "Unregister", FromDeclaringType = typeof(IPropertyRegistrationCallback))]
public bool Remove(string name)
{
return Remove(name, false);
}
internal bool Remove(string name, bool skipValidations)
{
if (!skipValidations)
{
if (string.IsNullOrEmpty(name))
{
throw FxTrace.Exception.ArgumentNullOrEmpty("name");
}
ThrowIfActivityExecutionContextDisposed();
}
if (this.properties != null && this.properties.IsOwner(this.scope))
{
object property = this.properties.GetPropertyAtCurrentScope(name);
if (property != null)
{
if (!skipValidations)
{
Handle handleProperty = property as Handle;
if (handleProperty == null || !handleProperty.CanBeRemovedWithExecutingChildren)
{
ThrowIfChildrenAreExecuting();
}
}
this.properties.Remove(name);
IPropertyRegistrationCallback registrationCallback = property as IPropertyRegistrationCallback;
if (registrationCallback != null)
{
registrationCallback.Unregister(new RegistrationContext(this.properties, this.currentIdSpace));
}
return true;
}
}
return false;
}
public object Find(string name)
{
if (string.IsNullOrEmpty(name))
{
throw FxTrace.Exception.ArgumentNullOrEmpty("name");
}
if (this.properties == null)
{
return null;
}
else
{
return this.properties.GetProperty(name, this.currentIdSpace);
}
}
// Note that we don't need to pass the IdSpace here because we're
// just checking for things that this activity has added.
internal object FindAtCurrentScope(string name)
{
Fx.Assert(!string.IsNullOrEmpty(name), "We should only call this with non-null names");
if (this.properties == null || !this.properties.IsOwner(this.scope))
{
return null;
}
else
{
return this.properties.GetPropertyAtCurrentScope(name);
}
}
public IEnumerator> GetEnumerator()
{
return GetKeyValues().GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetKeyValues().GetEnumerator();
}
IEnumerable> GetKeyValues()
{
if (this.properties != null)
{
return this.properties.GetFlattenedProperties(this.currentIdSpace);
}
else
{
return EmptyKeyValues;
}
}
void ThrowIfChildrenAreExecuting()
{
if (this.scope.HasChildren)
{
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.CannotAddOrRemoveWithChildren));
}
}
void ThrowIfActivityExecutionContextDisposed()
{
if (this.context.IsDisposed)
{
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.AECForPropertiesHasBeenDisposed));
}
}
}
}
// 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
- SystemParameters.cs
- QuestionEventArgs.cs
- EncodingTable.cs
- processwaithandle.cs
- ClientScriptManagerWrapper.cs
- ISAPIRuntime.cs
- Timeline.cs
- MessageSecurityTokenVersion.cs
- RuleSettingsCollection.cs
- WebPartEventArgs.cs
- CLSCompliantAttribute.cs
- FormsAuthenticationModule.cs
- QuerySettings.cs
- ServiceOperationListItem.cs
- PathSegmentCollection.cs
- PropertyMetadata.cs
- WasHttpHandlersInstallComponent.cs
- ServiceContractAttribute.cs
- HttpException.cs
- UnsafeNativeMethods.cs
- SimpleTextLine.cs
- controlskin.cs
- EndPoint.cs
- ValidatingPropertiesEventArgs.cs
- EventHandlerList.cs
- Message.cs
- XmlQueryContext.cs
- HtmlUtf8RawTextWriter.cs
- HtmlInputCheckBox.cs
- Label.cs
- CodeDomLocalizationProvider.cs
- PassportIdentity.cs
- SkinIDTypeConverter.cs
- ZipIOModeEnforcingStream.cs
- SchemaConstraints.cs
- Point3DConverter.cs
- HttpAsyncResult.cs
- MessageSmuggler.cs
- DBSchemaRow.cs
- ProfileServiceManager.cs
- TemplatePropertyEntry.cs
- SqlBuffer.cs
- COMException.cs
- SpellerStatusTable.cs
- PerfService.cs
- UriExt.cs
- CheckedPointers.cs
- PartialTrustVisibleAssemblyCollection.cs
- XmlSchemas.cs
- TriggerCollection.cs
- ExpressionLexer.cs
- AppSecurityManager.cs
- GeneralTransform2DTo3DTo2D.cs
- StrokeNodeOperations2.cs
- CodeAttributeDeclarationCollection.cs
- NewArray.cs
- SqlRowUpdatingEvent.cs
- ItemCollection.cs
- NextPreviousPagerField.cs
- ComponentChangedEvent.cs
- ImportRequest.cs
- LineServicesCallbacks.cs
- UserUseLicenseDictionaryLoader.cs
- WindowPattern.cs
- ErrorTableItemStyle.cs
- SafeNativeMethods.cs
- DesignTimeTemplateParser.cs
- CompositeDataBoundControl.cs
- IPAddress.cs
- OperationCanceledException.cs
- TableRowsCollectionEditor.cs
- ListView.cs
- UrlAuthorizationModule.cs
- AsyncResult.cs
- CollectionChangedEventManager.cs
- XsdBuilder.cs
- FusionWrap.cs
- IPEndPoint.cs
- HtmlHead.cs
- ShaderEffect.cs
- _HeaderInfoTable.cs
- ZipIOEndOfCentralDirectoryBlock.cs
- SvcMapFileLoader.cs
- IFlowDocumentViewer.cs
- XmlArrayItemAttributes.cs
- TransactionContextValidator.cs
- HtmlLink.cs
- EDesignUtil.cs
- DateTimeConstantAttribute.cs
- Resources.Designer.cs
- DateTimeConstantAttribute.cs
- dbdatarecord.cs
- TextAnchor.cs
- GeneralTransform3D.cs
- DataServiceRequest.cs
- TypeElement.cs
- XamlPointCollectionSerializer.cs
- GeneralTransform3DGroup.cs
- BitmapFrameDecode.cs
- ISAPIRuntime.cs