本文整理汇总了C#中RubyContext.CreateSnippet方法的典型用法代码示例。如果您正苦于以下问题:C# RubyContext.CreateSnippet方法的具体用法?C# RubyContext.CreateSnippet怎么用?C# RubyContext.CreateSnippet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RubyContext
的用法示例。
在下文中一共展示了RubyContext.CreateSnippet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseInteger
// This method uses the tokenizer to auto-detect the base type -- happens when agument to to_i is 0
private static object ParseInteger(RubyContext/*!*/ context, string/*!*/ str) {
bool isNegative = false;
if (str.Length == 0) {
return ScriptingRuntimeHelpers.Int32ToObject(0);
}
str = ParseSign(str, ref isNegative);
Tokenizer tokenizer = new Tokenizer(false, ErrorSink.Null);
tokenizer.Initialize(context.CreateSnippet(str, SourceCodeKind.File));
tokenizer.GetNextToken();
TokenValue value = tokenizer.TokenValue;
TokenValueType type = value.Type;
if (type == TokenValueType.Integer)
return ScriptingRuntimeHelpers.Int32ToObject(isNegative ? -value.Integer: value.Integer);
else if (type == TokenValueType.BigInteger)
return isNegative ? BigInteger.Negate(value.BigInteger) : value.BigInteger;
else
return ScriptingRuntimeHelpers.Int32ToObject(0);
}
示例2: ParseInteger
private static int ParseInteger(RubyContext/*!*/ context, string/*!*/ str) {
bool isNegative = false;
if (str[0] == '-') {
isNegative = true;
str = str.Remove(0, 1);
}
Tokenizer tokenizer = new Tokenizer(false, ErrorSink.Null);
tokenizer.Initialize(context.CreateSnippet(str, SourceCodeKind.File));
tokenizer.GetNextToken();
TokenValue value = tokenizer.TokenValue;
TokenValueType type = value.Type;
tokenizer.GetNextToken();
TokenValueType nextType = tokenizer.TokenValue.Type;
// We are only interested in the whole string being a valid Integer
if (type == TokenValueType.Integer && nextType == TokenValueType.None) {
return isNegative ? -value.Integer : value.Integer;
} else {
throw RubyExceptions.CreateTypeConversionError("String", "Integer");
}
}