本文整理汇总了C#中IronRuby.StandardLibrary.Yaml.Node类的典型用法代码示例。如果您正苦于以下问题:C# Node类的具体用法?C# Node怎么用?C# Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Node类属于IronRuby.StandardLibrary.Yaml命名空间,在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConstructYamlBool
public static object ConstructYamlBool(IConstructor ctor, Node node) {
bool result;
if (TryConstructYamlBool(ctor, node, out result)) {
return result;
}
return null;
}
示例2: AddAnchor
private void AddAnchor(string anchor, Node node) {
if (_anchors.ContainsKey(anchor)) {
_anchors[anchor] = node;
} else {
_anchors.Add(anchor, node);
}
}
示例3: AnchorNode
private void AnchorNode(Node node) {
while (node is LinkNode) {
node = ((LinkNode)node).Linked;
}
if (!IgnoreAnchor(node)) {
string anchor;
if (_anchors.TryGetValue(node, out anchor)) {
if (null == anchor) {
_anchors[node] = GenerateAnchor(node);
}
} else {
_anchors.Add(node, null);
SequenceNode seq;
MappingNode map;
if ((seq = node as SequenceNode) != null) {
foreach (Node n in seq.Nodes) {
AnchorNode(n);
}
} else if ((map = node as MappingNode) != null) {
foreach (KeyValuePair<Node, Node> e in map.Nodes) {
AnchorNode(e.Key);
AnchorNode(e.Value);
}
}
}
}
}
示例4: Serialize
public void Serialize(Node node) {
if (_closed) {
throw new SerializerException("serializer is closed");
}
_emitter.Emit(new DocumentStartEvent(_useExplicitStart, _useVersion, null));
AnchorNode(node);
SerializeNode(node, null, null);
_emitter.Emit(_useExplicitEnd ? DocumentEndEvent.ExplicitInstance : DocumentEndEvent.ImplicitInstance);
_serializedNodes.Clear();
_anchors.Clear();
_lastAnchorId = 0;
}
示例5: ConstructRubyRange
private static Range ConstructRubyRange(RubyConstructor/*!*/ ctor, Node node) {
object begin = null;
object end = null;
bool excludeEnd = false;
ScalarNode scalar = node as ScalarNode;
if (scalar != null) {
string value = scalar.Value;
int dotsIdx;
if ((dotsIdx = value.IndexOf("...")) != -1) {
begin = ParseObject(ctor, value.Substring(0, dotsIdx));
end = ParseObject(ctor, value.Substring(dotsIdx + 3));
excludeEnd = true;
} else if ((dotsIdx = value.IndexOf("..")) != -1) {
begin = ParseObject(ctor, value.Substring(0, dotsIdx));
end = ParseObject(ctor, value.Substring(dotsIdx + 2));
} else {
throw new ConstructorException("Invalid Range: " + value);
}
} else {
MappingNode mapping = node as MappingNode;
if (mapping == null) {
throw new ConstructorException("Invalid Range: " + node);
}
foreach (KeyValuePair<Node, Node> n in mapping.Nodes) {
string key = ctor.ConstructScalar(n.Key).ToString();
switch (key) {
case "begin":
begin = ctor.ConstructObject(n.Value);
break;
case "end":
end = ctor.ConstructObject(n.Value);
break;
case "excl":
TryConstructYamlBool(ctor, n.Value, out excludeEnd);
break;
default:
throw new ConstructorException(string.Format("'{0}' is not allowed as an instance variable name for class Range", key));
}
}
}
var comparisonStorage = new BinaryOpStorage(ctor.GlobalScope.Context);
return new Range(comparisonStorage, ctor.GlobalScope.Context, begin, end, excludeEnd);
}
示例6: ConstructYamlBinary
public static byte[] ConstructYamlBinary(IConstructor ctor, Node node) {
string val = ctor.ConstructScalar(node).ToString().Replace("\r", "").Replace("\n", "");
return Convert.FromBase64String(val);
}
示例7: ConstructRubyScalar
private static object ConstructRubyScalar(RubyConstructor/*!*/ ctor, Node node) {
object value = ctor.ConstructScalar(node);
if (value == null) {
return value;
}
string str = value as string;
if (str != null) {
return MutableString.Create(str, RubyEncoding.UTF8);
}
return value;
}
示例8: GenerateAnchor
private string GenerateAnchor(Node node) {
return string.Format(_anchorTemplate, ++_lastAnchorId);
}
示例9: IgnoreAnchor
protected virtual bool IgnoreAnchor(Node node) {
// This is possibly Ruby specific.
// but it didn't seem worth subclassing Serializer for this one method
return !(node is CollectionNode);
//return false;
}
示例10: ConstructRubyStruct
private static object ConstructRubyStruct(RubyConstructor/*!*/ ctor, string className, Node node) {
MappingNode mapping = node as MappingNode;
if (mapping == null) {
throw new ConstructorException("can only construct struct from mapping node");
}
RubyContext context = ctor.GlobalScope.Context;
RubyModule module;
RubyClass cls;
if (context.TryGetModule(ctor.GlobalScope, className, out module)) {
cls = module as RubyClass;
if (cls == null) {
throw new ConstructorException("Struct type name must be Ruby class");
}
} else {
RubyModule structModule = context.GetModule(typeof(RubyStruct));
cls = RubyUtils.GetConstant(ctor.GlobalScope, structModule, className, false) as RubyClass;
if (cls == null) {
throw new ConstructorException(String.Format("Cannot find struct class \"{0}\"", className));
}
}
RubyStruct newStruct = RubyStruct.Create(cls);
foreach (var pair in ctor.ConstructMapping(mapping)) {
RubyStructOps.SetValue(newStruct, SymbolTable.StringToId(pair.Key.ToString()), pair.Value);
}
return newStruct;
}
示例11: ConstructRubyTimestampYMD
private static object ConstructRubyTimestampYMD(RubyConstructor/*!*/ ctor, Node node) {
ScalarNode scalar = node as ScalarNode;
if (scalar == null) {
throw new ConstructorException("Can only contruct timestamp from scalar node.");
}
Match match = BaseConstructor.YmdRegex.Match(scalar.Value);
if (match.Success) {
int year_ymd = Int32.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture);
int month_ymd = Int32.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture);
int day_ymd = Int32.Parse(match.Groups[3].Value, CultureInfo.InvariantCulture);
RubyModule module;
if (ctor.GlobalScope.Context.TryGetModule(ctor.GlobalScope, "Date", out module)) {
return ctor._newSite.Target(ctor._newSite, module, year_ymd, month_ymd, day_ymd);
} else {
throw new ConstructorException("Date class not found.");
}
}
throw new ConstructorException("Invalid tag:yaml.org,2002:timestamp#ymd value.");
}
示例12: TryConstructYamlBool
public static bool TryConstructYamlBool(IConstructor ctor, Node node, out bool result) {
if (BOOL_VALUES.TryGetValue(ctor.ConstructScalar(node).ToString(), out result)) {
return true;
}
return false;
}
示例13: ConstructYamlOmap
public static object ConstructYamlOmap(IConstructor ctor, Node node) {
return ctor.ConstructPairs(node);
}
示例14: ConstructYamlNull
public static object ConstructYamlNull(IConstructor ctor, Node node) {
return null;
}
示例15: ConstructYamlInt
public static object ConstructYamlInt(IConstructor ctor, Node node) {
string value = ctor.ConstructScalar(node).ToString().Replace("_","").Replace(",","");
int sign = +1;
char first = value[0];
if(first == '-') {
sign = -1;
value = value.Substring(1);
} else if(first == '+') {
value = value.Substring(1);
}
int @base = 10;
if (value == "0") {
return 0;
} else if (value.StartsWith("0b")) {
value = value.Substring(2);
@base = 2;
} else if (value.StartsWith("0x")) {
value = value.Substring(2);
@base = 16;
} else if (value.StartsWith("0")) {
value = value.Substring(1);
@base = 8;
} else if (value.IndexOf(':') != -1) {
string[] digits = value.Split(':');
int bes = 1;
int val = 0;
for (int i = 0, j = digits.Length; i < j; i++) {
val += (int.Parse(digits[(j - i) - 1]) * bes);
bes *= 60;
}
return sign*val;
}
try {
// LiteralParser.ParseInteger delegate handles parsing & conversion to BigInteger (if needed)
return LiteralParser.ParseInteger(sign, value, @base);
} catch (Exception e) {
throw new ConstructorException(string.Format("Could not parse integer value: '{0}' (sign {1}, base {2})", value, sign, @base), e);
}
}