public bool TryGetAccessToPublicLocation(LocationReference publicLocation,
                                                 ArgumentDirection accessDirection, out LocationReference equivalentLocation)
        {
            if (publicLocation == null)
            {
                throw Microsoft.CoreWf.Internals.FxTrace.Exception.ArgumentNull("publicLocation");
            }
            ThrowIfUninitialized();

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

            return(TryGetReferenceToPublicLocation(publicReference, false, out equivalentReference));
        }
Esempio n. 3
0
        public void SetValue <T>(LocationReference locationReference, T value)
        {
            ThrowIfDisposed();

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

            SetValueCore <T>(locationReference, value);
        }
Esempio n. 4
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 Microsoft.CoreWf.Internals.FxTrace.Exception.ArgumentNull("locationReference");
            }

            return(GetValueCore <T>(locationReference));
        }
Esempio n. 5
0
        public override bool IsVisible(LocationReference locationReference)
        {
            if (locationReference == null)
            {
                throw Microsoft.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);
        }
        // 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 (_metadata.Environment.IsVisible(publicLocation))
            {
                if (!_withoutArgument)
                {
                    CreateArgument(publicLocation, accessDirection, useLocationReferenceValue);
                }
                equivalentLocation = new InlinedLocationReference(publicLocation, _metadata.CurrentActivity, accessDirection);
                return(true);
            }

            equivalentLocation = null;
            return(false);
        }
Esempio n. 7
0
        internal T GetValueCore <T>(LocationReference locationReference)
        {
            Location location = locationReference.GetLocationForRead(this);

            Location <T> typedLocation = location as Location <T>;

            if (typedLocation != null)
            {
                // 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));
            }
        }
Esempio n. 8
0
        internal void SetValueCore <T>(LocationReference locationReference, T value)
        {
            Location location = locationReference.GetLocationForWrite(this);

            Location <T> typedLocation = location as Location <T>;

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

                location.Value = value;
            }
        }
Esempio n. 9
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);
                }
            }
        }
Esempio n. 10
0
 public abstract bool TryGetLocationReference(string name, out LocationReference result);
Esempio n. 11
0
 public abstract bool IsVisible(LocationReference locationReference);
Esempio n. 12
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);
        }
        internal void CreateLocationArgument(LocationReference sourceReference, bool useLocationReferenceValue = false)
        {
            ActivityWithResult expression = ActivityUtilities.CreateLocationAccessExpression(sourceReference, true, useLocationReferenceValue);

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