// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.ReactNative;
namespace Microsoft.ReactNative.Managed
{
///
/// A default implementation that uses reflection to extract the Modules
/// to be registered on the package builder.
///
/// This must be thea type defined in the assembly where the items for the react package should be extracted.
///
/// The common use case of this type is adding this to the PackageProviders from the constructor of your application (say: in App() of App.g.cs) like PackageProviders.Add(new ReflectionReactPackageProvider<App>());.
///
public class ReflectionReactPackageProvider : IReactPackageProvider
{
public virtual void CreatePackage(IReactPackageBuilder packageBuilder)
{
ReflectionReactPackageProviderExtensions.AddReflectionReactPackageProvider(packageBuilder);
}
}
///
/// Extensions for registering a reflection based package provider
///
public static class ReflectionReactPackageProviderExtensions
{
///
/// Helper extension method to register a reflection
///
/// This must be thea type defined in the assembly where the items for the react package should be extracted.
///
/// The common use case of this type is when you have a react library. Then you would call this from the function in ReactPackageProvider class that implements like:
///
/// public sealed class ReactPackageProvider : IReactPackageProvider
/// {
/// public void CreatePackage(IReactPackageBuilder packageBuilder)
/// {
/// packageBuilder.AddReflectionReactPackageProvider<ReactPackageProvider>();
/// }
/// }
/// .
///
public static void AddReflectionReactPackageProvider(this IReactPackageBuilder packageBuilder)
{
var assembly = typeof(T).Assembly;
packageBuilder.AddAttributedModules(assembly);
JSValueReaderGenerator.RegisterAssembly(assembly);
JSValueWriterGenerator.RegisterAssembly(assembly);
}
}
}