mirror of
https://gitee.com/csharpui/CPF.git
synced 2026-04-21 19:28:11 +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)
|
||||
|
||||
Reference in New Issue
Block a user