예제 #1
0
        private static void onRegistered(MethodInfo method, RunAtAttribute runAt, int index)
        {
            if (method.IsConstructor) ThrowHelper.Throw("{0} cannot be called @sever since it is constructor.", method.GetSignature());
            if (method.IsVirtual) ThrowHelper.Throw("{0} cannot be called @sever since it is virtual.", method.GetSignature());
            sb.Append("case ").Append(index).Append(":try{");
            if (!method.IsStatic || method.GetParameters().Length > 0) {
                sb.Append("args=Serializer.Deserialize(context");
                if (!method.IsStatic)
                    sb.Append(",typeof(").Append(Name(method.DeclaringType)).Append(')');
                foreach (var param in method.GetParameters()) {
                    sb.Append(",typeof(").Append(Name(param.ParameterType)).Append(')');
                }
                sb.Append(");");
            }
            if (method.ReturnParameter.ParameterType != typeof(void))
                sb.Append("context.Response.Write(\"(\"+Serializer.Serialize(");
            if (method.IsSpecialName) {
                if (method.Name.StartsWith("get_")) {
                    appendThisOrType(method);
                    sb.Append('.').Append(method.Name.Substring(4));
                } else if (method.Name.StartsWith("set_")) {
                    appendThisOrType(method);
                    sb.Append('.').Append(method.Name.Substring(4)).Append("=args[");
                    sb.Append(method.IsStatic ? 0 : 1);
                    sb.Append("]");
                } else {
                    ThrowHelper.Throw("Special name method {0} cannot be called @server.", method.GetSignature());
                }
            } else {
                appendThisOrType(method);
                sb.Append('.').Append(method.Name).Append('(');
                var parameters = method.GetParameters();
                if (parameters.Length > 0) {
                    for (int j = 0; j < parameters.Length; ++j) {
                        sb.Append('(').Append(Name(parameters[j].ParameterType)).Append(")args[").Append(method.IsStatic ? j : (j + 1)).Append("],");
                    }
                    --sb.Length;
                }
                sb.Append(")");
            }
            if (method.ReturnParameter.ParameterType != typeof(void)) {
                sb.Append(")+\")\")");
            } else {
                sb.Append(";context.Response.Write(\"0\")");
            }
            sb.Append(";}catch(Exception e){context.Response.Write(");

            if (runAt.HideExceptionMessage) {
                sb.Append("\"throw Error()\"");
            } else {
                sb.Append("\"throw Error(\"+Serializer.Serialize(e.Message)+\")\"");
            }
            sb.Append(");}break;");
        }
예제 #2
0
 public static int Register(MethodInfo info, RunAtAttribute runAt)
 {
     int index;
     if (!used.TryGetValue(info, out index)) {
         index = used.Count;
         used[info] = index;
         onRegistered(info, runAt, index);
     }
     return index;
 }