Attribute - Using IDL Attributes

Description:

CORBA IDL attributes may be mapped straight forward into standard .NET attributes. (In contrast, the OMG IDL-to-Java mapping maps IDL attributes into instance variables with explicit setter & getter methods.)

Source:

\Demo\Attribute

Mapping:

CORBA IDL Attributes <---> .NET Attributes


Example

Step 1. The IDL (Attribute.idl):

     module Attribute
    {
        interface Greetings
        {
            attribute string Name;
            
            readonly attribute string City;   
            
            string hello();
        };
    };

(Will be compiled into Attribute.cs)

Step 2. The Implementation (AttriSrv.cs):

    public class Greetings : GreetingsPOA
    {
        private string m_strCity;
        private string m_strName;
        
        public Greetings()
        {
            m_strCity = "Hamburg";
        }
        
        public override string Name
        {
            set
            {
                m_strName = value;
            }
            get
            {
                return m_strName;
            }
        }
        
        public override string City
        {
            get
            { 
                return m_strCity;
            }
        }
        
        public override string hello()
        {
            return "Greetings to " + m_strName;  
        }
    }	

Step 3. The Client (AttriClt.cs):

Write an attribute to the server:

     m_oIGreetings.Name = "John";  

Read an attribute from the server:

     string strTheCity = m_oIGreetings.City;  

Call a server method (reading a changed attribute):

     System.Console.WriteLine("'{0}' from '{1}'", m_oIGreetings.hello(), strTheCity);  

Step 4. Run the example

a.) Start the Server.

b.) Start the Client.