本文整理汇总了C#中Env.FindRulesets方法的典型用法代码示例。如果您正苦于以下问题:C# Env.FindRulesets方法的具体用法?C# Env.FindRulesets怎么用?C# Env.FindRulesets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Env
的用法示例。
在下文中一共展示了Env.FindRulesets方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
public override Node Evaluate(Env env)
{
var found = false;
var closures = env.FindRulesets(Selector);
if(closures == null)
throw new ParsingException(Selector.ToCSS(env).Trim() + " is undefined", Index);
env.Rule = this;
var rules = new NodeList();
for(var i = 0; i < closures.Count; i++)
{
var closure = closures[i];
var ruleset = closure.Ruleset;
if (!ruleset.MatchArguements(Arguments, env))
continue;
found = true;
if (ruleset is MixinDefinition)
{
try
{
var mixin = ruleset as MixinDefinition;
rules.AddRange(mixin.Evaluate(Arguments, env, closure.Context).Rules);
}
catch (ParsingException e)
{
throw new ParsingException(e.Message, e.Index, Index);
}
}
else
{
if (ruleset.Rules != null)
{
var nodes = new List<Node>(ruleset.Rules);
NodeHelper.ExpandNodes<MixinCall>(env, nodes);
rules.AddRange(nodes);
}
}
}
env.Rule = null;
if (!found)
{
var message = String.Format("No matching definition was found for `{0}({1})`",
Selector.ToCSS(env).Trim(),
StringExtensions.JoinStrings(Arguments.Select(a => a.ToCSS(env)), ", "));
throw new ParsingException(message, Index);
}
return rules;
}
示例2: Evaluate
public override Node Evaluate(Env env)
{
var found = false;
var closures = env.FindRulesets(Selector);
if(closures == null)
throw new ParsingException(Selector.ToCSS(env).Trim() + " is undefined", Location);
env.Rule = this;
var rules = new NodeList();
if (PreComments)
rules.AddRange(PreComments);
foreach (var closure in closures)
{
var ruleset = closure.Ruleset;
var matchType = ruleset.MatchArguments(Arguments, env);
if (matchType == MixinMatch.ArgumentMismatch)
continue;
found = true;
if (matchType == MixinMatch.GuardFail)
continue;
if (ruleset is MixinDefinition)
{
try
{
var mixin = ruleset as MixinDefinition;
rules.AddRange(mixin.Evaluate(Arguments, env, closure.Context).Rules);
}
catch (ParsingException e)
{
throw new ParsingException(e.Message, e.Location, Location);
}
}
else
{
if (ruleset.Rules != null)
{
var nodes = new NodeList(ruleset.Rules);
NodeHelper.ExpandNodes<MixinCall>(env, nodes);
rules.AddRange(nodes);
}
}
}
if (PostComments)
rules.AddRange(PostComments);
env.Rule = null;
if (!found)
{
var message = String.Format("No matching definition was found for `{0}({1})`",
Selector.ToCSS(env).Trim(),
Arguments.Select(a => a.Value.ToCSS(env)).JoinStrings(env.Compress ? "," : ", "));
throw new ParsingException(message, Location);
}
if (Important)
{
var importantRules = new NodeList();
foreach (Node node in rules)
{
Rule r = node as Rule;
if (r != null)
{
var valueNode = r.Value;
var value = valueNode as Value;
value = value != null
? new Value(value.Values, "!important").ReducedFrom<Value>(value)
: new Value(new NodeList {valueNode}, "!important");
importantRules.Add((new Rule(r.Name, value)).ReducedFrom<Rule>(r));
}
else
{
importantRules.Add(node);
}
}
return importantRules;
}
return rules;
}
示例3: Evaluate
public override Node Evaluate(Env env)
{
var closures = env.FindRulesets(Selector);
if (closures == null)
throw new ParsingException(Selector.ToCSS(env).Trim() + " is undefined", Location);
env.Rule = this;
var rules = new NodeList();
if (PreComments)
rules.AddRange(PreComments);
var rulesetList = closures.ToList();
// To address bug https://github.com/dotless/dotless/issues/136, where a mixin and ruleset selector may have the same name, we
// need to favour matching a MixinDefinition with the required Selector and only fall back to considering other Ruleset types
// if no match is found.
// However, in order to support having a regular ruleset with the same name as a parameterized
// mixin (see https://github.com/dotless/dotless/issues/387), we need to take argument counts into account, so we make the
// decision after evaluating for argument match.
var mixins = rulesetList.Where(c => c.Ruleset is MixinDefinition).ToList();
var defaults = new List<Closure>();
bool foundMatches = false, foundExactMatches = false, foundDefaultMatches = false;
foreach (var closure in mixins)
{
var ruleset = (MixinDefinition)closure.Ruleset;
var matchType = ruleset.MatchArguments(Arguments, env);
if (matchType == MixinMatch.ArgumentMismatch)
{
continue;
}
if (matchType == MixinMatch.Default) {
defaults.Add(closure);
foundDefaultMatches = true;
continue;
}
foundMatches = true;
if (matchType == MixinMatch.GuardFail)
{
continue;
}
foundExactMatches = true;
try
{
var closureEnvironment = env.CreateChildEnvWithClosure(closure);
rules.AddRange(ruleset.Evaluate(Arguments, closureEnvironment).Rules);
}
catch (ParsingException e)
{
throw new ParsingException(e.Message, e.Location, Location);
}
}
if (!foundExactMatches && foundDefaultMatches) {
foreach (var closure in defaults) {
try {
var closureEnvironment = env.CreateChildEnvWithClosure(closure);
var ruleset = (MixinDefinition) closure.Ruleset;
rules.AddRange(ruleset.Evaluate(Arguments, closureEnvironment).Rules);
} catch (ParsingException e) {
throw new ParsingException(e.Message, e.Location, Location);
}
}
foundMatches = true;
}
if (!foundMatches)
{
var regularRulesets = rulesetList.Except(mixins);
foreach (var closure in regularRulesets)
{
if (closure.Ruleset.Rules != null) {
var nodes = (NodeList)closure.Ruleset.Rules.Clone();
NodeHelper.ExpandNodes<MixinCall>(env, nodes);
rules.AddRange(nodes);
}
foundMatches = true;
}
}
if (PostComments)
rules.AddRange(PostComments);
env.Rule = null;
if (!foundMatches)
{
//.........这里部分代码省略.........