本文整理汇总了C#中ReadOnlyCollectionBuilder.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlyCollectionBuilder.ToArray方法的具体用法?C# ReadOnlyCollectionBuilder.ToArray怎么用?C# ReadOnlyCollectionBuilder.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReadOnlyCollectionBuilder
的用法示例。
在下文中一共展示了ReadOnlyCollectionBuilder.ToArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetConvertedArgs
private static Expression[] GetConvertedArgs(params Expression[] args) {
ReadOnlyCollectionBuilder<Expression> paramArgs = new ReadOnlyCollectionBuilder<Expression>(args.Length);
for (int i = 0; i < args.Length; i++) {
paramArgs.Add(Expression.Convert(args[i], typeof(object)));
}
return paramArgs.ToArray();
}
示例2: Reduce
public override MSAst.Expression Reduce() {
if (_names == _star) {
// from a[.b] import *
return GlobalParent.AddDebugInfo(
Ast.Call(
AstMethods.ImportStar,
Parent.LocalContext,
AstUtils.Constant(_root.MakeString()),
AstUtils.Constant(GetLevel())
),
Span
);
} else {
// from a[.b] import x [as xx], [ y [ as yy] ] [ , ... ]
ReadOnlyCollectionBuilder<MSAst.Expression> statements = new ReadOnlyCollectionBuilder<MSAst.Expression>();
MSAst.ParameterExpression module = Ast.Variable(typeof(object), "module");
// Create initializer of the array of names being passed to ImportWithNames
MSAst.Expression[] names = new MSAst.Expression[_names.Length];
for (int i = 0; i < names.Length; i++) {
names[i] = AstUtils.Constant(_names[i]);
}
// module = PythonOps.ImportWithNames(<context>, _root, make_array(_names))
statements.Add(
GlobalParent.AddDebugInfoAndVoid(
AssignValue(
module,
LightExceptions.CheckAndThrow(
Expression.Call(
AstMethods.ImportWithNames,
Parent.LocalContext,
AstUtils.Constant(_root.MakeString()),
Ast.NewArrayInit(typeof(string), names),
AstUtils.Constant(GetLevel())
)
)
),
_root.Span
)
);
// now load all the names being imported and assign the variables
for (int i = 0; i < names.Length; i++) {
statements.Add(
GlobalParent.AddDebugInfoAndVoid(
AssignValue(
Parent.GetVariableExpression(_variables[i]),
Ast.Call(
AstMethods.ImportFrom,
Parent.LocalContext,
module,
names[i]
)
),
Span
)
);
}
statements.Add(AstUtils.Empty());
return GlobalParent.AddDebugInfo(Ast.Block(new[] { module }, statements.ToArray()), Span);
}
}
示例3: GetConvertedArgs
private static Expression[] GetConvertedArgs(params Expression[] args)
{
var paramArgs = new ReadOnlyCollectionBuilder<Expression>(args.Length);
foreach (var t in args)
{
paramArgs.Add(Expression.Convert(t, typeof(object)));
}
return paramArgs.ToArray();
}
示例4: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
if (_names == _star) {
// from a[.b] import *
return ag.AddDebugInfo(
Ast.Call(
AstGenerator.GetHelperMethod("ImportStar"),
ag.LocalContext,
AstUtils.Constant(_root.MakeString()),
AstUtils.Constant(GetLevel())
),
Span
);
} else {
// from a[.b] import x [as xx], [ y [ as yy] ] [ , ... ]
ReadOnlyCollectionBuilder<MSAst.Expression> statements = new ReadOnlyCollectionBuilder<MSAst.Expression>();
MSAst.ParameterExpression module = ag.GetTemporary("module");
// Create initializer of the array of names being passed to ImportWithNames
MSAst.Expression[] names = new MSAst.Expression[_names.Length];
for (int i = 0; i < names.Length; i++) {
names[i] = AstUtils.Constant(_names[i]);
}
// module = PythonOps.ImportWithNames(<context>, _root, make_array(_names))
statements.Add(
ag.AddDebugInfoAndVoid(
GlobalAllocator.Assign(
module,
Ast.Call(
AstGenerator.GetHelperMethod("ImportWithNames"),
ag.LocalContext,
AstUtils.Constant(_root.MakeString()),
Ast.NewArrayInit(typeof(string), names),
AstUtils.Constant(GetLevel())
)
),
_root.Span
)
);
// now load all the names being imported and assign the variables
for (int i = 0; i < names.Length; i++) {
statements.Add(
ag.AddDebugInfoAndVoid(
GlobalAllocator.Assign(
ag.Globals.GetVariable(ag, _variables[i]),
Ast.Call(
AstGenerator.GetHelperMethod("ImportFrom"),
ag.LocalContext,
module,
names[i]
)
),
Span
)
);
}
statements.Add(AstUtils.Empty());
return ag.AddDebugInfo(Ast.Block(statements.ToArray()), Span);
}
}
示例5: MakeClosureTuple
internal Expression MakeClosureTuple()
{
if (_closureVariables == null)
return Utils.Constant(null, typeof(MutableTuple));
Debug.Assert(_closureVariables.Count > 0);
Debug.Assert(_closureType != null);
ReadOnlyCollectionBuilder<Expression> initializers = new ReadOnlyCollectionBuilder<Expression>();
for (var i = 0; i < _closureVariables.Count; i++)
{
var closureExpression = Parent._variableMapping[_closureVariables[i]] as ClosureExpression;
initializers.Add(closureExpression.ClosureCell);
}
var ret = MutableTuple.Create(
initializers.ToArray()
);
Debug.Assert(ret.Type == _closureType);
return ret;
}