Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/generator-enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,21 @@ void GenerateEnum (Type type)
var fa = kvp.Value;
// the attributes (availability and field) are important for our tests
PrintPlatformAttributes (f);
var libname = fa.LibraryName ?? library_name;
print ("[Field (\"{0}\", \"{1}\")]", fa.SymbolName, libname);
libraries.TryGetValue (library_name, out var libPath);
var libname = fa.LibraryName?.Replace ("+", string.Empty);
// We need to check for special cases inside FieldAttributes
// fa.LibraryName could contain a different framework i.e UITrackingRunLoopMode (UIKit) inside NSRunLoopMode enum (Foundation).
// libPath could have a custom path i.e. CoreImage which in macOS is inside Quartz
// library_name contains the Framework constant name the Field is inside of, used as fallback.
bool useFieldAttrLibName = libname != null && !string.Equals (libname, library_name, StringComparison.OrdinalIgnoreCase);
print ("[Field (\"{0}\", \"{1}\")]", fa.SymbolName, useFieldAttrLibName ? libname : libPath ?? library_name);
print ("internal unsafe static IntPtr {0} {{", fa.SymbolName);
indent++;
print ("get {");
indent++;
print ("fixed (IntPtr *storage = &values [{0}])", n++);
indent++;
print ("return Dlfcn.CachePointer (Libraries.{0}.Handle, \"{1}\", storage);", libname, fa.SymbolName);
print ("return Dlfcn.CachePointer (Libraries.{0}.Handle, \"{1}\", storage);", useFieldAttrLibName ? libname : library_name, fa.SymbolName);
indent--;
indent--;
print ("}");
Expand Down
10 changes: 9 additions & 1 deletion tests/generator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ else
IOS_GENERATOR = $(IOS_CURRENT_DIR)/bin/btouch-native /baselib:$(IOS_CURRENT_DIR)/lib/mono/Xamarin.iOS/Xamarin.iOS.dll /unsafe
endif
IOS_TESTS = bug15283 bug15307 bug15799 bug16036 sof20696157 bug23041 bug27430 bug27428 bug34042 btouch-with-hyphen-in-name property-redefination-ios arrayfromhandlebug bug36457 bug39614 bug40282 bug17232 bug24078-ignore-methods-events strong-dict-support-templated-dicts bug43579 bindastests
IOS_CUSTOM_TESTS = forum54078 desk63279 desk79124 multiple-api-definitions1 multiple-api-definitions2 bug29493 classNameCollision bi1036 bug37527 bug27986 bug35176 bi1046 bindas1048error bindas1049error bindas1050modelerror bindas1050protocolerror virtualwrap bug42855 bug52570classinternal bug52570methodinternal bug52570allowstaticmembers bug42742 warnaserror nowarn noasyncinternalwrapper noasyncwarningcs0219 bug53076 bug53076withmodel bug57070 fieldenumtests
IOS_CUSTOM_TESTS = forum54078 desk63279 desk79124 multiple-api-definitions1 multiple-api-definitions2 bug29493 classNameCollision bi1036 bug37527 bug27986 bug35176 bi1046 bindas1048error bindas1049error bindas1050modelerror bindas1050protocolerror virtualwrap bug42855 bug52570classinternal bug52570methodinternal bug52570allowstaticmembers bug42742 warnaserror nowarn noasyncinternalwrapper noasyncwarningcs0219 bug53076 bug53076withmodel bug57070 fieldenumtests smartenumwithframework

MAC_CURRENT_DIR=$(MAC_DESTDIR)/Library/Frameworks/Xamarin.Mac.framework/Versions/Current
ifdef IKVM
Expand Down Expand Up @@ -278,6 +278,14 @@ fieldenumtests:
@mkdir -p $@.tmpdir
$(if $(V),,@echo "$@";) $(IOS_GENERATOR) --sourceonly:$@.source -tmpdir=$@.tmpdir $@.cs --process-enums

smartenumwithframework:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a unit test project for the generator now 😄

@rm -Rf $@.tmpdir
@mkdir -p $@.tmpdir
$(if $(V),,@echo "$@";) $(IOS_GENERATOR) --sourceonly:$@.source -tmpdir=$@.tmpdir $@.cs --process-enums
@if [ `grep -r "Libraries.CoreImage.Handle" $@.tmpdir/SmartEnumWithFramework | wc -l` -ne 2 ]; then \
echo "Error: Expected 2 'Libraries.CoreImage.Handle'."; exit 1; \
fi

clean-local::
rm -f *.dll *.source
rm -Rf *.tmpdir
14 changes: 14 additions & 0 deletions tests/generator/smartenumwithframework.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using ObjCRuntime;
using Foundation;

namespace SmartEnumWithFramework {

enum FooEnumTest {
[Field ("First", "+CoreImage")]
First,

[Field ("Second", "+CoreImage")]
Second,
}
}