这个对我有用:
compileTimeAndRuntime
{
define New($T, $F) { $T $F = new $T(); }
public partial class DI : IResolver
{
public New(ConcurrentDictionary<Type, Expression<Func<IResolver, object>>>, Registrations);
internal New(ConcurrentDictionary<Type, Func<IResolver, object>>, DelegateCache);
}
}
// Generated from Untitled.ecs by LeMP 2.8.2.0.
public partial class DI : IResolver
{
public ConcurrentDictionary<Type, Expression<Func<IResolver, object>>> Registrations = new ConcurrentDictionary<Type, Expression<Func<IResolver, object>>>();
internal ConcurrentDictionary<Type, Func<IResolver, object>> DelegateCache = new ConcurrentDictionary<Type, Func<IResolver, object>>();
}
这是一个更有趣的版本:
// Matches variable declarations and replaces __var with the type name.
// Useful to avoid repeating the type twice when declaring fields in classes.
[Passive] // avoids warning on variable declarations that don't match
define #var(__var, $name = new $T($(..args)) { $(..initializers) }) {
$T $name = new $T($args) { $initializers };
}
public partial class DI : IResolver
{
public __var Registrations = new ConcurrentDictionary<Type, Expression<Func<IResolver, object>>>();
internal __var DelegateCache = new ConcurrentDictionary<Type, Func<IResolver, object>>();
private __var _array = new int[4] { 0, 10, 20, 30 };
}
// Generated from Untitled.ecs by LeMP 2.8.2.0.
public partial class DI : IResolver
{
public ConcurrentDictionary<Type, Expression<Func<IResolver, object>>> Registrations = new ConcurrentDictionary<Type, Expression<Func<IResolver, object>>>();
internal ConcurrentDictionary<Type, Func<IResolver, object>> DelegateCache = new ConcurrentDictionary<Type, Func<IResolver, object>>();
private int[] _array = new int[4] {
0, 10, 20, 30
};
}
这是基于我的知识,它T x = y
有一个 Loyc 树的形式#var(T, x = y)
,但是replace
宏允许你在没有这些知识的情况下做同样的事情:
replace (
{ __var $name = new $Type($(..args)) { $(..initializers) }; } =>
{ $Type $name = new $Type($(..args)) { $(..initializers) }; });
很抱歉花了这么长时间来回答。