现在的位置: 首页 > 综合 > 正文

ObjectSpace中说明文档的不足!

2012年09月18日 ⁄ 综合 ⁄ 共 2212字 ⁄ 字号 评论关闭

 

using System;
using Microsoft.ObjectSpaces;


//
// ObjectSpaces object 'Customer'.
//

public abstract class Customer 
{
    [UniqueId] 
public abstract string Id getset; }

    
public abstract string Name getset; }
    
public abstract string CompanyName getset; }
    
public abstract string Phone getset; }
    
public abstract string Fax getset; }

    
public void OnCreate(string newId) 
    
{
         Id 
= newId;
    }


}



//
// ObjectSpaces Tutorial #1
//

public class Example2 
{

    
public static void Main() 
    
{

       
try  
       
{

    
//
    
// Load in the Source.xml file (specifies the XmlObjectSpace to load in).
    
//

    IObjectSpace os 
= ObjectSpaceFactory.CreateObjectSpace("Source.xml");


    
//
    
// Create two new customers.
    
//

          Customer myCustomer 
= (Customer) os.CreateObject( typeof(Customer), "1" );
          myCustomer.Name 
= "Mario Esprito";
          myCustomer.CompanyName 
= "Infoltrix";
          myCustomer.Phone 
= "(111) 345 6777";
          myCustomer.Fax 
= "(222) 343 6744";

          myCustomer 
= (Customer) os.CreateObject( typeof(Customer), "2" );
          myCustomer.Name 
= "Frank Antuono";
          myCustomer.CompanyName 
= "Infoltrix";
          myCustomer.Phone 
= "(333) 345 6737";
          myCustomer.Fax 
= "(444) 343 6244";


    
//
    
// Once you have specified values for the fields, commit the changes to
    
// the underlying object storage.
    
//
    
          os.UpdateAll();


    
//
    
// Iterate through the newly created objects in the ObjectSpace and 
    
// print out object properties.
    
//

          
foreach(Customer theCustomer in os.GetObjects(typeof(Customer), "")) 
          
{
              Console.WriteLine(
" Customer Id: " + theCustomer.Id + 
                                
" Customer Name: " + theCustomer.Name + 
                                
" Company: " + theCustomer.CompanyName + 
                                
" Phone: " + theCustomer.Phone + 
                                
" Fax: " + theCustomer.Fax + " " );

          }


     }



  
//
  
// Catch any exceptions that might occur.
  
//

  
catch (Exception e) 
  
{
    Console.Write(e);
  }


   }

    
}

其中 Customer myCustomer = (Customer) os.CreateObject( typeof(Customer), "1" );
感觉文档中说得不太清楚!VS2003的ObjectSpace文档感觉写得太烂,很多细节都忽略了!

抱歉!评论已关闭.