public static object ConstructYamlTimestampYmd(BaseConstructor ctor, Node node) { ScalarNode scalar = node as ScalarNode; if (scalar == null) { throw new ConstructorException("can only contruct timestamp from scalar node"); } Match match = YmdRegex.Match(scalar.Value); if (match.Success) { int year_ymd = int.Parse(match.Groups[1].Value); int month_ymd = int.Parse(match.Groups[2].Value); int day_ymd = int.Parse(match.Groups[3].Value); // TODO: local/utc/... return(new RubyTime(new DateTime(year_ymd, month_ymd, day_ymd, 0, 0, 0, 0, DateTimeKind.Local))); } throw new ConstructorException("Invalid tag:yaml.org,2002:timestamp#ymd value."); }
public static object ConstructCliObject(BaseConstructor 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(ReflectionUtils.EmptyTypes).Invoke(null); foreach (KeyValuePair <object, object> e in ctor.ConstructMapping(node)) { string name = e.Key.ToString(); name = "" + name[0].ToString().ToUpperInvariant() + name.Substring(1); PropertyInfo prop = type.GetInheritedProperties(name).First(); prop.SetValue(result, Convert.ChangeType(e.Value, prop.PropertyType, CultureInfo.InvariantCulture), null); } return(result); } catch (Exception e) { throw new ConstructorException("Can't construct a CLI object from class: " + pref, e); } }
private static MutableString /*!*/ ConstructRubyBinary(RubyConstructor /*!*/ ctor, Node /*!*/ node) { return(MutableString.CreateBinary(BaseConstructor.ConstructYamlBinary(ctor, node))); }
public object Construct(BaseConstructor ctor, Node node) { return(Construct(ctor, node.Tag, node)); }
public static byte[] ConstructYamlBinary(BaseConstructor ctor, Node node) { string val = ctor.ConstructScalar(node).Replace("\r", "").Replace("\n", ""); return(Convert.FromBase64String(val)); }
public static object ConstructYamlTimestamp(BaseConstructor ctor, Node node) { ScalarNode scalar = node as ScalarNode; if (scalar == null) { throw new ConstructorException("can only contruct timestamp from scalar node"); } Match match = TimestampRegex.Match(scalar.Value); if (!match.Success) { return(ctor.ConstructPrivateType(node)); } string year_s = match.Groups[1].Value; string month_s = match.Groups[2].Value; string day_s = match.Groups[3].Value; string hour_s = match.Groups[4].Value; string min_s = match.Groups[5].Value; string sec_s = match.Groups[6].Value; string fract_s = match.Groups[7].Value; string utc = match.Groups[8].Value; string timezoneh_s = match.Groups[9].Value; string timezonem_s = match.Groups[10].Value; bool isUtc = utc == "Z" || utc == "z"; DateTime dt = new DateTime( year_s != "" ? Int32.Parse(year_s, CultureInfo.InvariantCulture) : 0, month_s != "" ? Int32.Parse(month_s, CultureInfo.InvariantCulture) : 1, day_s != "" ? Int32.Parse(day_s, CultureInfo.InvariantCulture) : 1, hour_s != "" ? Int32.Parse(hour_s, CultureInfo.InvariantCulture) : 0, min_s != "" ? Int32.Parse(min_s, CultureInfo.InvariantCulture) : 0, sec_s != "" ? Int32.Parse(sec_s, CultureInfo.InvariantCulture) : 0, DateTimeKind.Utc ); if (!String.IsNullOrEmpty(fract_s)) { long fract = Int32.Parse(fract_s, CultureInfo.InvariantCulture); if (fract > 0) { while (fract < 1000000) { fract *= 10; } dt = dt.AddTicks(fract); } } if (!isUtc) { if (timezoneh_s != "" || timezonem_s != "") { int zone = 0; int sign = +1; if (timezoneh_s != "") { if (timezoneh_s.StartsWith("-", StringComparison.Ordinal)) { sign = -1; } zone += Int32.Parse(timezoneh_s.Substring(1), CultureInfo.InvariantCulture) * 3600000; } if (timezonem_s != "") { zone += Int32.Parse(timezonem_s, CultureInfo.InvariantCulture) * 60000; } dt = dt.AddMilliseconds(-sign * zone); } dt = RubyTime.ToLocalTime(dt); } return(new RubyTime(dt)); }
public static Hash ConstructYamlMap(BaseConstructor /*!*/ ctor, Node /*!*/ node) { return(ctor.ConstructMapping(node)); }
public static object constructUndefined(BaseConstructor /*!*/ ctor, Node /*!*/ node) { throw new ConstructorException("could not determine a constructor for the tag: " + node.Tag); }
public static RubyArray ConstructYamlSeq(BaseConstructor /*!*/ ctor, Node /*!*/ node) { return(ctor.ConstructSequence(node)); }
public static string ConstructYamlStr(BaseConstructor /*!*/ ctor, Node /*!*/ node) { return(ctor.ConstructScalar(node)); }
public static ICollection <object> ConstructYamlSet(BaseConstructor /*!*/ ctor, Node /*!*/ node) { return(ctor.ConstructMapping(node).Keys); }
public static object ConstructYamlPairs(BaseConstructor /*!*/ ctor, Node /*!*/ node) { return(ConstructYamlOmap(ctor, node)); }
public static object ConstructYamlNull(BaseConstructor /*!*/ ctor, Node /*!*/ node) { return(null); }