Reputation: 1746
I'm attempting to do what is shown on the MonoTouch binding page and add some methods to a bound class. It says that all I have to do is include these in a partial class defined in a separate file that is included in the generation process with the -s option. The problem is that the generated class is not a partial class and when I run btouch I get the following errors:
$ /Developer/MonoTouch/usr/bin/btouch -v Node.cs -s:Extensions.cs /Developer/MonoTouch/usr/bin/smcs -unsafe -target:library Node.cs -nowarn:436 -out:/var/folders/cy/g71b7mr91rn4slbpq5cm39140000gn/T/u983s550.k1k/temp.dll -r:/Developer/MonoTouch/usr/lib/btouch/btouch.exe Extensions.cs -r:/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll
Node.cs(7,19): error CS0260: Missing partial modifier on declaration of typeNodeNameSpace.Node'. Another partial declaration of this type exists Extensions.cs(5,30): (Location of the symbol related to previous error) Extensions.cs(5,30): error CS0261: Partial declarations of
NodeNameSpace.Node' must be all classes, all structs or all interfaces Node.cs(7,19): (Location of the symbol related to previous error) Extensions.cs(7,29): error CS0106: The modifierpublic' is not valid for this item Extensions.cs(10,25): error CS0531:
NodeNameSpace.Node.IsExpanded.get': interface members cannot have a definition Extensions.cs(14,25): error CS0531: `NodeNameSpace.Node.IsExpanded.set': interface members cannot have a definition Compilation failed: 5 error(s), 0 warnings btouch: API binding contains errors.
According to the MonoTouch page on binding:
Each class produced by the generator from the API definition file is a partial class
Node.cs
using System;
using MonoTouch.Foundation;
namespace NodeNameSpace
{
[BaseType (typeof (NSObject))]
interface Node
{
[Export ("expanded")]
NSNumber Expanded { get; set; }
}
}
Extensons.cs
using MonoTouch.Foundation;
namespace NodeNameSpace
{
public partial class Node
{
public bool IsExpanded
{
get
{
return Expanded.BoolValue;
}
set
{
Expanded = NSNumber.FromBool(value);
}
}
}
}
Upvotes: 1
Views: 1152
Reputation: 43553
It's a long documentation page, but this should do what you want:
$ /Developer/MonoTouch/usr/bin/btouch Node.cs -x:Extensions.cs
$ ls -l Node.dll
-rwxr-xr-x 1 sebastienpouliot staff 5120 30 Sep 13:30 Node.dll
Your issue was using -s which is used when compiling your interface to a partial class (too early for extensions methods) and to compile the bindings to a .dll.
What you wanted is -x where the source file would only be used for the second compilation (source to .dll). The -s option is most useful for enums since you'll need them in both your interfaces and in the final assembly (.dll).
To get further help do:
/Developer/MonoTouch/usr/bin/btouch --help
Upvotes: 2
Reputation: 1746
Looks like that page is out of date. Doing some more searching I found the this post in the forums.
The correct command to compile my example above is:
/Developer/MonoTouch/usr/bin/btouch -v Node.cs --sourceonly genfiles --outdir=gen
followed by:
/Developer/MonoTouch/usr/bin/smcs -out:Node.dll `cat genfiles` Extensions.cs -r:/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll -target:library
Upvotes: 2