public static ImportedReferences Create(ModuleDefinition module)
        {
            var targetFramework = module.Assembly.CustomAttributes.Single(a => a.AttributeType.FullName == typeof(TargetFrameworkAttribute).FullName);

            ImportedReferences references;

            var frameworkName = new FrameworkName((string)targetFramework.ConstructorArguments.Single().Value);

            switch (frameworkName.Identifier)
            {
            case ".NETFramework":
            case "Xamarin.iOS":
            case "MonoAndroid":
            case "Xamarin.Mac":
                references = new NETFramework(module);
                break;

            case ".NETStandard":
            case ".NETPortable":
            case ".NETCore":
            case ".NETCoreApp":
                references = new NETPortable(module);
                break;

            default:
                throw new Exception($"Unsupported target framework: {frameworkName}");
            }

            references.InitializeFrameworkMethods();

            // Weaver may be run on an assembly which is not **yet** using Realm, if someone just adds nuget and builds.
            var realmAssembly = module.AssemblyReferences.SingleOrDefault(r => r.Name == "Realm");

            if (realmAssembly != null)
            {
                references.InitializeRealm(realmAssembly);

                switch (frameworkName.Identifier)
                {
                case "Xamarin.iOS":
                case "MonoAndroid":
                case ".NETStandard":
                case ".NETPortable":
                case "Xamarin.Mac":
                    var dataBindingAssembly = module.AssemblyReferences.SingleOrDefault(r => r.Name == "Realm.DataBinding");
                    if (dataBindingAssembly == null)
                    {
                        dataBindingAssembly = new AssemblyNameReference("Realm.DataBinding", new Version(1, 2, 0, 0));
                        module.AssemblyReferences.Add(dataBindingAssembly);
                    }
                    references.InitializeDataBinding(dataBindingAssembly);
                    break;
                }
            }

            return(references);
        }
        public static ImportedReferences Create(ModuleWeaver weaver, FrameworkName frameworkName)
        {
            var module = weaver.ModuleDefinition;

            ImportedReferences references;

            switch (frameworkName.Identifier)
            {
            case ".NETFramework":
            case "Xamarin.iOS":
            case "MonoAndroid":
            case "Xamarin.Mac":
                references = new NETFramework(module, weaver.TypeSystem, frameworkName);
                break;

            case ".NETStandard":
                if (frameworkName.Version >= new Version(2, 0))
                {
                    references = new NetStandard2(module, weaver.TypeSystem, frameworkName);
                }
                else
                {
                    references = new NETPortable(module, weaver.TypeSystem, frameworkName);
                }

                break;

            case ".NETPortable":
            case ".NETCore":
            case ".NETCoreApp":
                references = new NETPortable(module, weaver.TypeSystem, frameworkName);
                break;

            default:
                throw new Exception($"Unsupported target framework: {frameworkName}");
            }

            references.InitializeFrameworkMethods();

            // Weaver may be run on an assembly which is not **yet** using Realm, if someone just adds nuget and builds.
            var realmAssembly = module.AssemblyReferences.SingleOrDefault(r => r.Name == "Realm");

            if (realmAssembly != null)
            {
                references.InitializeRealm(realmAssembly);
            }
            else if (module.Name == "Realm.dll")
            {
                references.InitializeRealm(module);
            }

            return(references);
        }
Example #3
0
        public static ImportedReferences Create(ModuleDefinition module)
        {
            var targetFramework = module.Assembly.CustomAttributes.Single(a => a.AttributeType.FullName == typeof(TargetFrameworkAttribute).FullName);

            ImportedReferences references;

            var frameworkName = new FrameworkName((string)targetFramework.ConstructorArguments.Single().Value);

            switch (frameworkName.Identifier)
            {
                case ".NETFramework":
                case "Xamarin.iOS":
                case "MonoAndroid":
                    references = new NETFramework(module);
                    break;
                case ".NETStandard":
                case ".NETPortable":
                    references = new NETPortable(module);
                    break;
                default:
                    throw new Exception($"Unsupported target framework: {frameworkName}");
            }

            references.InitializeFrameworkMethods();
            references.InitializeRealm(module.AssemblyReferences.Single(r => r.Name == "Realm"));
            return references;
        }
        public static ImportedReferences Create(FrameworkName frameworkName, ModuleDefinition module)
        {
            ImportedReferences references;

            switch (frameworkName.Identifier)
            {
            case ".NETFramework":
            case "Xamarin.iOS":
            case "MonoAndroid":
            case "Xamarin.Mac":
                references = new NETFramework(module);
                break;

            case ".NETStandard":
                if (frameworkName.Version >= new Version(2, 0))
                {
                    references = new NetStandard2(module);
                }
                else
                {
                    references = new NETPortable(module);
                }
                break;

            case ".NETPortable":
            case ".NETCore":
            case ".NETCoreApp":
                references = new NETPortable(module);
                break;

            default:
                throw new Exception($"Unsupported target framework: {frameworkName}");
            }

            references.InitializeFrameworkMethods();

            // Weaver may be run on an assembly which is not **yet** using Realm, if someone just adds nuget and builds.
            var realmAssembly = module.AssemblyReferences.SingleOrDefault(r => r.Name == "Realm");

            if (realmAssembly != null)
            {
                references.InitializeRealm(realmAssembly);

                switch (frameworkName.Identifier)
                {
                case "Xamarin.iOS":
                case "MonoAndroid":
                case ".NETStandard":
                case ".NETPortable":
                case "Xamarin.Mac":
                    var dataBindingAssembly = module.AssemblyReferences.SingleOrDefault(r => r.Name == "Realm.DataBinding");
                    if (dataBindingAssembly == null)
                    {
                        dataBindingAssembly = new AssemblyNameReference("Realm.DataBinding", new Version(1, 2, 0, 0));
                        module.AssemblyReferences.Add(dataBindingAssembly);
                    }
                    references.InitializeDataBinding(dataBindingAssembly);
                    break;
                }
            }

            return(references);
        }