예제 #1
0
        private static void parseForeachStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsForeachStatement fes = (CsForeachStatement)pStatement;

            Expression ex   = pCreator.Parse(fes.expression);
            string     type = JsHelpers.Convert(Helpers.GetType(fes.type));

            pSb.AppendLine();

            _enumCount++;
            string enumName = String.Format(@"__ie{0}", _enumCount);

            pSb.AppendFormat("var {0}:IEnumerator = {1}.GetEnumerator();",
                             enumName, ex.Value);
            pSb.AppendLine();
            pSb.AppendFormat("while ({0}.MoveNext()){{", enumName);
            pSb.AppendLine();

            pSb.AppendFormat("\tvar {1}:{2} = {0}.get_Current() as {2};",
                             enumName,
                             fes.identifier.identifier,
                             type
                             );

            pSb.AppendLine();


            ParseNode(fes.statement, pSb, pCreator);
            pSb.AppendLine("}");
            pSb.AppendLine();
        }
예제 #2
0
        private static void parseForeachStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsForeachStatement fes = (CsForeachStatement)pStatement;

            Expression ex   = pCreator.Parse(fes.expression);
            string     type = As3Helpers.Convert(Helpers.GetType(fes.type));

            pSb.AppendLine();

            TheClass theClass = TheClassFactory.Get(ex.Type, pCreator);

            if (ex.Type.type == cs_entity_type.et_array || ex.IsAs3Generic ||
                (theClass != null && @"System.Array".Equals(theClass.FullName)))                     //foreach
            {
                pSb.AppendFormat("for each(var {0}:{1} in {2}){{",
                                 fes.identifier.identifier,
                                 type,
                                 ex.Value);
                pSb.AppendLine();
            }
            else if (ex.Type.type == cs_entity_type.et_object ||
                     ex.Type.type == cs_entity_type.et_generic_param ||
                     (theClass != null && @"flash.utils.Dictionary".Equals(theClass.FullName)))
            {
                pSb.AppendFormat("for (var {0}:{1} in {2}){{",
                                 fes.identifier.identifier,
                                 type,
                                 ex.Value);

                pSb.AppendLine();
                if (ex.Type.type == cs_entity_type.et_object)
                {
                    pSb.AppendFormat("	if (!{1}.hasOwnProperty({0})) continue;",
                                     fes.identifier.identifier,
                                     ex.Value
                                     );
                }

                pSb.AppendLine();
            }
            else
            {
                _enumCount++;
                //TheClass theClass = TheClassFactory.Get(fes.expression.entity_typeref);

                string enumName = String.Format(@"__ie{0}", _enumCount);
                pSb.AppendFormat("var {0}:IEnumerator = {1}.GetEnumerator();", enumName, ex.Value);
                pSb.AppendLine();
                pSb.AppendFormat("while ({0}.MoveNext()){{", enumName);
                pSb.AppendLine();

                pSb.AppendFormat("\tvar {1}:{2} = {0}.get_Current() as {2};",
                                 enumName,
                                 fes.identifier.identifier,
                                 type
                                 );

                pSb.AppendLine();
            }

            ParseNode(fes.statement, pSb, pCreator);
            pSb.AppendLine("}");
            pSb.AppendLine();
        }