private static DataFieldDescriptor CreateReferenceDataFieldDescriptor(DataTypeDescriptor targetDataTypeDescriptor, out string foreignKeyFieldName, string fieldName = null)
        {
            var targetType         = TypeManager.GetType(targetDataTypeDescriptor.TypeManagerTypeName);
            var targetKeyFieldName = targetDataTypeDescriptor.KeyPropertyNames.First();

            var targetKeyDataFieldDescriptor = targetDataTypeDescriptor.Fields[targetKeyFieldName];

            foreignKeyFieldName = fieldName ?? $"{targetDataTypeDescriptor.Name}{targetKeyFieldName}ForeignKey";

            var widgetFunctionProvider = StandardWidgetFunctions.GetDataReferenceWidget(targetType);

            return(new DataFieldDescriptor(Guid.NewGuid(), foreignKeyFieldName, targetKeyDataFieldDescriptor.StoreType, targetKeyDataFieldDescriptor.InstanceType)
            {
                IsNullable = targetKeyDataFieldDescriptor.IsNullable,
                DefaultValue = targetKeyDataFieldDescriptor.DefaultValue,
                ValidationFunctionMarkup = targetKeyDataFieldDescriptor.ValidationFunctionMarkup,
                ForeignKeyReferenceTypeName = targetDataTypeDescriptor.TypeManagerTypeName,
                FormRenderingProfile = new DataFieldFormRenderingProfile
                {
                    Label = foreignKeyFieldName,
                    HelpText = foreignKeyFieldName,
                    WidgetFunctionMarkup = widgetFunctionProvider.SerializedWidgetFunction.ToString(SaveOptions.DisableFormatting)
                }
            });
        }
        internal static IEnumerable <ParameterProfile> BuildInlineXhtmlEditorParameters()
        {
            // TODO: localize
            var templateSelectorWidget = StandardWidgetFunctions.DropDownList(
                typeof(VisualXhtmlEditorFuntion), StaticReflection.GetMethodInfo(() => PageTemplates()).Name, "Key", "Value", false, false);

            yield return(new ParameterProfile(PreviewTemplateIdParameterName,
                                              typeof(Guid), false,
                                              new ConstantValueProvider(Guid.Empty),
                                              templateSelectorWidget,
                                              null,
                                              "Page template for preview",
                                              new HelpDefinition("Page template to be used while generating preview images for the C1 functions calls.")));

            yield return(new ParameterProfile(PreviewPlaceholderParameterName,
                                              typeof(string), false,
                                              new ConstantValueProvider(null), StandardWidgetFunctions.TextBoxWidget, null,
                                              "Page placeholder for preview",
                                              new HelpDefinition("Page placeholder to be used while generating preview images for the C1 functions calls. If not specified, the default placeholder for the selected template will be used.")
                                              ));

            yield return(new ParameterProfile(PreviewPageIdParameterName,
                                              typeof(Guid), false,
                                              new ConstantValueProvider(Guid.Empty),
                                              StandardWidgetFunctions.GetDataReferenceWidget <IPage>(),
                                              null,
                                              "Page for preview",
                                              new HelpDefinition("Page template to be used while generating preview images. Certain fuctions may require page information for previewing.")));
        }