First Eiffel .NET Program
Sunday 29 September 2002
I've downloaded and installed Eiffel Envision, the Eiffel plug-in for Visual Studio. I'm planning to write a review of Envision but the first thing I attempted was to implement an XML-RPC client. I had to seek help on how to specify custom attributes but otherwise it was fairly straightforward.
indexing
attribute: create {XML_RPC_METHOD_ATTRIBUTE}.make
end
class MATH_PROXY inherit XML_RPC_CLIENT_PROTOCOL
feature
Add(a : INTEGER b : INTEGER) : INTEGER is
indexing
attribute:
create {XML_RPC_METHOD_ATTRIBUTE}.make_from_method(
("math.Add").to_cil)
end
local
args : NATIVE_ARRAY[SYSTEM_OBJECT]
ret : INTEGER
do
!!args.make(2)
args.put(0, a)
args.put(1, b)
Result ?= Invoke(("Add").to_cil, args)
end
end -- class MATH_PROXY
The custom attributes are specified in the indexing clauses of the class and the Add feature
attribute: create {XML_RPC_METHOD_ATTRIBUTE}.make
and
attribute:
create {XML_RPC_METHOD_ATTRIBUTE}.make_from_method(
("math.Add").to_cil)
There are some points worth noting here. First, when referring to classes in other assemblies, the name is automatically changed from typical .NET style, e.g. XmlRpcMethodAttribute, to the Eiffel style XML_RPC_METHOD_ATTRIBUTE.
Second, Eiffel does not support overloaded methods and so the XmlRpcMethodAttribute constructor taking a string parameter is renamed as "make_from_method", with the default constructor named "make".
Third, because Eiffel has its own rich framework class library, a straightforward string literal cannot be used in the XmlRpcMethodAttribute constructor: this would specify an instance of the Eiffel String class. Instead the ugly construction ("math.Add").to_cil has to be used (although the online help states that this will be unnecessary in a future release because the type of string will be determined from the context of the literal).