public static void AppendComplexType <T, TProperty>(RenderTreeBuilder pBuilder, IMPropertyInfo pPropertyInfo, T pModel, Guid pId, IMForm pParent, MComplexPropertyField <T, TProperty> pComplexField,
                                                            MFormGridContext pGridContext)
        {
            if (pComplexField.Template == null)
            {
                ShowNotSupportedType(pBuilder, pPropertyInfo, pModel, pId, pParent);
                return;
            }

            MComplexPropertyFieldContext <TProperty> context = new MComplexPropertyFieldContext <TProperty>();

            TProperty value = (TProperty)pPropertyInfo.GetValue(pModel);

#pragma warning disable BL0005 // Component parameter should not be set outside of its component.
            context.Row              = pModel;
            context.InputId          = pId;
            context.Value            = value;
            context.MFormGridContext = pGridContext;

            context.ValueChanged = RuntimeHelpers.CreateInferredEventCallback <TProperty>(pParent, async __value =>
            {
                pPropertyInfo.SetValue(pModel, __value);
                await pParent.OnInputValueChanged(pComplexField, pPropertyInfo, __value);
            }, value);

            context.ValueExpression = GetValueExpression <TProperty>(pPropertyInfo, pModel);

#pragma warning restore BL0005 // Component parameter should not be set outside of its component.

            pBuilder.AddContent(42, pComplexField.Template?.Invoke(context));
        }
Esempio n. 2
0
        public static void AppendComplexType <T, TProperty>(RenderTreeBuilder pBuilder, IMPropertyInfo pPropertyInfo, T pModel, Guid pId, IMForm pParent, MComplexPropertyField <TProperty> pComplexField,
                                                            MFormGridContext pGridContext)
        {
            if (pComplexField.Template == null)
            {
                ShowNotSupportedType(pBuilder, pPropertyInfo, pModel, pId);
                return;
            }

            TProperty value = (TProperty)pPropertyInfo.GetValue(pModel);

            var context = new MComplexPropertyFieldContext <TProperty>
            {
                Row              = pModel,
                InputId          = pId.ToString(),
                FormId           = pParent.Id.ToString(),
                Form             = pParent,
                Value            = value,
                MFormGridContext = pGridContext,

                ValueChanged = RuntimeHelpers.CreateInferredEventCallback <TProperty>(pParent, async __value =>
                {
                    pPropertyInfo.SetValue(pModel, __value);
                    await pParent.OnInputValueChanged(pComplexField, pPropertyInfo, __value);
                }, value),

                ValueExpression = GetValueExpression <TProperty>(pPropertyInfo, pModel)
            };

            pBuilder.AddContent(263, pComplexField.Template?.Invoke(context));

            if (pParent.EnableValidation)
            {
                pBuilder.OpenComponent <ValidationMessage <TProperty> >(236);
                pBuilder.AddAttribute(237, "For", context.ValueExpression);
                pBuilder.CloseComponent();
            }
        }