Пример #1
0
        public void Generate(CodeGenerationOptions opt, GenerationInfo gen_info)
        {
            using (var sw = gen_info.OpenStream(opt.GetFileName("__NamespaceMapping__"))) {
                sw.WriteLine("using System;");
                sw.WriteLine();

                foreach (var p in mappings)
                {
                    sw.WriteLine("[assembly:global::Android.Runtime.NamespaceMapping (Java = \"{0}\", Managed=\"{1}\")]",
                                 p.Key, p.Value);
                }

                sw.WriteLine();

                // delegate bool _JniMarshal_PPL_Z (IntPtr jnienv, IntPtr klass, IntPtr a);
                foreach (var jni in opt.GetJniMarshalDelegates())
                {
                    sw.WriteLine($"delegate {FromJniType (jni[jni.Length - 1])} {jni} (IntPtr jnienv, IntPtr klass{GetDelegateParameters (jni)});");
                }
            }
        }
Пример #2
0
        public void Generate(CodeGenerationOptions opt, GenerationInfo gen_info)
        {
            using (var sw = gen_info.OpenStream(opt.GetFileName("__NamespaceMapping__"))) {
                sw.WriteLine("using System;");
                sw.WriteLine();

                if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1)
                {
                    foreach (var p in mappings)
                    {
                        sw.WriteLine($"[assembly:global::Android.Runtime.NamespaceMapping (Java = \"{p.Key}\", Managed=\"{p.Value}\")]");
                    }
                    sw.WriteLine();
                }

                // delegate bool _JniMarshal_PPL_Z (IntPtr jnienv, IntPtr klass, IntPtr a);
                foreach (var jni in opt.GetJniMarshalDelegates())
                {
                    sw.WriteLine($"delegate {FromJniType (jni[jni.Length - 1])} {jni} (IntPtr jnienv, IntPtr klass{GetDelegateParameters (jni)});");
                }

                // [SupportedOSPlatform] only exists in .NET 5.0+, so we need to generate a
                // dummy one so earlier frameworks can compile.
                if (opt.CodeGenerationTarget == Xamarin.Android.Binder.CodeGenerationTarget.XAJavaInterop1)
                {
                    sw.WriteLine("#if !NET");
                    sw.WriteLine("namespace System.Runtime.Versioning {");
                    sw.WriteLine("    [System.Diagnostics.Conditional(\"NEVER\")]");
                    sw.WriteLine("    [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Event | AttributeTargets.Method | AttributeTargets.Module | AttributeTargets.Property | AttributeTargets.Struct, AllowMultiple = true, Inherited = false)]");
                    sw.WriteLine("    internal sealed class SupportedOSPlatformAttribute : Attribute {");
                    sw.WriteLine("        public SupportedOSPlatformAttribute (string platformName) { }");
                    sw.WriteLine("    }");
                    sw.WriteLine("}");
                    sw.WriteLine("#endif");
                    sw.WriteLine("");
                }
            }
        }