本文整理汇总了C#中Env类的典型用法代码示例。如果您正苦于以下问题:C# Env类的具体用法?C# Env怎么用?C# Env使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Env类属于命名空间,在下文中一共展示了Env类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
protected override Node Evaluate(Env env)
{
Guard.ExpectMinArguments(2, Arguments.Count, this, Index);
Guard.ExpectMaxArguments(3, Arguments.Count, this, Index);
Guard.ExpectAllNodes<Color>(Arguments.Take(2), this, Index);
double weight = 50;
if (Arguments.Count == 3)
{
Guard.ExpectNode<Number>(Arguments[2], this, Index);
weight = ((Number) Arguments[2]).Value;
}
var colors = Arguments.Take(2).Cast<Color>().ToArray();
// Note: this algorithm taken from http://github.com/nex3/haml/blob/0e249c844f66bd0872ed68d99de22b774794e967/lib/sass/script/functions.rb
var p = weight/100.0;
var w = p*2 - 1;
var a = colors[0].Alpha - colors[1].Alpha;
var w1 = (((w*a == -1) ? w : (w + a)/(1 + w*a)) + 1)/2.0;
var w2 = 1 - w1;
var rgb = colors[0].RGB.Select((x, i) => x*w1 + colors[1].RGB[i]*w2).ToArray();
var alpha = colors[0].Alpha*p + colors[1].Alpha*(1 - p);
var color = new Color(rgb[0], rgb[1], rgb[2], alpha);
return color;
}
示例2: Evaluate
public override Node Evaluate(Env env)
{
int blockIndex = env.MediaBlocks.Count;
env.MediaBlocks.Add(this);
env.MediaPath.Push(this);
env.Frames.Push(Ruleset);
NodeHelper.ExpandNodes<Import>(env, Ruleset.Rules);
env.Frames.Pop();
var features = Features.Evaluate(env);
var ruleset = Ruleset.Evaluate(env) as Ruleset;
var media = new Media(features, ruleset,Extensions).ReducedFrom<Media>(this);
env.MediaPath.Pop();
env.MediaBlocks[blockIndex] = media;
if (env.MediaPath.Count == 0)
{
return media.EvalTop(env);
}
else
{
return media.EvalNested(env, features, ruleset);
}
}
示例3: Evaluate
public override Node Evaluate(Env env)
{
if(Evaluated) return this;
try
{
env = env ?? new Env();
env.Frames.Push(this);
NodeHelper.ExpandNodes<Import>(env, Rules);
env.Frames.Pop();
var clone = new Root(new NodeList(Rules), Error, OriginalRuleset);
clone = DoVisiting(clone, env, VisitorPluginType.BeforeEvaluation);
clone.ReducedFrom<Root>(this);
clone.EvaluateRules(env);
clone.Evaluated = true;
clone = DoVisiting(clone, env, VisitorPluginType.AfterEvaluation);
return clone;
}
catch (ParsingException e)
{
throw Error(e);
}
}
示例4: AppendCSS
public override void AppendCSS(Env env)
{
env.Output
.Append('(')
.Append(Value)
.Append(')');
}
示例5: Evaluate
public override Node Evaluate(Env env)
{
var a = First.Evaluate(env);
var b = Second.Evaluate(env);
if (a is Number && b is Color)
{
if (Operator == "*" || Operator == "+")
{
var temp = b;
b = a;
a = temp;
}
else
throw new ParsingException("Can't substract or divide a color from a number", Index);
}
try
{
var operable = a as IOperable;
if (operable != null)
return operable.Operate(this, b).ReducedFrom<Node>(this);
throw new ParsingException(string.Format("Cannot apply operator {0} to the left hand side: {1}", Operator, a.ToCSS(env)), Index);
}
catch (DivideByZeroException e)
{
throw new ParsingException(e, Index);
}
catch (InvalidOperationException e)
{
throw new ParsingException(e, Index);
}
}
示例6: Evaluate
protected override Node Evaluate(Env env)
{
if (Arguments.Count == 0)
return new Quoted("", false);
Func<Node, string> stringValue = n => n is Quoted ? ((Quoted)n).Value : n.ToCSS(env);
var str = stringValue(Arguments[0]);
var args = Arguments.Skip(1).ToArray();
var i = 0;
MatchEvaluator replacement = m =>
{
var value = (m.Value == "%s") ?
stringValue(args[i++]) :
args[i++].ToCSS(env);
return char.IsUpper(m.Value[1]) ?
Uri.EscapeDataString(value) :
value;
};
str = Regex.Replace(str, "%[sda]", replacement, RegexOptions.IgnoreCase);
var quote = Arguments[0] is Quoted ? (Arguments[0] as Quoted).Quote : null;
return new Quoted(str, quote);
}
示例7: Evaluate
public override Node Evaluate(Env env)
{
if (Values.Count == 1 && string.IsNullOrEmpty(Important))
return Values[0].Evaluate(env);
return new Value(Values.Select(n => n.Evaluate(env)), Important);
}
示例8: Evaluate
protected override Node Evaluate(Env env)
{
Guard.ExpectNumArguments(1, Arguments.Count, this, Location);
var color = Guard.ExpectNode<Color>(Arguments[0], this, Location);
return new TextNode(color.ToArgb());
}
示例9: BDB43
public BDB43(string file, string table, bool create, DBFormat format, bool allowDuplicates, Env environment) {
this.env = environment;
db_create(out dbp, environment.envptr, 0);
funcs = (dbstruct)Marshal.PtrToStructure((IntPtr)((int)dbp+268), typeof(dbstruct));
uint dbflags = DB_DIRECT_DB;
if (allowDuplicates)
dbflags |= DB_DUP; // DB_DUPSORT;
funcs.set_flags(dbp, dbflags);
int type = (int)format;
uint flags = DB_DIRTY_READ; // | DB_AUTO_COMMIT;
int chmod_mode = 0;
if (create)
flags |= DB_CREATE;
// if file & database are null, db is held in-memory
// on file is taken as UTF8 (is this call right?)
int ret = funcs.open(dbp, env.Txn, file, table, type, flags, chmod_mode);
CheckError(ret);
binfmt = new Serializer();
}
示例10: AppendCSS
protected override void AppendCSS(Env env, Context context)
{
env.Output.Append(Name);
if (Rules != null)
{
env.Output
.Append(env.Compress ? "{" : " {\n")
.Push()
.AppendMany(Rules, "\n")
.Trim()
.Indent(env.Compress ? 0 : 2)
.PopAndAppend()
.Append(env.Compress ? "}" : "\n}\n");
return;
}
env.Output
.Append(" ")
.Append(Value)
.Append(";\n");
}
示例11: Find
public List<Closure> Find(Env env, Selector selector, Ruleset self)
{
self = self ?? this;
var rules = new List<Closure>();
var key = selector.ToCSS(env);
if (_lookups.ContainsKey(key))
return _lookups[key];
foreach (var rule in Rulesets().Where(rule => rule != self))
{
if (rule.Selectors && rule.Selectors.Any(selector.Match))
{
if (selector.Elements.Count > 1)
{
var remainingSelectors = new Selector(new NodeList<Element>(selector.Elements.Skip(1)));
var closures = rule.Find(env, remainingSelectors, self);
foreach (var closure in closures)
{
closure.Context.Insert(0, rule);
}
rules.AddRange(closures);
}
else
rules.Add(new Closure { Ruleset = rule, Context = new List<Ruleset> { rule } });
}
}
return _lookups[key] = rules;
}
示例12: AppendCSS
public override void AppendCSS(Env env)
{
if (!Rules.Any())
return;
((Ruleset) Evaluate(env)).AppendCSS(env, new Context());
}
示例13: UtilsManager
private UtilsManager(Env env, string serverName, string catalog)
{
_serverName = serverName;
_catalog = catalog;
this._env = env;
_valuesForCombo = new Dictionary<string, IEnumerable<string>>();
}
示例14: Evaluate
protected override Node Evaluate(Env env)
{
Guard.ExpectNumArguments(1, Arguments.Count, this, Location);
Guard.ExpectNode<TextNode>(Arguments[0], this, Location);
var argument = ((TextNode) Arguments[0]);
string rgb;
if (!argument.Value.StartsWith("#")) {
var color = Color.GetColorFromKeyword(argument.Value);
if (color != null) {
return color;
}
rgb = argument.Value;
} else {
rgb = argument.Value.TrimStart('#');
}
try
{
return new Color(rgb);
}
catch (FormatException ex)
{
throw new ParsingException(string.Format("Invalid RGB color string '{0}'", rgb), ex, Location, null);
}
}
示例15: AppendCSS
public override void AppendCSS(Env env)
{
env.Output
.Append(First)
.Append("/")
.Append(Second);
}