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)); } }