mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
EventInterfaceGenerate支持List与Dictionary(但不推荐用)
EventInterfaceGenerate支持List与Dictionary(但不推荐用)
This commit is contained in:
@@ -187,14 +187,20 @@ public static class EventInterfaceGenerate
|
||||
var parameterInfo = parameterInfos[i];
|
||||
Type type = parameterInfo.ParameterType;
|
||||
string paramName = parameterInfo.Name;
|
||||
|
||||
if (type.FullName.StartsWith("System.Collections.Generic.List"))
|
||||
{
|
||||
Debug.Log("123");
|
||||
}
|
||||
|
||||
if (i == parameterInfos.Length - 1)
|
||||
{
|
||||
paramStr += $"{type.FullName} {paramName}";
|
||||
paramStr += $"{GetTypeName(parameterInfo)} {paramName}";
|
||||
paramStr2 += $"{paramName}";
|
||||
}
|
||||
else
|
||||
{
|
||||
paramStr += $"{type.FullName} {paramName},";
|
||||
paramStr += $"{GetTypeName(parameterInfo)} {paramName},";
|
||||
paramStr2 += $"{paramName},";
|
||||
}
|
||||
}
|
||||
@@ -214,6 +220,65 @@ public static class EventInterfaceGenerate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetTypeName(ParameterInfo parameterInfo)
|
||||
{
|
||||
if (parameterInfo.ParameterType.IsList() && parameterInfo.ParameterType.IsGenericType)
|
||||
{
|
||||
string typeName = parameterInfo.ParameterType.FullName.Split('`')[0];
|
||||
|
||||
return $"{typeName}<{parameterInfo.ParameterType.GenericTypeArguments[0].FullName}>";
|
||||
}
|
||||
else if (parameterInfo.ParameterType.IsDictionary() && parameterInfo.ParameterType.IsGenericType)
|
||||
{
|
||||
string typeName = parameterInfo.ParameterType.FullName.Split('`')[0];
|
||||
|
||||
return $"{typeName}<{parameterInfo.ParameterType.GenericTypeArguments[0].FullName},{parameterInfo.ParameterType.GenericTypeArguments[1].FullName}>";
|
||||
}
|
||||
else
|
||||
{
|
||||
return parameterInfo.ParameterType.FullName;
|
||||
}
|
||||
|
||||
return parameterInfo.ParameterType.FullName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断类型是否为可操作的列表类型
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsList(this Type type)
|
||||
{
|
||||
if (typeof (System.Collections.IList).IsAssignableFrom(type))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var it in type.GetInterfaces())
|
||||
{
|
||||
if (it.IsGenericType && typeof (IList<>) == it.GetGenericTypeDefinition())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsDictionary(this Type type)
|
||||
{
|
||||
if (typeof (System.Collections.IDictionary).IsAssignableFrom(type))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var it in type.GetInterfaces())
|
||||
{
|
||||
if (it.IsGenericType && typeof (IDictionary) == it.GetGenericTypeDefinition())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EventInterfaceGenerateTag
|
||||
|
Reference in New Issue
Block a user