AXForum  
Go Back   AXForum > Microsoft Dynamics AX > DAX: Программирование
All
Forgotten Your Password?
Register Forum Rules FAQ Members List Today's Posts Search Mark Forums Read

 
 
Thread Tools Search this Thread Display Modes
Old 27.10.2013, 23:15   #1  
b_nosoff is offline
b_nosoff
Читатель
b_nosoff's Avatar
MCP
MCBMSS
 
197 / 143 (5) +++++
Join Date: 01.12.2004
Location: Msk
Blog Entries: 13
Quote:
Originally Posted by Cardagant View Post
Но если я получаю данный объект (System.Collections.Generic.IEnumerable`1) как результат работы функции, которая содержится в объекте сборки, то не могу считать через Reflection её энумератор.
Можете:

X++:
    type = myIntList.GetType();

    propertyCount = type.GetProperty("Count");
    
    nil = new System.Object[0]();
    
    cnt = propertyCount.GetValue(myIntList, nil);
    
    info(strFmt("%1", cnt));
__________________
Axapta non erubescit
This post has been rated by: Cardagant (1).
Old 28.10.2013, 13:12   #2  
Cardagant is offline
Cardagant
Участник
 
317 / 54 (2) ++++
Join Date: 11.10.2011
Спасибо за ответ! Но всё равно не выходит.

Попробую привести ситуацию подробнее

TMSoft.Gohub.Client.GohubConnection - Класс сборки, реализующий подключение к сторонней БД

TMSoft.Gohub.Client.GohubDocument - Класс сборки, реализующий объекты, коллекцию которых требуется получить.

X++:
System.Type                         enumerable;
System.Type                         enumerator;
System.Object                       CLRenumerable;
System.Object                       CLRenumerator;
System.Reflection.MethodInfo        methodInfo;
;

// Создаётся некоторое подключение
con = new TMSoft.Gohub.Client.GohubConnection(someparams);

// Получить коллекцию всех документов
// Описание функции говорит, что возвратит System.Collections.Generic.IEnumerable`1[TMSoft.Gohub.Client.GohubDocument]
CLRenumerable = con.QueryDocuments(0);

// Получить тип
enumerable = CLRenumerable.GetType();

info(enumerable.get_Name()); // <_QueryDocuments>d__0
info(enumerable.get_FullName()); // TMSoft.Gohub.Client.GohubConnection+<_QueryDocuments>d__0
info(enumerable.get_AssemblyQualifiedName()); // TMSoft.Gohub.Client.GohubConnection+<_QueryDocuments>d__0, TMSoft.Gohub.Client.Net, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

if (CLRInterop::isNull(enumerable)) // false
     throw error("null");

methodInfo = enumerable.GetMethod("GetEnumerator");

if (CLRInterop::isNull(methodInfo)) // true
     throw error("null"); 

CLRenumerator   = methodInfo1.Invoke(enumerable, nil);

Last edited by Cardagant; 28.10.2013 at 13:18.
Old 28.10.2013, 13:51   #3  
b_nosoff is offline
b_nosoff
Читатель
b_nosoff's Avatar
MCP
MCBMSS
 
197 / 143 (5) +++++
Join Date: 01.12.2004
Location: Msk
Blog Entries: 13
Quote:
Originally Posted by Cardagant View Post
X++:
CLRenumerator   = methodInfo1.Invoke(enumerable, nil);
Может все же
X++:
CLRenumerator   = methodInfo.Invoke(CLRenumerable, nil);
А CLRInterop::isNull ошибается порой, известная тема...
__________________
Axapta non erubescit

Last edited by b_nosoff; 28.10.2013 at 15:16.
Old 28.10.2013, 14:23   #4  
Cardagant is offline
Cardagant
Участник
 
317 / 54 (2) ++++
Join Date: 11.10.2011
Quote:
Originally Posted by b_nosoff View Post
Может все же
X++:
CLRenumerator   = methodInfo1.Invoke(CLRenumerable, nil);
Моя ошибка, Вы правы!

Quote:
Originally Posted by b_nosoff View Post
А CLRInterop::isNull ошибается порой, известная тема...
Закоментировал проверку на Нулл, получаю ошибку на строке
X++:
CLRenumerator   = methodInfo.Invoke(CLRenumerable, nil);
Объект не инициализирован.

Last edited by Cardagant; 28.10.2013 at 14:25.
Old 28.10.2013, 15:28   #5  
b_nosoff is offline
b_nosoff
Читатель
b_nosoff's Avatar
MCP
MCBMSS
 
197 / 143 (5) +++++
Join Date: 01.12.2004
Location: Msk
Blog Entries: 13
Quote:
Originally Posted by Cardagant View Post
Объект не инициализирован.
Попробуйте так:
X++:
enumerable = System.Type::GetType("System.Collections.IEnumerable");
чисто в порядке эксперимента
__________________
Axapta non erubescit
Old 28.10.2013, 17:24   #6  
Cardagant is offline
Cardagant
Участник
 
317 / 54 (2) ++++
Join Date: 11.10.2011
Благодарю Вас, b_nosoff
Вы мне очень помогли.

Привожу код рабочего метода, в котором получаю XML-текст первого документа.
Мне нужен цикл, его, естественно, доделаю.

Очень благодарен всем, кто помог!

docum - это класс документа, определённый в сборке (TMSoft.Gohub.Client.GohubDocument)

X++:
con = new TMSoft.Gohub.Client.GohubConnection("localhost", 20295);

CLRenumerable = con.QueryDocuments(0);
// Получить тип
//enumerable = CLRenumerable.GetType();
enumerable = System.Type::GetType("System.Collections.IEnumerable");

if (CLRInterop::isNull(enumerable)) // false
     throw error("null");

methodInfo = enumerable.GetMethod("GetEnumerator");

/*if (CLRInterop::isNull(methodInfo)) // true
     throw error("null");*/

CLRenumerator   = methodInfo.Invoke(CLRenumerable, nil);

if (CLRInterop::isNull(CLRenumerator))
     throw error("null");

enumerator  = System.Type::GetType("System.Collections.IEnumerator");

methodInfo = enumerator.GetMethod("MoveNext");

// Переход к первому элементу
b = methodInfo.Invoke(CLRenumerator, nil);
// считывание текущего элемента
if (b)
{
       // Сичтываю свойство с текущим документом
       ParameterInfo = enumerator.GetProperty("Current");
       // Получение текущего элемента
       docum = ParameterInfo.GetValue(CLRenumerator, nil);
       // ПОлучение документа в формате XML
       info(docum.GetXmlText());
}

Last edited by Cardagant; 28.10.2013 at 17:40.
This post has been rated by: Logger (5), MazZzDaI (1).
Tags
.net, generic

 

Similar Threads
Thread Thread Starter Forum Replies Last Post
ssmantha: Debugging .NET code called from X++ code in AX 2012 Blog bot DAX Blogs 1 11.11.2011 15:50
emeadaxsupport: When browsing AX 2009 Role Centers, you get an error: An unexpected error has occurred on systems with .NET Framework v4.0 installed Blog bot DAX Blogs 1 28.07.2010 08:24
AX.NET: интеграция .NET-приложений с Аксаптой и (будущие) возможности облачных вычислений gl00mie DAX: Программирование 2 23.04.2010 00:47
jinx: Microsoft Dynamics AX und .NET - Erstellen eines Termins in Outlook Blog bot DAX auf Deutsch 0 03.11.2007 00:33
Inside Dynamics AX 4.0: Working with the .NET Business Connector Blog bot DAX Blogs 0 04.10.2007 05:15
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Рейтинг@Mail.ru
All times are GMT +3. The time now is 04:27.
Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Contacts E-mail, Advertising.