![]() | ![]() |
|
10-25-2010 08:03 AM - last edited on 10-25-2010 08:03 AM
Hi,
Solved! Go to Solution.
10-25-2010 08:15 AM
I've attached an example below. Hopefully it answers your question. (Note that is for v9, SR2, Hotfix 2).
Ethan
10-25-2010 08:39 AM
Hi,
Thanks for the super fast reply however it doesn't quite get to where I need.
Your solution included the two lines below however this assumes that you are instantiating the List object internally within the IDE and therefore know the values you wish to add.
Metastorm.Runtime.Types.List myList = new List("Item 1", "Item 2");
return myList;
What I'm trying to achieve is to assign to an List object from an externally created dll. The dll currently doesn't have any reference to any of the Metastorm libraries so it doesn't know anything of the specialised metastorm structures (however we can add these if you recomend this approach)
Our application returns certain options that we would like to surface in option based fields and we'd like to keep this list centrally managed wthin our app code base. Ideally I was hoping something like the following would be possible:
Metastorm.Runtime.Types.List myList = new List(); myList = (List)ExternalComponent.GetTestTypeOptions(); return myList;
or possibly ....
Metastorm.Runtime.Types.List myList = new List(); myList.LoadGenericList(ExternalComponent.GetTestTypeOptions()); return myList;
Is there any way to achieve something similar to what's above, or do we need to iterate our returned collection and append each item?
Many thanks,
Paul.
10-25-2010 09:17 AM
You don't name the return type of your method.
The default constructor for the Metastorm Lists is "array" (the Intellisense give you a hint). If you can convert your returned type to an array of strings, you should be able to do what I think you are asking:
string[] names = new string[3] {"Matt", "Joanne", "Robert"};
Metastorm.Runtime.Types.List myList = new List(names);
return myList;
See the Microsoft page on arrays for more information.
10-25-2010 09:35 AM
I tried this. To turn a generic list into something a metastorm list box can use, you have to turn it into a list of KeyValuePairs, and then into an array, and then into a Metastorm List. It's a lovely process...
I've attached a small extract of code to show you. I'm not sure whether it works all the way through though, as I was using nHibernate to generate the original list and NHibernate and Metastorm didn't get on too well, so I gave up after a while. But if you're not using nHibernate, in principle it ought to work. Let us all know, cos there are lots of us wanting to do this.
10-25-2010 09:41 AM
I admit I'm not that advanced with C#. I did find this page for converting Lists to arrays which may be helpful.
10-25-2010 10:08 AM
Yeah. Trust me, I wouldn't have done it this way unless I'd tried everything else first.
10-25-2010 10:30 AM
Thanks Carolyn,
I must admit I'm not that familiar with Linq but I think I understand how you've structured your solution and it's allowed me to get a fix to what I needed.
My library function which used to return list now returns an object array containing KeyValuePair<string,string> objects. This seems to work and allows a list to be created using the constructor.
[Category("ApplicationName")]
[Alias("List all types")]
public static List GetTestTypeList
{
get
{
return (new List(App.GetTestValueDescriptorPairs()));
}
}
I'm now going to have a look at the linq syntax so I fully understand the class extensions as your sample looked like a much better generic solution for the standard Microsoft List types
Cheers,
Paul.
![]() |
![]() |
![]() |
|
|
![]() |
![]() |
![]() |
















