AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 16.11.2017, 10:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,448 / 846 (79) +++++++
Регистрация: 28.10.2006
ievgensaxblog: D365FOE. FormHasMethod extension for form extension methods.
Источник: https://ievgensaxblog.wordpress.com/...nsion-methods/
==============

Recently I have seen multiple people asking how to check if form has method added by extension at run-time.  For form methods we can use Global::formHasMethod but it does not work with form extensions. I advised people to use new metadata API to do this and finally community user Axaptus wrote the code!

I tweaked it a bit to ignore method’s name case as AX does and to exclude private methods. Also I used it to extend standard formHasMethod method

X++:
/// <summary>
/// The class <c>Global_Extension</c> contains extension methods for the <c>Global</c> class.
/// </summary>

[ExtensionOf(classStr(Global))]
public static final class Global_Extension
{
    static boolean formHasMethod(FormRun fr, IdentifierName methodName)
    {
        boolean ret = next formHasMethod(fr, methodName);

        if (!ret)
        {
            ret = Global::formExtensionHasMethod_IM(fr, methodName);
        }

        return ret;
    }

    private static boolean formExtensionHasMethod_IM(FormRun _formRun, IdentifierName _methodName)
    {
        if (!_formRun || !_methodName)
        {
            return false;
        }

        boolean ret = false;

        try
        {
            System.Object[] extensions = Microsoft.Dynamics.Ax.Xpp.ExtensionClassSupport::GetExtensionsOnType(_formRun.GetType(), true);

            if (extensions)
            {
                System.Type    formRunExtensionType;
                System.Reflection.MethodInfo    methodInfo;
var bindingFlags = BindingFlags::Public | BindingFlags::Instance | BindingFlags::Static | BindingFlags::IgnoreCase;
for (int i = 0; i < extensions.Length; i++)
{
                    formRunExtensionType = extensions.GetValue(i);

                    methodInfo = formRunExtensionType.GetMethod(_methodName, bindingFlags);

                    if (methodInfo)
                    {
                        ret = true;
                        break;
                    }
                }
            }
        }
        catch (Exception::CLRError)
        {
            error(CLRInterop::getLastException().ToString());
        }

        return ret;
    }
}
Extending standard method has its pros and cons. From one side it will slow down execution of standard code that calls it when method does not exist, but it’s a rare case. From another side it allows you to reuse standard code without changing it and it could be handy in various places where AX looks for a method on a form.

Source code is available on GitHub




Источник: https://ievgensaxblog.wordpress.com/...nsion-methods/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.

Последний раз редактировалось mazzy; 16.11.2017 в 10:19.
За это сообщение автора поблагодарили: Jorj (1).
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
ievgensaxblog: D365FOE. Issue with enums that have “Use Enum Value” property set to “No”. Blog bot DAX Blogs 0 15.10.2017 11:12
newdynamicsax: Code behind extension forms: How to add state variables and override methods without overlayering Blog bot DAX Blogs 0 12.10.2016 06:25
goshoom: Class extensions Blog bot DAX Blogs 0 18.07.2016 17:11
mfp: X++ in AX7: Extension methods Blog bot DAX Blogs 10 17.12.2015 18:22
axaptapedia: Table Methods Generator Blog bot DAX Blogs 0 13.02.2009 02:05
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 14:31.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.