新增默认脚本内容
This commit is contained in:
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Convention.RScript.Variable.CStyle
|
||||
{
|
||||
public class RScriptInjectVariable : Variable.RScriptInjectVariable
|
||||
public class RScriptVariableGenerater : RScriptInjectVariableGenerater
|
||||
{
|
||||
public static string GetTypename(Type type)
|
||||
{
|
||||
@@ -18,7 +18,7 @@ namespace Convention.RScript.Variable.CStyle
|
||||
private int layer = 0;
|
||||
private string Prefix => new('\t', layer);
|
||||
|
||||
public RScriptInjectVariable(Type targetType, [MaybeNull] Generater generater, string name) : base(targetType, generater, name)
|
||||
public RScriptVariableGenerater(Type targetType, [MaybeNull] Generater generater, string name) : base(targetType, generater, name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,19 @@ namespace Convention.RScript.Variable
|
||||
public sealed class EnumAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class DefaultAttribute : Attribute
|
||||
{
|
||||
public string defaultScript;
|
||||
public DefaultAttribute(string defaultScript)
|
||||
{
|
||||
this.defaultScript = defaultScript;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class RScriptInjectVariable
|
||||
public abstract class RScriptInjectVariableGenerater
|
||||
{
|
||||
public string RScriptString { get; private set; }
|
||||
|
||||
@@ -59,18 +69,19 @@ namespace Convention.RScript.Variable
|
||||
|
||||
private Generater MyGenerater;
|
||||
|
||||
public readonly static Dictionary<string, RScriptInjectVariable> AllRScriptInjectVariables = new();
|
||||
public readonly static Dictionary<string, RScriptInjectVariableGenerater> AllRScriptInjectVariables = new();
|
||||
|
||||
public readonly Type targetType;
|
||||
public readonly string name;
|
||||
public readonly string script;
|
||||
public readonly string scriptIndicator;
|
||||
public readonly string defaultScript;
|
||||
|
||||
public object Generate()
|
||||
{
|
||||
return MyGenerater();
|
||||
}
|
||||
|
||||
public RScriptInjectVariable(Type targetType, [MaybeNull] Generater generater, string name)
|
||||
public RScriptInjectVariableGenerater(Type targetType, [MaybeNull] Generater generater, string name)
|
||||
{
|
||||
if (AllRScriptInjectVariables.TryGetValue(name, out var exist_var))
|
||||
{
|
||||
@@ -80,7 +91,9 @@ namespace Convention.RScript.Variable
|
||||
}
|
||||
this.targetType = exist_var.targetType;
|
||||
this.name = exist_var.name;
|
||||
this.script = exist_var.script;
|
||||
this.scriptIndicator = exist_var.scriptIndicator;
|
||||
this.defaultScript = exist_var.defaultScript;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -125,12 +138,14 @@ namespace Convention.RScript.Variable
|
||||
builder.AppendLine(this.WriteClassBodyExit(targetType));
|
||||
builder.AppendLine(this.WriteClassTail(targetType));
|
||||
builder.AppendLine(this.WritePageEnd(targetType));
|
||||
this.script = builder.ToString();
|
||||
this.scriptIndicator = builder.ToString();
|
||||
}
|
||||
|
||||
this.targetType = targetType;
|
||||
this.MyGenerater = generater;
|
||||
this.name = name;
|
||||
var defaultAttr = targetType.GetCustomAttribute<Attr.DefaultAttribute>();
|
||||
this.defaultScript = defaultAttr?.defaultScript;
|
||||
}
|
||||
|
||||
public static object GenerateRScriptVariable(string name)
|
||||
@@ -154,7 +169,7 @@ namespace Convention.RScript.Variable
|
||||
{
|
||||
public static object New(string name)
|
||||
{
|
||||
return RScriptInjectVariable.GenerateRScriptVariable(name);
|
||||
return RScriptInjectVariableGenerater.GenerateRScriptVariable(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user