CPF/CpfRazorSample/Program.cs

74 lines
2.7 KiB
C#
Raw Normal View History

2024-01-08 10:55:10 +08:00
using CPF.Platform;
using CPF.Skia;
using CPF.Windows;
using Microsoft.Extensions.Hosting;
using System;
using CPF.Razor;
2024-01-09 00:39:58 +08:00
using ComponentWrapperGenerator;
2024-01-08 10:55:10 +08:00
namespace CpfRazorSample
{
class Program
{
[STAThread]
static void Main(string[] args)
{
Application.Initialize(
(OperatingSystemType.Windows, new WindowsPlatform(), new SkiaDrawingFactory())
2024-01-09 00:39:58 +08:00
//, (OperatingSystemType.OSX, new CPF.Mac.MacPlatform(), new SkiaDrawingFactory())//如果需要支持Mac才需要
//, (OperatingSystemType.Linux, new CPF.Linux.LinuxPlatform(), new SkiaDrawingFactory())//如果需要支持Linux才需要
2024-01-08 10:55:10 +08:00
);
2024-01-09 16:57:27 +08:00
//Create();
2024-01-08 10:55:10 +08:00
var host = Host.CreateDefaultBuilder()
.ConfigureServices((hostContext, services) =>
{
// Register app-specific services
//services.AddSingleton<AppState>();
})
.Build();
2024-01-09 00:39:58 +08:00
var window = new CPF.Controls.Window { Width = 500, Height = 500, Background = null };
2024-01-09 16:57:27 +08:00
window.LoadStyleFile("res://CpfRazorSample/Stylesheet1.css");
2024-01-08 10:55:10 +08:00
host.AddComponent<Test>(window);
Application.Run(window);
2024-01-09 00:39:58 +08:00
}
static void Create()
{
var settings = new GeneratorSettings
{
FileHeader = @"//CPF自动生成.
",
RootNamespace = "CPF.Razor.Controls",
};
var type = typeof(CPF.UIElement);
var viewType = typeof(CPF.Controls.View);
var types = type.Assembly.GetTypes();
CpfGenerateWrapperForType(type, settings, "");
//CpfGenerateWrapperForType(typeof(CPF.Controls.WindowFrame), settings, "");
foreach (var item in types)
{
if (item.IsPublic && item.IsSubclassOf(type) && !item.IsAbstract && !item.IsGenericType && !item.IsSubclassOf(viewType) && item.GetConstructor(Array.Empty<Type>()) != null)
{
var brow = item.GetCustomAttributes(typeof(System.ComponentModel.BrowsableAttribute), true);
if (brow != null && brow.Length > 0 && !(brow[0] as System.ComponentModel.BrowsableAttribute).Browsable)
{
continue;
}
CpfGenerateWrapperForType(item, settings, "");
}
}
}
private static void CpfGenerateWrapperForType(Type typeToGenerate, GeneratorSettings settings, string outputFolder)
{
var generator = new CpfComponentWrapperGenerator(settings);
generator.GenerateComponentWrapper(typeToGenerate, outputFolder);
Console.WriteLine();
2024-01-08 10:55:10 +08:00
}
}
}