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(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); }