这样写就对了,虽然还不太理解
 - static Object MathMethod(String methodName, ResultBuffer rb)
- {
- TypedValue[] values = rb.AsArray();
- if (rb != null)
- {
- if (values.Count() == 1 && values[0].TypeCode == (int)LispDataType.Double)
- {
- Double num = (Double)Convert.ToDouble(values[0].Value);
- Type t = Type.GetType("System.Math");
- Type[] parameterTypes = new Type[1];
- parameterTypes[0] = Type.GetType("System.Double");
- MethodInfo method = t.GetMethod(methodName, parameterTypes);
- return (Object)method.Invoke(null, new Object[] { num });
- }
- else
- {
- return null;
- }
- }
- else
- {
- return null;
- }
- }
- //反正弦函数
- [LispFunction("math_asin")]
- public Object MathAtan(ResultBuffer rb)
- {
- return MathMethod("Asin", rb);
- }
- //反余弦函数
- [LispFunction("math_acos")]
- public Object MathAcos(ResultBuffer rb)
- {
- return MathMethod("Acos", rb);
- }
- //正切函数
- [LispFunction("math_tan")]
- public Object MathTan(ResultBuffer rb)
- {
- return MathMethod( "Tan",rb);
- }
- //指定角度的双曲正弦值
- [LispFunction("math_sinh")]
- public Object MathSinh(ResultBuffer rb)
- {
- return MathMethod( "Sinh",rb);
- }
- //指定角度的双曲余弦值
- [LispFunction("Math_Cosh")]
- public Object MathCosh(ResultBuffer rb)
- {
- return MathMethod("Cosh", rb);
- }
|