/// <exclude />
        public override object GetValue(FunctionContextContainer contextContainer)
        {
            if (contextContainer == null)
            {
                throw new ArgumentNullException("contextContainer");
            }

            ValidateNotSelfCalling();

            ParameterList parameters = new ParameterList(contextContainer);

            foreach (ParameterProfile parameterProfile in _widgetFunction.ParameterProfiles)
            {
                BaseParameterRuntimeTreeNode parameterTreeNode = this.Parameters.Where(ptn => ptn.Name == parameterProfile.Name).SingleOrDefault();

                if (parameterTreeNode == null)
                {
                    BaseValueProvider valueProvider = parameterProfile.FallbackValueProvider;

                    object value = valueProvider.GetValue(contextContainer);

                    parameters.AddConstantParameter(parameterProfile.Name, value, parameterProfile.Type);
                }
                else
                {
                    parameters.AddLazyParameter(parameterProfile.Name, parameterTreeNode, parameterProfile.Type);
                }
            }

            return(_widgetFunction.GetWidgetMarkup(parameters, this.Label, this.HelpDefinition, this.BindingSourceName));
        }
        /// <exclude />
        public ParameterProfile(
            string name,
            Type type,
            bool isRequired,
            BaseValueProvider fallbackValueProvider,
            WidgetFunctionProvider widgetFunctionProvider,
            string label,
            HelpDefinition helpDefinition,
            bool hideInSimpleView)
        {
            Verify.ArgumentNotNull(name, "name");
            Verify.ArgumentNotNull(type, "type");
            Verify.ArgumentNotNull(fallbackValueProvider, "fallbackValueProvider");
            Verify.ArgumentCondition(!label.IsNullOrEmpty(), "label", "label may not be null or an empty string");
            Verify.ArgumentNotNull(helpDefinition, "helpDefinition");

            this.Name                  = name;
            this.Type                  = type;
            this.IsRequired            = isRequired && (!type.IsGenericType || type.GetGenericTypeDefinition() != typeof(NullableDataReference <>));
            this.FallbackValueProvider = fallbackValueProvider;
            _widgetFunctionProvider    = widgetFunctionProvider;
            this.Label                 = label;
            this.HelpDefinition        = helpDefinition;
            this.HideInSimpleView      = hideInSimpleView;
        }
 /// <exclude />
 public ParameterProfile(
     string name, Type type, bool isRequired, BaseValueProvider fallbackValueProvider, WidgetFunctionProvider widgetFunctionProvider,
     Dictionary <string, object> widgetFunctionRuntimeParameters, string label, HelpDefinition helpDefinition)
     : this(name, type, isRequired, fallbackValueProvider, widgetFunctionProvider, label, helpDefinition)
 {
     _widgetFunctionRuntimeParameters = widgetFunctionRuntimeParameters;
 }
        /// <exclude />
        public override object GetValue(FunctionContextContainer contextContainer)
        {
            if (contextContainer == null)
            {
                throw new ArgumentNullException("contextContainer");
            }

            string functionName = _function.CompositeName() ?? "<unknown function>";

            using (TimerProfilerFacade.CreateTimerProfiler(functionName))
            {
                ValidateNotSelfCalling();

                try
                {
                    var parameters = new ParameterList(contextContainer);

                    foreach (ParameterProfile parameterProfile in _function.ParameterProfiles)
                    {
                        List <BaseParameterRuntimeTreeNode> parameterTreeNodes = this.Parameters.Where(ptn => ptn.Name == parameterProfile.Name).ToList();

                        if (parameterTreeNodes.Count > 0)
                        {
                            parameters.AddLazyParameter(parameterProfile.Name, parameterTreeNodes[0], parameterProfile.Type);
                            continue;
                        }

                        if (parameterProfile.Type.IsGenericType &&
                            parameterProfile.Type.GetGenericTypeDefinition() == typeof(NullableDataReference <>))
                        {
                            parameters.AddConstantParameter(parameterProfile.Name, null, parameterProfile.Type);
                            continue;
                        }

                        if (parameterProfile.IsRequired)
                        {
                            var injectedValue = TryGetInjectedValue(parameterProfile.Type);

                            if (injectedValue == null)
                            {
                                throw new ArgumentException("Missing parameter '{0}' (type of {1})".FormatWith(parameterProfile.Name, parameterProfile.Type.FullName));
                            }

                            parameters.AddConstantParameter(parameterProfile.Name, injectedValue, parameterProfile.Type);
                            continue;
                        }

                        BaseValueProvider valueProvider = parameterProfile.FallbackValueProvider;

                        object value;
                        try
                        {
                            value = valueProvider.GetValue(contextContainer);
                        }
                        catch (Exception ex)
                        {
                            throw new InvalidOperationException($"Failed to get value for parameter '{parameterProfile.Name}' in function '{functionName}'.", ex);
                        }
                        parameters.AddConstantParameter(parameterProfile.Name, value, parameterProfile.Type, true);
                    }

                    object result;

                    IDisposable measurement = null;
                    try
                    {
                        if (functionName != "Composite.Utils.GetInputParameter")
                        {
                            var nodeToLog = functionName;

                            if (_function is IDynamicFunction df && df.PreventFunctionOutputCaching)
                            {
                                nodeToLog += " (PreventCaching)";
                            }

                            measurement = Profiler.Measure(nodeToLog, () => _function.EntityToken);
                        }

                        result = _function.Execute(parameters, contextContainer);
                    }
                    finally
                    {
                        measurement?.Dispose();
                    }

                    return(result);
                }
                catch (ThreadAbortException)
                {
                    return(null); // Nothing will be returned as ThreadAbort will propagate
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException($"Failed to get value for function '{functionName}'", ex);
                }
            }
        }
 /// <exclude />
 public ParameterProfile(string name, Type type, bool isRequired, BaseValueProvider fallbackValueProvider, WidgetFunctionProvider widgetFunctionProvider, string label, HelpDefinition helpDefinition)
     : this(name, type, isRequired, fallbackValueProvider, widgetFunctionProvider, label, helpDefinition, false)
 {
 }