spacer
cornerspacercorner
Reply
Frequent Advisor
Paul York
Posts: 64
Registered: 05-22-2010
0 Kudos
Accepted Solution

Assigning to Metastorm.Runtime.Types.List variable?

[ Edited ]

Hi,

 

After promoting some methods from an imported dll to the expression wizard ( I have to say I really like this feature btw!) I'd like a drop down field to be based upon the  results a call to one of these methods.  I've noticed the input type for the drop down box is of type Metastorm.Runtime.Types.List but is there an easy way to assign to variables of this type?

 

I've tried creating a standard generic List and trying to assign this but this fails with for an implicit or explicit assignment. ( to be honest I thought it may but I can't find any documentation about the runtime types - are we actually supposed to be using these?)

 

I suspect I can iterate over the returned List and then assign each item one by one but I was hoping for something a little simpler?

 

Thanks,

 

Paul.

 

 

 

 

Employee
Ethan Beisher
Posts: 378
Registered: 05-10-2010
0 Kudos

Re: Assigning to Metastorm.Runtime.Types.List variable?

I've attached an example below. Hopefully it answers your question. (Note that is for v9, SR2, Hotfix 2).

 

Ethan

Ethan Beisher
Solutions Engineer
Business Process Solutions
Frequent Advisor
Paul York
Posts: 64
Registered: 05-22-2010
0 Kudos

Re: Assigning to Metastorm.Runtime.Types.List variable?

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.

Employee
Ethan Beisher
Posts: 378
Registered: 05-10-2010
0 Kudos

Re: Assigning to Metastorm.Runtime.Types.List variable?

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.

 

Ethan Beisher
Solutions Engineer
Business Process Solutions
Frequent Advisor
Carolyn
Posts: 65
Registered: 06-30-2010

Re: Assigning to Metastorm.Runtime.Types.List variable?

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.

Employee
Ethan Beisher
Posts: 378
Registered: 05-10-2010
0 Kudos

Re: Assigning to Metastorm.Runtime.Types.List variable?

I admit I'm not that advanced with C#. I did find this page for converting Lists to arrays which may be helpful.

Ethan Beisher
Solutions Engineer
Business Process Solutions
Frequent Advisor
Carolyn
Posts: 65
Registered: 06-30-2010
0 Kudos

Re: Assigning to Metastorm.Runtime.Types.List variable?

Yeah. Trust me, I wouldn't have done it this way unless I'd tried everything else first.

Frequent Advisor
Paul York
Posts: 64
Registered: 05-22-2010
0 Kudos

Re: Assigning to Metastorm.Runtime.Types.List variable?

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.

line spacer line
spacerFollow Metastorm on:
spacer Twitter YouTube Blog iTunes LinkedIn Metastorm Community Central, MC2
spacer Copyright © 2011 OpenText Corporation. All Rights Reserved.spacer About Metastormspacer Privacyspacer Legalspacer Site Mapspacer RSSspacer Contact Us
Microsoft Gold Certified Partner
Powered by Windows Azure
line spacer line