示例#1
0
        public void CreateActionJavaScript(string methodName, StringCollection code, StringCollection parameters, string returnReceiver)
        {
            IJavascriptType ijt = this.ObjectInstance as IJavascriptType;

            if (ijt == null)
            {
                Type t = this.ObjectInstance as Type;
                if (t != null)
                {
                    if (t.GetInterface("IJavascriptType") != null)
                    {
                        ijt = Activator.CreateInstance(t) as IJavascriptType;
                    }
                }
            }
            if (ijt != null)
            {
                string m = ijt.GetJavascriptMethodRef(this.GetJavaScriptReferenceCode(code), methodName, code, parameters);
                if (!string.IsNullOrEmpty(m))
                {
                    if (string.IsNullOrEmpty(returnReceiver))
                    {
                        code.Add(string.Format(CultureInfo.InvariantCulture, "{0};\r\n", m));
                    }
                    else
                    {
                        code.Add(string.Format(CultureInfo.InvariantCulture, "{0}={1};\r\n", returnReceiver, m));
                    }
                    return;
                }
            }
            WebPageCompilerUtility.CreateActionJavaScript(this.GetJavaScriptReferenceCode(code), methodName, code, parameters, returnReceiver);
        }
示例#2
0
        public void CreateActionJavaScript(string methodName, StringCollection code, StringCollection parameters, string returnReceiver)
        {
            if (ClassType != null && _type.BaseClassType.GetInterface("IJavascriptType") != null)
            {
                IJavascriptType js = Activator.CreateInstance(_type.BaseClassType) as IJavascriptType;
                string          v  = js.GetJavascriptMethodRef(this.CodeName, methodName, code, parameters);

                if (string.IsNullOrEmpty(returnReceiver))
                {
                }
                else
                {
                    code.Add(returnReceiver);
                    code.Add("=");
                }
                code.Add(v);
                code.Add(";\r\n");
            }
            else if (this.BaseClassType.IsArray)
            {
                if (string.CompareOrdinal(methodName, "Set") == 0)
                {
                    code.Add(CodeName);
                    code.Add("[");
                    code.Add(parameters[0]);
                    code.Add("]=");
                    code.Add(parameters[1]);
                    code.Add(";\r\n");
                }
                else if (string.CompareOrdinal(methodName, "Get") == 0)
                {
                    if (!string.IsNullOrEmpty(returnReceiver))
                    {
                        code.Add(string.Format(CultureInfo.InvariantCulture,
                                               "{0}={1}[{2}];\r\n", returnReceiver, this.GetJavaScriptReferenceCode(code), parameters[0]));
                    }
                }
            }
            else
            {
                WebPageCompilerUtility.CreateActionJavaScript(this.CodeName, methodName, code, parameters, returnReceiver);
            }
        }
 public override void CreateJavaScript(StringCollection sb, StringCollection parameters, string returnReceiver)
 {
     if (_returnReceiver != null)
     {
         if (_returnReceiver.BaseClassType.GetInterface("IJavascriptType") != null)
         {
             IJavascriptType js = Activator.CreateInstance(_returnReceiver.BaseClassType) as IJavascriptType;
             string          v  = js.GetJavascriptMethodRef(_returnReceiver.CodeName, ".ctor", sb, parameters);
             sb.Add(_returnReceiver.CodeName);
             sb.Add("=");
             sb.Add(v);
             sb.Add(";\r\n");
             return;
         }
     }
     if (_mif != null && _returnReceiver != null)
     {
         if (_mif.ReflectedType != null && _mif.ReflectedType.IsArray)
         {
             sb.Add(_returnReceiver.CodeName);
             sb.Add("=new Array();\r\n");
             if (parameters != null && parameters.Count > 0)
             {
                 string idx = string.Format(CultureInfo.InvariantCulture, "i{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                 sb.Add("for(var ");
                 sb.Add(idx);
                 sb.Add("=0;");
                 sb.Add(idx);
                 sb.Add("<");
                 sb.Add(parameters[0]);
                 sb.Add(";");
                 sb.Add(idx);
                 sb.Add("++) {\r\n");
                 sb.Add(_returnReceiver.CodeName);
                 sb.Add(".push(null);\r\n");
                 sb.Add("}\r\n");
             }
         }
     }
 }