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
- FrugalMap.cs
- ProcessInfo.cs
- ListControlDesigner.cs
- CompoundFileStorageReference.cs
- RuleSettingsCollection.cs
- SmtpNtlmAuthenticationModule.cs
- DesignerExtenders.cs
- StructuredTypeInfo.cs
- Content.cs
- DbProviderFactories.cs
- TextPenaltyModule.cs
- ResourceReferenceExpressionConverter.cs
- InputReportEventArgs.cs
- CngProperty.cs
- DataBoundControlAdapter.cs
- ExtendedTransformFactory.cs
- AlternateView.cs
- XmlDataLoader.cs
- ScrollProviderWrapper.cs
- SQLChars.cs
- WebResourceAttribute.cs
- NameObjectCollectionBase.cs
- CannotUnloadAppDomainException.cs
- Enum.cs
- IfJoinedCondition.cs
- CardSpaceSelector.cs
- LinkAreaEditor.cs
- DataGridLength.cs
- PartBasedPackageProperties.cs
- ClientConfigurationHost.cs
- PathSegmentCollection.cs
- SqlEnums.cs
- RequestCachePolicy.cs
- controlskin.cs
- DefaultExpressionVisitor.cs
- Section.cs
- PagesSection.cs
- ISSmlParser.cs
- PermissionSet.cs
- Stroke2.cs
- PackWebResponse.cs
- NavigationProperty.cs
- GetPageNumberCompletedEventArgs.cs
- WorkflowEventArgs.cs
- XsltLoader.cs
- GeneralTransformGroup.cs
- ListBox.cs
- DrawingVisual.cs
- ImageIndexEditor.cs
- SpeechEvent.cs
- EmptyEnumerable.cs
- SponsorHelper.cs
- SQlBooleanStorage.cs
- JsonGlobals.cs
- MruCache.cs
- XpsSerializerFactory.cs
- FileSystemInfo.cs
- Span.cs
- InputManager.cs
- DefaultPrintController.cs
- objectquery_tresulttype.cs
- Behavior.cs
- Membership.cs
- XmlReaderSettings.cs
- XmlSortKeyAccumulator.cs
- Attributes.cs
- HttpCachePolicyElement.cs
- ActionItem.cs
- CalendarDay.cs
- StorageComplexTypeMapping.cs
- OdbcConnectionString.cs
- MimeMultiPart.cs
- SecureUICommand.cs
- TypeUtil.cs
- ClientSponsor.cs
- StringKeyFrameCollection.cs
- ProgramNode.cs
- PrinterSettings.cs
- FixedPage.cs
- WizardSideBarListControlItem.cs
- DocumentPageViewAutomationPeer.cs
- WinFormsSecurity.cs
- dbdatarecord.cs
- DataViewManager.cs
- WebPartDescription.cs
- InvokePatternIdentifiers.cs
- XmlSchemaAnnotated.cs
- RemotingConfiguration.cs
- PerfCounterSection.cs
- SettingsBindableAttribute.cs
- GridViewHeaderRowPresenter.cs
- NetworkInformationPermission.cs
- FlowLayout.cs
- Win32.cs
- HtmlEmptyTagControlBuilder.cs
- AdornerPresentationContext.cs
- TypeSource.cs
- MenuRenderer.cs
- StringUtil.cs
- Margins.cs