本文整理汇总了C#中IronRuby.StandardLibrary.Yaml.Node类的典型用法代码示例。如果您正苦于以下问题:C# Node类的具体用法?C# Node怎么用?C# Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Node类属于IronRuby.StandardLibrary.Yaml命名空间,在下文中一共展示了Node类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ConstructYamlBool
public static object ConstructYamlBool(IConstructor ctor, Node node) {
bool result;
if (TryConstructYamlBool(ctor, node, out result)) {
return result;
}
return null;
}
开发者ID:bclubb,项目名称:ironruby,代码行数:7,代码来源:SafeConstructor.cs
示例2: AddAnchor
private void AddAnchor(string anchor, Node node) {
if (_anchors.ContainsKey(anchor)) {
_anchors[anchor] = node;
} else {
_anchors.Add(anchor, node);
}
}
开发者ID:jschementi,项目名称:iron,代码行数:7,代码来源:Composer.cs
示例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);
}
}
}
}
}
开发者ID:bclubb,项目名称:ironruby,代码行数:28,代码来源:Serializer.cs
示例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;
}
开发者ID:rudimk,项目名称:dlr-dotnet,代码行数:13,代码来源:Serializer.cs
示例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);
}
开发者ID:atczyc,项目名称:ironruby,代码行数:44,代码来源:RubyConstructor.cs
示例6: ConstructYamlBinary
public static byte[] ConstructYamlBinary(IConstructor ctor, Node node) {
string val = ctor.ConstructScalar(node).ToString().Replace("\r", "").Replace("\n", "");
return Convert.FromBase64String(val);
}
开发者ID:bclubb,项目名称:ironruby,代码行数:4,代码来源:SafeConstructor.cs
示例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;
}
开发者ID:atczyc,项目名称:ironruby,代码行数:11,代码来源:RubyConstructor.cs
示例8: GenerateAnchor
private string GenerateAnchor(Node node) {
return string.Format(_anchorTemplate, ++_lastAnchorId);
}
开发者ID:rudimk,项目名称:dlr-dotnet,代码行数:3,代码来源:Serializer.cs
示例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;
}
开发者ID:rudimk,项目名称:dlr-dotnet,代码行数:6,代码来源:Serializer.cs
示例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;
}
开发者ID:atczyc,项目名称:ironruby,代码行数:28,代码来源:RubyConstructor.cs
示例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.");
}
开发者ID:atczyc,项目名称:ironruby,代码行数:21,代码来源:RubyConstructor.cs
示例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;
}
开发者ID:bclubb,项目名称:ironruby,代码行数:6,代码来源:SafeConstructor.cs
示例13: ConstructYamlOmap
public static object ConstructYamlOmap(IConstructor ctor, Node node) {
return ctor.ConstructPairs(node);
}
开发者ID:bclubb,项目名称:ironruby,代码行数:3,代码来源:SafeConstructor.cs
示例14: ConstructYamlNull
public static object ConstructYamlNull(IConstructor ctor, Node node) {
return null;
}
开发者ID:bclubb,项目名称:ironruby,代码行数:3,代码来源:SafeConstructor.cs
示例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);
}
}
开发者ID:bclubb,项目名称:ironruby,代码行数:40,代码来源:SafeConstructor.cs
示例16: ConstructCliObject
public static object ConstructCliObject(IConstructor ctor, string pref, Node node) {
// TODO: should this use serialization or some more standard CLR mechanism?
// (it is very ad-hoc)
// TODO: use DLR APIs instead of reflection
try {
Type type = Type.GetType(pref);
object result = type.GetConstructor(Type.EmptyTypes).Invoke(null);
foreach (KeyValuePair<object, object> e in ctor.ConstructMapping(node)) {
string name = e.Key.ToString();
name = "" + char.ToUpper(name[0]) + name.Substring(1);
PropertyInfo prop = type.GetProperty(name);
prop.SetValue(result, Convert.ChangeType(e.Value, prop.PropertyType), null);
}
return result;
} catch (Exception e) {
throw new ConstructorException("Can't construct a CLI object from class: " + pref, e);
}
}
开发者ID:bclubb,项目名称:ironruby,代码行数:21,代码来源:SafeConstructor.cs
示例17: ConstructSpecializedMap
public static object ConstructSpecializedMap(IConstructor ctor, string pref, Node node) {
Hash result = null;
try {
result = (Hash)Type.GetType(pref).GetConstructor(Type.EmptyTypes).Invoke(null);
} catch (Exception e) {
throw new ConstructorException("Can't construct a mapping from class: " + pref, e);
}
foreach (KeyValuePair<object, object> e in ctor.ConstructMapping(node)) {
result.Add(e.Key, e.Value);
}
return result;
}
开发者ID:bclubb,项目名称:ironruby,代码行数:12,代码来源:SafeConstructor.cs
示例18: ConstructSpecializedSequence
public static object ConstructSpecializedSequence(IConstructor ctor, string pref, Node node) {
RubyArray result = null;
try {
result = (RubyArray)Type.GetType(pref).GetConstructor(Type.EmptyTypes).Invoke(null);
} catch (Exception e) {
throw new ConstructorException("Can't construct a sequence from class: " + pref, e);
}
foreach (object x in ctor.ConstructSequence(node)) {
result.Add(x);
}
return result;
}
开发者ID:bclubb,项目名称:ironruby,代码行数:12,代码来源:SafeConstructor.cs
示例19: ConstructRubyRegexp
private static RubyRegex ConstructRubyRegexp(RubyConstructor/*!*/ ctor, Node node) {
ScalarNode scalar = node as ScalarNode;
if (node == null) {
throw RubyExceptions.CreateTypeError("Can only create regex from scalar node");
}
Match match = _regexPattern.Match(scalar.Value);
if (!match.Success) {
throw new ConstructorException("Invalid Regular expression: \"" + scalar.Value + "\"");
}
RubyRegexOptions options = new RubyRegexOptions();
foreach (char c in match.Groups["opts"].Value) {
switch (c) {
case 'i': options |= RubyRegexOptions.IgnoreCase; break;
case 'x': options |= RubyRegexOptions.Extended; break;
case 'm': options |= RubyRegexOptions.Multiline; break;
case 'o': break;
case 'n': options |= RubyRegexOptions.FIXED; break;
case 'e': options |= RubyRegexOptions.EUC; break;
case 's': options |= RubyRegexOptions.SJIS; break;
case 'u': options |= RubyRegexOptions.UTF8; break;
default:
throw new ConstructorException("Unknown regular expression option: '" + c + "'");
}
}
// TODO: encoding (ignore kcode on 1.9, string enc?):
return new RubyRegex(MutableString.CreateMutable(match.Groups["expr"].Value, RubyEncoding.UTF8), options);
}
开发者ID:atczyc,项目名称:ironruby,代码行数:27,代码来源:RubyConstructor.cs
示例20: ConstructRubyString
/// <summary>
/// Returns MutableString or RubySymbol.
/// </summary>
private static object ConstructRubyString(RubyConstructor/*!*/ ctor, Node/*!*/ node) {
ScalarNode scalar = (ScalarNode)node;
string value = ctor.ConstructScalar(node);
if (value == null) {
return null;
}
if (value.Length > 1 && value[0] == ':' && scalar.Style == ScalarQuotingStyle.None) {
return ctor.GlobalScope.Context.CreateAsciiSymbol(value.Substring(1));
}
return MutableString.CreateMutable(value, ctor.RubyEncoding);
}
开发者ID:jschementi,项目名称:iron,代码行数:17,代码来源:RubyConstructor.cs
注:本文中的IronRuby.StandardLibrary.Yaml.Node类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论