Beispiel #1
0
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     if (!string.IsNullOrEmpty(this.PropertyName))
     {
         object rootTemplatedActivity = ActivityWithResultConverter.GetRootTemplatedActivity(serviceProvider);
         if (rootTemplatedActivity != null)
         {
             PropertyDescriptor descriptor = TypeDescriptor.GetProperties(rootTemplatedActivity)[this.PropertyName];
             if (descriptor != null)
             {
                 return(descriptor.GetValue(rootTemplatedActivity));
             }
         }
     }
     throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.PropertyReferenceNotFound(this.PropertyName)));
 }
Beispiel #2
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (!string.IsNullOrEmpty(this.PropertyName))
            {
                object targetObject = ActivityWithResultConverter.GetRootTemplatedActivity(serviceProvider);
                if (targetObject != null)
                {
                    PropertyDescriptor property = TypeDescriptor.GetProperties(targetObject)[PropertyName];

                    if (property != null)
                    {
                        return(property.GetValue(targetObject));
                    }
                }
            }

            throw FxTrace.Exception.AsError(
                      new InvalidOperationException(SR.PropertyReferenceNotFound(this.PropertyName)));
        }
        static bool TryEvaluateExpression(
            string expressionString,
            Type locationValueType,                             // Non null for Reference type (location)
            LocationReferenceEnvironment locationReferenceEnvironment,
            CodeActivityContext context,
            out object result)
        {
            expressionString = string.Format(CultureInfo.InvariantCulture, "[{0}]", expressionString);

            Type activityType;
            if (locationValueType != null)
            {
                activityType = typeof(Activity<>).MakeGenericType(typeof(Location<>).MakeGenericType(locationValueType));
            }
            else
            {
                activityType = typeof(Activity<object>);
            }

            // General expression.
            ActivityWithResultConverter converter = new ActivityWithResultConverter(activityType);
            ActivityWithResult expression = converter.ConvertFromString(
                new TypeDescriptorContext { LocationReferenceEnvironment = locationReferenceEnvironment },
                expressionString) as ActivityWithResult;

            if (locationValueType != null)
            {
                Type locationHelperType = typeof(LocationHelper<>).MakeGenericType(locationValueType);
                LocationHelper helper = (LocationHelper)Activator.CreateInstance(locationHelperType);
                return helper.TryGetValue(expression, locationReferenceEnvironment, context, out result);
            }
            else
            {
                return TryEvaluateExpression(expression, locationReferenceEnvironment, context, out result);
            }
        }