示例#1
0
        private static bool TryEvaluateExpression(string expressionString, Type locationValueType, LocationReferenceEnvironment locationReferenceEnvironment, ActivityContext context, out object result)
        {
            Type type;

            expressionString = string.Format(CultureInfo.InvariantCulture, "[{0}]", new object[] { expressionString });
            if (locationValueType != null)
            {
                type = typeof(Activity <>).MakeGenericType(new Type[] { typeof(Location <>).MakeGenericType(new Type[] { locationValueType }) });
            }
            else
            {
                type = typeof(Activity <object>);
            }
            ActivityWithResultConverter converter = new ActivityWithResultConverter(type);
            TypeDescriptorContext       context2  = new TypeDescriptorContext {
                LocationReferenceEnvironment = locationReferenceEnvironment
            };
            ActivityWithResult expression = converter.ConvertFromString(context2, expressionString) as ActivityWithResult;

            if (locationValueType != null)
            {
                LocationHelper helper = (LocationHelper)Activator.CreateInstance(typeof(LocationHelper).MakeGenericType(new Type[] { locationValueType }));
                return(helper.TryGetValue(expression, locationReferenceEnvironment, context, out result));
            }
            return(TryEvaluateExpression <object>(expression, locationReferenceEnvironment, context, out result));
        }
示例#2
0
        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));
            }
        }