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
- ButtonColumn.cs
- ThreadAttributes.cs
- MachineKeyValidationConverter.cs
- ColumnWidthChangedEvent.cs
- DefaultPrintController.cs
- PolicyStatement.cs
- ToolStripDesignerUtils.cs
- QilExpression.cs
- TaskCanceledException.cs
- FormsAuthenticationUserCollection.cs
- Helper.cs
- CursorConverter.cs
- DataGridViewCellStateChangedEventArgs.cs
- CheckableControlBaseAdapter.cs
- SafeHandles.cs
- SqlDesignerDataSourceView.cs
- InfoCardArgumentException.cs
- ContentPosition.cs
- PackageRelationshipSelector.cs
- EditorPartCollection.cs
- RuleSetCollection.cs
- CodeParameterDeclarationExpressionCollection.cs
- HMAC.cs
- ConfigXmlElement.cs
- StylusCaptureWithinProperty.cs
- MsmqIntegrationProcessProtocolHandler.cs
- Exceptions.cs
- ObsoleteAttribute.cs
- DynamicQueryableWrapper.cs
- ProfileSettings.cs
- DetailsViewUpdateEventArgs.cs
- Page.cs
- RecognizedWordUnit.cs
- EmbeddedMailObject.cs
- MbpInfo.cs
- ApplicationActivator.cs
- PartialCachingAttribute.cs
- ClientTarget.cs
- WebServiceTypeData.cs
- GroupBoxDesigner.cs
- ClientFormsIdentity.cs
- NameValueFileSectionHandler.cs
- XmlDocumentSerializer.cs
- RSACryptoServiceProvider.cs
- TemplateInstanceAttribute.cs
- DataSourceViewSchemaConverter.cs
- JournalEntryStack.cs
- EncoderFallback.cs
- ServiceOperation.cs
- CheckBoxDesigner.cs
- SqlParameterCollection.cs
- ToolBar.cs
- UserControlCodeDomTreeGenerator.cs
- SingleAnimation.cs
- MimeBasePart.cs
- HttpProfileGroupBase.cs
- UnsafeMethods.cs
- EventLogPermission.cs
- GcSettings.cs
- ApplicationActivator.cs
- TypedDataSetSchemaImporterExtension.cs
- precedingquery.cs
- Comparer.cs
- ListViewItemSelectionChangedEvent.cs
- PropertyIDSet.cs
- TripleDES.cs
- QuestionEventArgs.cs
- ProjectionPlanCompiler.cs
- PostBackOptions.cs
- ProtocolsSection.cs
- ConditionCollection.cs
- ChannelServices.cs
- KnownTypeAttribute.cs
- CollectionBuilder.cs
- Error.cs
- NullableLongSumAggregationOperator.cs
- ListMarkerSourceInfo.cs
- BatchParser.cs
- AutoResetEvent.cs
- PropertyValueUIItem.cs
- DataBinder.cs
- HttpServerChannel.cs
- NominalTypeEliminator.cs
- NavigateUrlConverter.cs
- MenuItemAutomationPeer.cs
- LinqDataSourceUpdateEventArgs.cs
- DataSourceSelectArguments.cs
- WSSecurityOneDotOneSendSecurityHeader.cs
- Int32.cs
- FormView.cs
- altserialization.cs
- DateTimeSerializationSection.cs
- PrintDialogException.cs
- MdiWindowListItemConverter.cs
- DataServiceContext.cs
- DataGridPagingPage.cs
- DataGridViewRowHeaderCell.cs
- DataRowCollection.cs
- WebControlAdapter.cs
- WebBrowserBase.cs