[Mono-dev] Embedded API: delegate type building

Jonathan Mitchell lists at mugginsoft.com
Fri Mar 4 13:44:45 UTC 2016


Hi

At present I use an InternalCalls for my callbacks and conditional compilation (see end) in our cross platform code
In this we assign  a Func<string, string> directly to an extern static string FilePathCallback(string EmployerName);

 In future I would like to support calling methods such as

public CloudClient(Func<string, string> filePathCallback) 

using the Embedded API and cut out the extra plumbing need for InternalCalls.

I have a wooly feel for how I should approach this!
When generating generic types I use a managed helper method.

So I could envisage creating a System.Delegate instance of System.Func<string, string>.
Then I could set the Target and Method properties - however since I am calling back into C there won’t be a Target class.
However System.Delegate is abstract so I would need to sort that out too! - presumably this needs to be done dynamically at runtime.

I am aware of the existence of Delegate.CreateDelegate() put that only seems to work for instance delegates.

Any insight would be helpful.

Thanks

Jonathan

end
===
public class CloudClient
{
#if TARGET_OSX
		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern static string FilePathCallback(string EmployerName);
#endif
		public CloudClient(Func<string, string> filePathCallback) {

			_filePathCallback = filePathCallback;

#if TARGET_OSX
			if (_filePathCallback == null) {
				_filePathCallback = FilePathCallback;
			}
#endif
		}

}







More information about the Mono-devel-list mailing list