GetProperty pour obtenir une collection à partir d'un COM
Bonjour à tous,
J'ai un problème avec un GetProperty pour obtenir avec une collection à partir d'un objet COM.
Voici le code VBA que je dois migrer en C# :
(Ce code permet de supprimer une molécule du visualisateur 3D de molécules)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
lig = molname + "_lig"
For Each mol In mdl.Molecules
If mol.name = molname Then
Call mol.delete
End If
Next
For Each mol In mdl.Molecules
If mol.name = lig Then
Call mol.delete
End If
next
Call mdl.Views(1).UpdateChanges |
J'ai essayé avec ce code C# :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
//Init the global values for the B3D display
Lithium.Application App = new Lithium.Application();
App.Visible = true;
TRIPOS_WEB_SCRIPTING_Lib.DynamicEventSink snk = new TRIPOS_WEB_SCRIPTING_Lib.DynamicEventSink();
object mdl = App.ActiveModel;
Type t = mdl.GetType();
PropertyInfo prop = t.GetProperty("Molecules");
foreach (object molTmp in prop)
{
} |
mais il me plante sur :
foreach (object molTmp in prop)
avec l'erreur :
CS1579: l'instruction foreach ne peut pas fonctionner sur des variables de type 'System.Reflection.PropertyInfo', car 'System.Reflection.PropertyInfo' ne contient pas de définition public pour 'GetEnumerator'
Voici un code qui marche bien avec les même objets COM : cela affiche une molécule dans le visualisateur 3D de molécules.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView2.Rows[index];
string strCurrentPdb = Server.HtmlDecode(row.Cells[2].Text);
//Init the global values for the B3D display
Lithium.Application App = new Lithium.Application();
App.Visible = true;
TRIPOS_WEB_SCRIPTING_Lib.DynamicEventSink snk = new TRIPOS_WEB_SCRIPTING_Lib.DynamicEventSink();
object mdl = App.ActiveModel;
Type t = mdl.GetType(); MethodInfo method = t.GetMethod("ImportFile");
if (method != null)
{
method.Invoke(mdl, new object[] { strCurrentPdb, 0 });
} |
Merci beaucoup pour vos réponses.
Laurent.