示例#1
0
        public void SetValue <T>(LocationReference locationReference, T value)
        {
            ThrowIfDisposed();

            if (locationReference == null)
            {
                throw CoreWf.Internals.FxTrace.Exception.ArgumentNull("locationReference");
            }

            SetValueCore <T>(locationReference, value);
        }
        // Soft-Link: This method is referenced through reflection by
        // ExpressionUtilities.TryRewriteLambdaExpression.  Update that
        // file if the signature changes.
        public T GetValue <T>(LocationReference locationReference)
        {
            ThrowIfDisposed();

            if (locationReference == null)
            {
                throw FxTrace.Exception.ArgumentNull(nameof(locationReference));
            }

            return(GetValueCore <T>(locationReference));
        }
示例#3
0
        // Soft-Link: This method is referenced through reflection by
        // ExpressionUtilities.TryRewriteLambdaExpression.  Update that
        // file if the signature changes.
        public T GetValue <T>(LocationReference locationReference)
        {
            ThrowIfDisposed();

            if (locationReference == null)
            {
                throw CoreWf.Internals.FxTrace.Exception.ArgumentNull("locationReference");
            }

            return(GetValueCore <T>(locationReference));
        }
        public void SetValue <T>(LocationReference locationReference, T value)
        {
            ThrowIfDisposed();

            if (locationReference == null)
            {
                throw FxTrace.Exception.ArgumentNull(nameof(locationReference));
            }

            SetValueCore <T>(locationReference, value);
        }
        public bool TryGetReferenceToPublicLocation(LocationReference publicReference,
                                                    out LocationReference equivalentReference)
        {
            if (publicReference == null)
            {
                throw FxTrace.Exception.ArgumentNull(nameof(publicReference));
            }
            ThrowIfUninitialized();

            return(TryGetReferenceToPublicLocation(publicReference, false, out equivalentReference));
        }
        public bool TryGetAccessToPublicLocation(LocationReference publicLocation,
                                                 ArgumentDirection accessDirection, out LocationReference equivalentLocation)
        {
            if (publicLocation == null)
            {
                throw FxTrace.Exception.ArgumentNull(nameof(publicLocation));
            }
            ThrowIfUninitialized();

            return(TryGetAccessToPublicLocation(publicLocation, accessDirection, false, out equivalentLocation));
        }
 private void AddProperty(LocationReference reference, Dictionary <string, object> names,
                          List <PropertyDescriptorImpl> propertyList)
 {
     if (!string.IsNullOrEmpty(reference.Name) &&
         !names.ContainsKey(reference.Name))
     {
         names.Add(reference.Name, reference);
         PropertyDescriptorImpl property = new PropertyDescriptorImpl(reference);
         propertyList.Add(property);
         AddNotifyHandler(property);
     }
 }
示例#8
0
        public override bool IsVisible(LocationReference locationReference)
        {
            if (locationReference == null)
            {
                throw CoreWf.Internals.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);
        }
        internal T GetValueCore <T>(LocationReference locationReference)
        {
            Location location = locationReference.GetLocationForRead(this);


            if (location is Location <T> typedLocation)
            {
                // If we hit this path we can avoid boxing value types
                return(typedLocation.Value);
            }
            else
            {
                Fx.Assert(location != null, "The contract of LocationReference is that GetLocation never returns null.");

                return(TypeHelper.Convert <T>(location.Value));
            }
        }
示例#10
0
        internal bool TryGetReferenceToPublicLocation(LocationReference publicReference,
                                                      bool useLocationReferenceValue, out LocationReference equivalentReference)
        {
            Fx.Assert(!useLocationReferenceValue || this.ActivityMetadata.CurrentActivity.UseOldFastPath, "useLocationReferenceValue should only be used for back-compat");

            if (_metadata.Environment.IsVisible(publicReference))
            {
                if (!_withoutArgument)
                {
                    CreateLocationArgument(publicReference, useLocationReferenceValue);
                }
                equivalentReference = new InlinedLocationReference(publicReference, _metadata.CurrentActivity);
                return(true);
            }

            equivalentReference = null;
            return(false);
        }
        // In 4.0 the expression type for publicly inspectable auto-generated arguments was
        // LocationReferenceValue<T>, whether the argument was actually used as an L-Value or R-Value.
        // We keep that for back-compat (useLocationReferenceValue == true), and only use the new
        // EnvironmentLocationValue/Reference classes for new activities.
        internal bool TryGetAccessToPublicLocation(LocationReference publicLocation,
                                                   ArgumentDirection accessDirection, bool useLocationReferenceValue, out LocationReference equivalentLocation)
        {
            Fx.Assert(!useLocationReferenceValue || this.ActivityMetadata.CurrentActivity.UseOldFastPath, "useLocationReferenceValue should only be used for back-compat");

            if (this.metadata.Environment.IsVisible(publicLocation))
            {
                if (!this.withoutArgument)
                {
                    CreateArgument(publicLocation, accessDirection, useLocationReferenceValue);
                }
                equivalentLocation = new InlinedLocationReference(publicLocation, this.metadata.CurrentActivity, accessDirection);
                return(true);
            }

            equivalentLocation = null;
            return(false);
        }
        internal void SetValueCore <T>(LocationReference locationReference, T value)
        {
            Location location = locationReference.GetLocationForWrite(this);


            if (location is Location <T> typedLocation)
            {
                // If we hit this path we can avoid boxing value types
                typedLocation.Value = value;
            }
            else
            {
                if (!TypeHelper.AreTypesCompatible(value, locationReference.Type))
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(SR.CannotSetValueToLocation(value != null ? value.GetType() : typeof(T), locationReference.Name, locationReference.Type)));
                }

                location.Value = value;
            }
        }
示例#13
0
        public void Declare(LocationReference locationReference, Activity owner, ref IList <ValidationError> validationErrors)
        {
            Fx.Assert(locationReference != null, "Must not be null");

            if (locationReference.Name == null)
            {
                if (_unnamedDeclarations == null)
                {
                    _unnamedDeclarations = new List <LocationReference>();
                }

                _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 abstract bool TryGetLocationReference(string name, out LocationReference result);
 public abstract bool IsVisible(LocationReference locationReference);
示例#16
0
        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 (_declarations != null && _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);
        }
            // TODO 131998, We should support readonly LocationReferences.
            // bool isReadOnly;


            public PropertyDescriptorImpl(LocationReference reference)
                : base(reference.Name, new Attribute[0])
            {
                this.reference = reference;
            }
        internal void CreateLocationArgument(LocationReference sourceReference, bool useLocationReferenceValue = false)
        {
            ActivityWithResult expression = ActivityUtilities.CreateLocationAccessExpression(sourceReference, true, useLocationReferenceValue);

            AddGeneratedArgument(expression.ResultType, ArgumentDirection.In, expression);
        }