16.11.2017, 10:11 | #1 |
Участник
|
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; } } Source code is available on GitHub Источник: https://ievgensaxblog.wordpress.com/...nsion-methods/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. Последний раз редактировалось mazzy; 16.11.2017 в 10:19. |
|
|
За это сообщение автора поблагодарили: Jorj (1). |
|
|