mirror of
https://gitee.com/csharpui/CPF.git
synced 2025-11-24 08:33:23 +08:00
razor支持
This commit is contained in:
@@ -75,6 +75,7 @@ namespace ComponentWrapperGenerator
|
||||
};
|
||||
|
||||
// props
|
||||
Dictionary<string, PropertyInfo> cps = new Dictionary<string, PropertyInfo>();
|
||||
var propertyDeclarationBuilder = new StringBuilder();
|
||||
if (propertiesToGenerate.Any())
|
||||
{
|
||||
@@ -82,6 +83,10 @@ namespace ComponentWrapperGenerator
|
||||
}
|
||||
foreach (var prop in propertiesToGenerate)
|
||||
{
|
||||
if (prop.GetCustomAttribute(typeof(CPF.NotCpfProperty)) == null)
|
||||
{
|
||||
cps.Add(prop.Name + "Changed", prop);
|
||||
}
|
||||
propertyDeclarationBuilder.Append(GetPropertyDeclaration(prop, usings));
|
||||
}
|
||||
|
||||
@@ -90,10 +95,19 @@ namespace ComponentWrapperGenerator
|
||||
{
|
||||
if (typeToGenerate == typeof(CPF.UIElement) || (typeToGenerate != typeof(CPF.UIElement) && prop.DeclaringType != typeof(CPF.UIElement) && prop.DeclaringType != typeof(CPF.Visual) && prop.DeclaringType != typeof(CPF.CpfObject)))
|
||||
{
|
||||
propertyDeclarationBuilder.Append(GetEventDeclaration(prop, usings));
|
||||
if (!cps.ContainsKey(prop.Name))
|
||||
{
|
||||
propertyDeclarationBuilder.Append(GetEventDeclaration(prop, usings));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in cps)
|
||||
{
|
||||
propertyDeclarationBuilder.Append(GetPropertyChangedDeclaration(item.Value, usings));
|
||||
}
|
||||
|
||||
|
||||
var propertyDeclarations = propertyDeclarationBuilder.ToString();
|
||||
|
||||
//var propertyAttributeBuilder = new StringBuilder();
|
||||
@@ -176,7 +190,7 @@ namespace {Settings.RootNamespace}
|
||||
{
|
||||
var propertyType = prop.PropertyType;
|
||||
string propertyTypeName;
|
||||
if (propertyType == typeof(IList<string>) || propertyType == typeof(CPF.ViewFill) || propertyType == typeof(CPF.Drawing.Color) || propertyType == typeof(CPF.Drawing.Brush))
|
||||
if (propertyType == typeof(IList<string>) || propertyType == typeof(CPF.ViewFill) || propertyType == typeof(CPF.Drawing.Color) || propertyType == typeof(CPF.Drawing.Brush) || propertyType == typeof(CPF.Classes))
|
||||
{
|
||||
// Lists of strings are special-cased because they are handled specially by the handlers as a comma-separated list
|
||||
propertyTypeName = "string";
|
||||
@@ -210,12 +224,12 @@ namespace {Settings.RootNamespace}
|
||||
}
|
||||
else
|
||||
{
|
||||
//propertyTypeName = GetTypeNameAndAddNamespace(propertyType, usings);
|
||||
//if (propertyType.IsValueType)
|
||||
//{
|
||||
// propertyTypeName += "?";
|
||||
//}
|
||||
propertyTypeName = $"EventCallback<{propertyType.GetGenericArguments()[0]}>";
|
||||
propertyTypeName = GetTypeNameAndAddNamespace(propertyType.GetGenericArguments()[0], usings);
|
||||
if (propertyType.GetGenericArguments()[0].IsValueType)
|
||||
{
|
||||
propertyTypeName += "?";
|
||||
}
|
||||
propertyTypeName = $"EventCallback<{propertyTypeName}>";
|
||||
}
|
||||
var des = "";
|
||||
var d = prop.GetCustomAttribute<System.ComponentModel.DescriptionAttribute>();
|
||||
@@ -227,6 +241,25 @@ namespace {Settings.RootNamespace}
|
||||
";
|
||||
}
|
||||
|
||||
static string GetPropertyChangedDeclaration(PropertyInfo prop, IList<UsingStatement> usings)
|
||||
{
|
||||
var propertyType = prop.PropertyType;
|
||||
string propertyTypeName = GetTypeNameAndAddNamespace(propertyType, usings);
|
||||
//if (propertyType.IsValueType && (!propertyType.IsGenericType || propertyType.GetGenericTypeDefinition() == typeof(Nullable)))
|
||||
//{
|
||||
// propertyTypeName += "?";
|
||||
//}
|
||||
propertyTypeName = $"EventCallback<{propertyTypeName}>";
|
||||
var des = "";
|
||||
var d = prop.GetCustomAttribute<System.ComponentModel.DescriptionAttribute>();
|
||||
if (d != null)
|
||||
{
|
||||
des = $" /// <summary>\r\n /// {d.Description}\r\n /// <summary>\r\n";
|
||||
}
|
||||
return $@"{des} [Parameter] public {propertyTypeName} {GetIdentifierName(prop.Name + "Changed")} {{ get; set; }}
|
||||
";
|
||||
}
|
||||
|
||||
private static string GetTypeNameAndAddNamespace(Type type, IList<UsingStatement> usings)
|
||||
{
|
||||
var typeName = GetCSharpType(type);
|
||||
@@ -613,7 +646,7 @@ namespace {Settings.RootNamespace}
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return propInfo.GetGetMethod() != null && propInfo.GetSetMethod() != null && propInfo.GetCustomAttribute(typeof(CPF.NotCpfProperty)) == null;
|
||||
return propInfo.GetGetMethod() != null && propInfo.GetSetMethod() != null && (propInfo.GetCustomAttribute(typeof(CPF.NotCpfProperty)) == null || propInfo.PropertyType == typeof(CPF.Classes));
|
||||
}
|
||||
|
||||
private static bool IsPropertyBrowsable(PropertyInfo propInfo)
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace CpfRazorSample
|
||||
//, (OperatingSystemType.OSX, new CPF.Mac.MacPlatform(), new SkiaDrawingFactory())//如果需要支持Mac才需要
|
||||
//, (OperatingSystemType.Linux, new CPF.Linux.LinuxPlatform(), new SkiaDrawingFactory())//如果需要支持Linux才需要
|
||||
);
|
||||
//Create();
|
||||
|
||||
var host = Host.CreateDefaultBuilder()
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
@@ -28,10 +29,10 @@ namespace CpfRazorSample
|
||||
.Build();
|
||||
|
||||
var window = new CPF.Controls.Window { Width = 500, Height = 500, Background = null };
|
||||
window.LoadStyleFile("res://CpfRazorSample/Stylesheet1.css");
|
||||
host.AddComponent<Test>(window);
|
||||
Application.Run(window);
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void Create()
|
||||
|
||||
@@ -1,24 +1,49 @@
|
||||
<WindowFrame MaximizeBox="true" Width='"100%"' Height="@("100%")">
|
||||
<StackPanel Background="#f00" Width='"100%"' Height="@("100%")">
|
||||
<Button Width="80" Height="30" MouseDown="OnMouseDown" Content="text">
|
||||
<StackPanel Width='"100%"' Height="@("100%")">
|
||||
<Button Width="80" Height="30" MouseDown="OnMouseDown" Content="test">
|
||||
</Button>
|
||||
<CheckBox Content="12"></CheckBox>
|
||||
@if (visible)
|
||||
{
|
||||
<Panel Background="#0f0" Width="20" Height="30" MarginLeft="10"></Panel>
|
||||
}
|
||||
<Button>1234dsggs</Button>
|
||||
<TextBox Text="@text"></TextBox>
|
||||
<Button><CheckBox></CheckBox></Button>
|
||||
<TextBox @ref="textBox" Text="text" Width="100" Height="30" TextChanged="TextChanged"></TextBox>
|
||||
<Button @ref="button"><CheckBox>@enable</CheckBox></Button>
|
||||
<ListBox @ref="listBox" Width="200" Height="200" Items="list"></ListBox>
|
||||
</StackPanel>
|
||||
</WindowFrame>
|
||||
@code
|
||||
{
|
||||
string key = "textBox";
|
||||
TextBox textBox;
|
||||
CPF.Controls.Button button;
|
||||
bool visible = false;
|
||||
string text = "test";
|
||||
List<string> list = new List<string>()
|
||||
{
|
||||
"1","2","3"
|
||||
};
|
||||
ListBox listBox;
|
||||
object test = "test";
|
||||
bool enable;
|
||||
void OnMouseDown(CPF.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
//enable = visible;
|
||||
button.IsEnabled = visible;
|
||||
|
||||
text = "test" + visible;
|
||||
visible = !visible;
|
||||
list.Add(list.Count.ToString());
|
||||
test = list.Count;
|
||||
}
|
||||
|
||||
void TextChanged()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user