本文整理汇总了C#中ScriptProcessor.CreateNumber方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptProcessor.CreateNumber方法的具体用法?C# ScriptProcessor.CreateNumber怎么用?C# ScriptProcessor.CreateNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScriptProcessor
的用法示例。
在下文中一共展示了ScriptProcessor.CreateNumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToNumber
internal override SNumber ToNumber(ScriptProcessor processor)
{
if (Value)
return processor.CreateNumber(1);
else
return processor.CreateNumber(0);
}
示例2: constructor
private static SObject constructor(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
{
var obj = (SError)instance;
if (parameters.Length > 0)
{
SString message;
if (parameters[0] is SString)
message = (SString)parameters[0];
else
message = parameters[0].ToString(processor);
obj.Members[MEMBER_NAME_MESSAGE].Data = message;
}
if (parameters.Length > 1)
{
SString errorType;
if (parameters[1] is SString)
errorType = (SString)parameters[1];
else
errorType = parameters[1].ToString(processor);
obj.Members[MEMBER_NAME_TYPE].Data = errorType;
}
else
{
obj.Members[MEMBER_NAME_TYPE].Data = processor.CreateString("UserError");
}
if (parameters.Length > 2)
{
SNumber errorLine;
if (parameters[2] is SNumber)
errorLine = (SNumber)parameters[2];
else
errorLine = parameters[2].ToNumber(processor);
obj.Members[MEMBER_NAME_LINE].Data = errorLine;
}
else
{
obj.Members[MEMBER_NAME_LINE].Data = processor.CreateNumber(-1);
}
return obj;
}
示例3: ToNumber
internal override SNumber ToNumber(ScriptProcessor processor)
{
return processor.CreateNumber(Value);
}
示例4: NegateNumber
/// <summary>
/// Multiplies an object with -1.
/// </summary>
internal static SObject NegateNumber(ScriptProcessor processor, SObject obj)
{
double number;
if (obj is SNumber)
number = ((SNumber)obj).Value;
else
number = obj.ToNumber(processor).Value;
return processor.CreateNumber(number * -1);
}
示例5: DecrementOperator
internal static string DecrementOperator(ScriptProcessor processor, SObject obj)
{
// Only variables can be decremented:
if (obj is SVariable)
{
var svar = (SVariable)obj;
svar.Data = processor.CreateNumber(svar.Data.ToNumber(processor).Value - 1D);
return svar.Identifier;
}
else
{
processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_INVALID_DECREMENT);
return "";
}
}
示例6: ToNumber
internal override SNumber ToNumber(ScriptProcessor processor)
{
if (Value.Trim() == "")
{
return processor.CreateNumber(0);
}
else
{
var dblResult = 0D;
if (double.TryParse(Value, out dblResult))
{
return processor.CreateNumber(dblResult);
}
else
{
return processor.CreateNumber(double.NaN);
}
}
}
示例7: SetValue
/// <summary>
/// Sets the value and updates the length property.
/// </summary>
internal void SetValue(ScriptProcessor processor, string value)
{
Value = value;
var length = processor.CreateNumber(value.Length);
//TODO: add length to prototype.
Members[STRING_LENGTH_PROPERTY_NAME].ForceSetData(length);
}
示例8: Length
public static SObject Length(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
{
var str = instance as SString;
return processor.CreateNumber(str.Value.Length);
}
示例9: LastIndexOf
public static SObject LastIndexOf(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
{
if (TypeContract.Ensure(parameters, typeof(SString)))
{
var str = instance as SString;
var search = parameters[0] as SString;
if (!str.Value.Contains(search.Value) || search.Value == "")
return processor.CreateNumber(-1);
return processor.CreateNumber(str.Value.LastIndexOf(search.Value));
}
return processor.Undefined;
}
示例10: UpdateLength
/// <summary>
/// Updates the "length" property of this object.
/// </summary>
public void UpdateLength(ScriptProcessor processor)
{
//TODO: Add length to prototype
Members["length"] = new SVariable("length", processor.CreateNumber(ArrayMembers.Length)) { IsReadOnly = true };
}
示例11: TranslateNumber
private static SObject TranslateNumber(ScriptProcessor processor, double dblIn)
{
return processor.CreateNumber(dblIn);
}
示例12: Length
public static SObject Length(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
{
var arr = (SArray)instance;
return processor.CreateNumber(arr.ArrayMembers.Length);
}
示例13: Count
public static SObject Count(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
{
if (parameters.Length == 0)
{
var arr = (SArray)instance;
return processor.CreateNumber(arr.ArrayMembers.Length);
}
if (parameters.Length >= 1)
{
var arr = (SArray)instance;
var comparer = (SFunction)Unbox(parameters[0]);
var result = arr.ArrayMembers.Count(m => ((SBool)comparer.Call(processor, This, This, new[] { m })).Value);
return processor.CreateNumber(result);
}
return processor.Undefined;
}
示例14: Where
public static SObject Where(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
{
if (parameters.Length >= 1)
{
var arr = (SArray)instance;
var comparer = (SFunction)Unbox(parameters[0]);
var results = arr.ArrayMembers.Where((m, i) => ((SBool)comparer.Call(processor, This, This, new[] {m, processor.CreateNumber(i)})).Value);
return processor.CreateArray(results.ToArray());
}
return processor.Undefined;
}
示例15: ToNumber
/// <summary>
/// Returns the number representation of this object.
/// </summary>
internal virtual SNumber ToNumber(ScriptProcessor processor)
{
return processor.CreateNumber(double.NaN);
}