本文整理汇总了C#中NETRuby.NetRuby.ConvertType方法的典型用法代码示例。如果您正苦于以下问题:C# NetRuby.ConvertType方法的具体用法?C# NetRuby.ConvertType怎么用?C# NetRuby.ConvertType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NETRuby.NetRuby
的用法示例。
在下文中一共展示了NetRuby.ConvertType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Float
// as rb_Float
static public RFloat Float(NetRuby rb, object o)
{
if (o == null || o == rb.oNil)
return new RFloat(rb, 0.0);
if (o is int)
return new RFloat(rb, (double)(int)o);
if (o is long)
return new RFloat(rb, (double)(long)o);
if (o is double)
return new RFloat(rb, (double)o);
if (o is RFloat)
return (RFloat)o;
if (o is RBignum)
return new RFloat(rb, ((RBignum)o).Big2Dbl());
string s = null;
if (o is string)
s = (string)o;
else if (o is RString)
s = ((RString)o).ToString();
if (s != null)
{
s = s.Trim().Replace("_", "");
try
{
return new RFloat(rb, Convert.ToDouble(s));
}
catch
{
throw new eArgError("Invalid valud for Float: \"" + s + "\"");
}
}
return (RFloat)rb.ConvertType(o, typeof(RFloat), "Float", "to_f");
}
示例2: ToLong
public static long ToLong(NetRuby ruby, object o)
{
if (o == null)
{
throw new eTypeError("no implicit conversion from nil");
}
if (o is int) return (long)(int)o;
if (o is uint) return (long)(uint)o;
if (o is long) return (long)o;
if (o is RNumeric)
return ((RNumeric)o).ToLong();
if (o is string || o is RString)
throw new eTypeError("no implicit conversion from string");
if (o is bool || o is RBool)
throw new eTypeError("no implicit conversion from boolean");
RFixnum f = (RFixnum)ruby.ConvertType(o, typeof(RFixnum), "Integer", "to_int");
return (long)f.ToLong();
}
示例3: StringToRString
public static RString StringToRString(NetRuby ruby, object s)
{
return (RString)ruby.ConvertType(s, typeof(RString), "String", "to_str");
}