Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Variable.cs / 1305376 / Variable.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities { using System; using System.Activities.Expressions; using System.Activities.Runtime; using System.Activities.Validation; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; using System.Diagnostics; using System.Linq.Expressions; using System.Runtime; using System.Runtime.Serialization; [DebuggerDisplay("Name = {Name}, Type = {Type}")] public abstract class Variable : LocationReference { VariableModifiers modifiers; string name; int cacheId; internal Variable() : base() { this.Id = -1; } internal bool IsHandle { get; set; } [DefaultValue(null)] public new string Name { get { return this.name; } set { this.name = value; } } [DefaultValue(VariableModifiers.None)] public VariableModifiers Modifiers { get { return this.modifiers; } set { VariableModifiersHelper.Validate(value, "value"); this.modifiers = value; } } [IgnoreDataMember] // this member is repeated by all subclasses, which we control [DefaultValue(null)] public ActivityWithResult Default { get { return this.DefaultCore; } set { this.DefaultCore = value; } } protected override string NameCore { get { return this.name; } } internal abstract ActivityWithResult DefaultCore { get; set; } internal bool IsPublic { get; set; } internal Activity Owner { get; private set; } internal bool IsInTree { get { return this.Owner != null; } } public static Variable Create(string name, Type type, VariableModifiers modifiers) { return ActivityUtilities.CreateVariable(name, type, modifiers); } internal bool InitializeRelationship(Activity parent, bool isPublic, ref IListvalidationErrors) { if (this.cacheId == parent.CacheId) { if (this.Owner != null) { ValidationError validationError = new ValidationError(SR.VariableAlreadyInUseOnActivity(this.Name, parent.DisplayName, this.Owner.DisplayName), false, this.Name, parent); ActivityUtilities.Add(ref validationErrors, validationError); // Get out early since we've already initialized this variable. return false; } } this.Owner = parent; this.cacheId = parent.CacheId; this.IsPublic = isPublic; if (this.Default != null) { ActivityWithResult expression = this.Default; if (expression is Argument.IExpressionWrapper) { expression = ((Argument.IExpressionWrapper)expression).InnerExpression; } if (expression.ResultType != this.Type) { ActivityUtilities.Add( ref validationErrors, new ValidationError(SR.VariableExpressionTypeMismatch(this.Name, this.Type, expression.ResultType), false, this.Name, parent)); } return this.Default.InitializeRelationship(this, isPublic, ref validationErrors); } return true; } internal void ThrowIfNotInTree() { if (!this.IsInTree) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.VariableNotOpen(this.Name, this.Type))); } } internal void ThrowIfHandle() { if (this.IsHandle) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.CannotPerformOperationOnHandle)); } } public override Location GetLocation(ActivityContext context) { if (context == null) { throw FxTrace.Exception.ArgumentNull("context"); } // No need to call context.ThrowIfDisposed explicitly since all // the methods/properties on the context will perform that check. ThrowIfNotInTree(); Location location; if (!context.AllowChainedEnvironmentAccess) { if (this.IsPublic || !object.ReferenceEquals(this.Owner, context.Activity)) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.VariableOnlyAccessibleAtScopeOfDeclaration(context.Activity, this.Owner))); } if (!context.Environment.TryGetLocation(this.Id, out location)) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.VariableDoesNotExist(this.Name))); } } else { // No validations in the allow chained access case if (!context.Environment.TryGetLocation(this.Id, this.Owner, out location)) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.VariableDoesNotExist(this.Name))); } } return location; } // Soft-Link: This method is referenced through reflection by // ExpressionUtilities.TryRewriteLambdaExpression. Update that // file if the signature changes. public object Get(ActivityContext context) { if (context == null) { throw FxTrace.Exception.ArgumentNull("context"); } return context.GetValue
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PriorityRange.cs
- EdmSchemaAttribute.cs
- SafeRightsManagementPubHandle.cs
- CLSCompliantAttribute.cs
- EntityDataSourceChangedEventArgs.cs
- ChtmlTextBoxAdapter.cs
- VideoDrawing.cs
- ReflectionUtil.cs
- DynamicResourceExtensionConverter.cs
- AudioDeviceOut.cs
- NamedPipeWorkerProcess.cs
- ClientSettings.cs
- TextUtf8RawTextWriter.cs
- AudioLevelUpdatedEventArgs.cs
- DesigntimeLicenseContextSerializer.cs
- datacache.cs
- CompilationRelaxations.cs
- X509UI.cs
- CodeConstructor.cs
- Missing.cs
- ReflectionUtil.cs
- PartialCachingControl.cs
- DatatypeImplementation.cs
- dbdatarecord.cs
- DataFormat.cs
- VisualTreeUtils.cs
- SchemaElement.cs
- StrongNameUtility.cs
- PeerSecurityManager.cs
- LoadedOrUnloadedOperation.cs
- FrameworkElementAutomationPeer.cs
- TypeUtil.cs
- PrintEvent.cs
- WebPartCloseVerb.cs
- TdsParser.cs
- ProcessHostFactoryHelper.cs
- XmlComment.cs
- Button.cs
- XmlDataSource.cs
- FontUnit.cs
- CheckBoxRenderer.cs
- XNodeNavigator.cs
- BrowserCapabilitiesFactoryBase.cs
- HtmlInputButton.cs
- RotationValidation.cs
- Propagator.JoinPropagator.cs
- UserControl.cs
- XmlJsonReader.cs
- ParameterDataSourceExpression.cs
- InheritedPropertyChangedEventArgs.cs
- ProfileSettings.cs
- WebScriptServiceHost.cs
- DeviceFilterEditorDialog.cs
- BitmapCodecInfo.cs
- QuaternionAnimationBase.cs
- SingleAnimation.cs
- Timeline.cs
- XmlDocument.cs
- Behavior.cs
- HtmlMeta.cs
- DecimalAnimation.cs
- IDispatchConstantAttribute.cs
- loginstatus.cs
- ReceiveErrorHandling.cs
- ReliableReplySessionChannel.cs
- SmiMetaDataProperty.cs
- ListView.cs
- MsmqInputChannel.cs
- BmpBitmapEncoder.cs
- Ipv6Element.cs
- TextElementEnumerator.cs
- PolicyLevel.cs
- SizeConverter.cs
- ApplicationInfo.cs
- HttpResponse.cs
- Graphics.cs
- ScaleTransform3D.cs
- SevenBitStream.cs
- ComponentCommands.cs
- Select.cs
- AuthenticationException.cs
- SQLDateTimeStorage.cs
- ColumnResizeAdorner.cs
- WeakEventManager.cs
- NativeMethods.cs
- PrePostDescendentsWalker.cs
- ItemTypeToolStripMenuItem.cs
- PropertyInfoSet.cs
- ToolbarAUtomationPeer.cs
- AuthorizationRuleCollection.cs
- ActivityScheduledQuery.cs
- ObjectDataSourceDesigner.cs
- ContentPlaceHolder.cs
- Geometry3D.cs
- _BufferOffsetSize.cs
- ViewgenGatekeeper.cs
- Variable.cs
- TreeViewImageGenerator.cs
- URLMembershipCondition.cs
- TrustManagerMoreInformation.cs