Passing arrays from c# to phalanger dll
3 posts
• Page 1 of 1
Passing arrays from c# to phalanger dll
Hi,
I'm working on a pure php dll that I need to call from c# apps.
The php code is an actual library and I cannot modify it, it has many functions that require array arguments.
Actually I use the PhpArray class to pass these arrays correctly from c# to the dll functions and it works perfectly, I was wondering if there is some method to automatically convert c# arrays or collections to php arrays to shorten the code.
Many thanks
I'm working on a pure php dll that I need to call from c# apps.
The php code is an actual library and I cannot modify it, it has many functions that require array arguments.
Actually I use the PhpArray class to pass these arrays correctly from c# to the dll functions and it works perfectly, I was wondering if there is some method to automatically convert c# arrays or collections to php arrays to shorten the code.
Many thanks
- strfrank
- Posts: 20
- Joined: May 30th, 2012, 5:05 pm
Re: Passing arrays from c# to phalanger dll
Hi,
I agree PhpArray is not always easy to create, as it has many additional array features.
For you the easiest ways would be to wrap System.Array or ICollection into PhpArray:
You can make an extension method to ICollection or IDictionary, that would create PhpArray from it:
Or write an explicit cast operator.
Also in most cases (tested for [] operator), Phalanger handles objects derived from IList and IDictionary directly, so you don't have to create PhpArray at all.
I agree PhpArray is not always easy to create, as it has many additional array features.
For you the easiest ways would be to wrap System.Array or ICollection into PhpArray:
- Code: Select all
new PhpArray(collection)
You can make an extension method to ICollection or IDictionary, that would create PhpArray from it:
- Code: Select all
public static PhpArray ToPhpArray(this IDictionary dict){ ... }
Or write an explicit cast operator.
Also in most cases (tested for [] operator), Phalanger handles objects derived from IList and IDictionary directly, so you don't have to create PhpArray at all.
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: Passing arrays from c# to phalanger dll
Hi,
Thanks for the answer, I'll rely on phparray, maybe I can write an adapter that accepts standard collections and converts them to PhpArray.
The problem with passing .net collections or arrays is that when the php code tries to add elements to the collections I get an exception.
Thanks
Thanks for the answer, I'll rely on phparray, maybe I can write an adapter that accepts standard collections and converts them to PhpArray.
The problem with passing .net collections or arrays is that when the php code tries to add elements to the collections I get an exception.
Thanks
- strfrank
- Posts: 20
- Joined: May 30th, 2012, 5:05 pm
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 39 guests