php 傳送物件陣列至 .net COM

  • 380
  • 0

摘要:php 傳送物件陣列至 .net COM

C#


namespace SampleCOM
{
    public interface ISample
    {
        Data[] GetAll();
        Saves(object[] list); 
    }
    public class Sample : ServicedComponent, ISample
    {
        private Data[] _data;

        public Data[] GetAll()
        {
            if (_data == null)
                _data = new Manager().GetAll().ToArray();
            return _data;
        }

        public void Saves(object[] list)
        {
            var temp = new Data[list.Length];
            Array.Copy(list, temp, list.Length);
            _data = temp;
        }
    }
}

 

PHP


<?php
$obj = new COM("SampleCOM.Sample", null, 65001) or die("Unable Initialize COM");
$result = $obj->GetAll();
$i=0;
foreach($result as $item)
{
    $i++;
    echo $i."=>".$item->name;
    if($i>9)
        break;
}
$new = array($result[1],$result[3],$result[5],$result[7]);
$obj->Save($new);
$result = $obj->GetAll();
$i=0; 
foreach($result as $item) { 
    $i++; 
    echo $i."=>".$item->name;
}
$obj=null; 
?>