本文整理汇总了C#中Scope.SetParent方法的典型用法代码示例。如果您正苦于以下问题:C# Scope.SetParent方法的具体用法?C# Scope.SetParent怎么用?C# Scope.SetParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scope
的用法示例。
在下文中一共展示了Scope.SetParent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareDataSource
private IScope PrepareDataSource(XElement source, IScope parent) {
var result = new Scope();
if (null != parent) {
result.SetParent(parent);
}
foreach (var a in source.Attributes()) {
result.Set(a.Name.LocalName, a.Value);
}
result.Set("this", source);
return result;
}
示例2: ProcessRepeat
private XElement[] ProcessRepeat(XElement source, IScope datasource) {
var a = GetDataSource(source, datasource);
if (0 == a.Length) {
return null;
}
var result = new List<XElement>();
var scope = source.Attr("xi-scope");
var scope2 = "";
var expand = source.Attr("xi-expand").ToBool();
var rep = source.Attr("xi-repeat");
if (rep.Contains(" in ")) {
scope2 = Regex.Match(rep, @"^([\s\S]+?)\s+in").Groups[1].Value;
if (scope2.EndsWith("+")) {
expand = true;
scope2 = scope2.Substring(0, scope2.Length - 1);
}
}
var i = 0;
foreach (var o in a) {
var dict = o.ToDict();
var cfg = new Scope();
if (!string.IsNullOrWhiteSpace(scope)) {
cfg[scope] = dict;
}
if (!string.IsNullOrWhiteSpace(scope2)) {
cfg[scope2] = dict;
}
if (expand) {
foreach (var p in dict) {
cfg[p.Key] = p.Value;
}
}
var clone = new XElement(source);
cfg.Set("this", clone);
cfg.Set("parent", source);
cfg.SetParent(datasource);
cfg.Set("_idx", i);
cfg.Set("_num", i + 1);
cfg.Set("_i", dict);
if (!MatchCondition(clone, cfg, "where")) {
continue;
}
clone.SetAttributeValue("xi-repeat", null);
clone.SetAttributeValue("xi-scope", null);
clone.SetAttributeValue("xi-expand", null);
clone = Interpolate(clone, cfg);
if (null != clone) {
if (clone.Attr("xi-body").ToBool()) {
foreach (var element in clone.Elements()) {
result.Add(element);
}
}
else {
result.Add(clone);
}
}
i++;
}
return result.ToArray();
}