Exemple #1
0
        public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
        {
            //expression "." identifier (type-argument-list?)
            CsPrimaryExpressionMemberAccess ex = (CsPrimaryExpressionMemberAccess)pStatement;
            string name;
            bool   renamed = Helpers.GetRealName(ex, ex.identifier.identifier, out name);

            if (renamed)
            {
                return(new Expression(name, pStatement.entity_typeref));
            }

            CsEntityProperty p          = ex.entity as CsEntityProperty;
            bool             isInternal = false;

            if (p != null && p.decl != null)
            {
                TheClass theClass = TheClassFactory.Get(p, pCreator);
                TheClass parent   = theClass;

                //Am I extending a standard flash class? Do not rename then...
                bool isStandardGetSet = false;
                while (parent.Base != null)
                {
                    isStandardGetSet |= parent.FullName.StartsWith("flash.");
                    parent            = parent.Base;
                }

                if (!isStandardGetSet)
                {
                    TheProperty theProperty = theClass.GetProperty((CsProperty)p.decl);
                    if (theProperty != null)
                    {
                        if (ex.parent is CsAssignmentExpression)
                        {
                            //setter
                            isInternal = true;
                            name       = "set_" + name + "({0})";
                        }
                        else
                        {
                            //getter, rename
                            name = "get_" + name + "()";
                        }
                    }
                }
            }
            else if (ex.ec == expression_classification.ec_event_access)                //remove eventhandler name
            {
                name = string.Empty;
            }

            return(new Expression(
                       pCreator.Parse(ex.expression).Value + "." + name,
                       pStatement.entity_typeref,
                       isInternal
                       ));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            DataSet workersDataSet = new DataSet();

            workersDataSet.ReadXml(MapPath("~/App_Data/Workers.xml"));
            Worker.DataSource = workersDataSet;
            Worker.DataBind();


            DataSet thePropertyDataSet = new DataSet();

            thePropertyDataSet.ReadXml(MapPath("~/App_Data/TheProperty.xml"));
            TheProperty.DataSource = thePropertyDataSet;
            TheProperty.DataBind();
        }
		public static void Parse(TheProperty pProperty, CodeBuilder pBuilder, FactoryExpressionCreator pCreator) {
			if (pProperty == null) return;
			bool isInterface = pProperty.MyClass.IsInterface;
			string type = JsHelpers.Convert(pProperty.ReturnType);

			if (pProperty.IsEmpty && !isInterface) {
				pBuilder.AppendFormat("private var _{0}:{1};", pProperty.Name, type);
				pBuilder.AppendLine();
			}

			TheClass parent = pProperty.MyClass;
			bool isStandardGetSet = false;
			while (parent.Base != null) {
				isStandardGetSet |= parent.FullName.StartsWith("flash.");
				parent = parent.Base;
			}

			if (pProperty.Getter != null) {//Getter
				if (isStandardGetSet) {//base is flash, use standard setter/getter
					pBuilder.AppendFormat("{0}function get {1}():{2}{3}",
						JsHelpers.ConvertModifiers(pProperty.Getter.Modifiers, _notValidPropertyMod),
						pProperty.Name,
						type,
						isInterface ? ";" : " {"
					);

				} else {
					bool isEnum = false;

					foreach (string s in pProperty.MyClass.Implements) {
						if (!s.StartsWith("IEnumerator", StringComparison.Ordinal)) {
							continue;
						}

						isEnum = true;
						break;
					}

					isEnum &= pProperty.Getter.Name.Equals("get_Current");

					//bool isEnum =
					//    pProperty.Getter.Name.Equals("get_Current") &&
					//    pProperty.MyClass.Implements.Contains()

					pBuilder.AppendFormat("{0}function {1}():{2}{3}",
						JsHelpers.ConvertModifiers(pProperty.Getter.Modifiers, _notValidPropertyMod),
						pProperty.Getter.Name,
						isEnum ? "*" : type,
						isInterface ? ";" : " {"
					);
				}

				pBuilder.AppendLine();

				if (!isInterface) {
					if (pProperty.IsEmpty) {
						pBuilder.Indent();
						pBuilder.AppendFormat("return _{0};", pProperty.Name);
						pBuilder.Unindent();

					} else {
						BlockParser.Parse(pProperty.Getter.CodeBlock, pBuilder, pCreator);
					}

					pBuilder.AppendLine();
					pBuilder.AppendLine("}");
					pBuilder.AppendLine();
				}
			}

			if (pProperty.Setter == null) {
				return;
			}

			if (isStandardGetSet) {//Setter
//base is flash, use standard setter/getter
				pBuilder.AppendFormat("{0}function set {1}(value:{2}):void{3}",
				                      JsHelpers.ConvertModifiers(pProperty.Setter.Modifiers, _notValidPropertyMod),
				                      pProperty.Name,
				                      type,
									  isInterface ? ";" : " {"
					);
			} else {
				pBuilder.AppendFormat("{0}function {1}(value:{2}):{2}{3}",
				                      JsHelpers.ConvertModifiers(pProperty.Setter.Modifiers, _notValidPropertyMod),
				                      pProperty.Setter.Name,
				                      type,
									  isInterface ? ";" : " {"
					);
			}

			pBuilder.AppendLine();

			if (!isInterface) {
				if (pProperty.IsEmpty) {
					pBuilder.Indent();
					pBuilder.AppendFormat("_{0} = value;", pProperty.Name);
					pBuilder.AppendLine();
					pBuilder.Append("return value;");
					pBuilder.Unindent();

				} else {
					BlockParser.InsideSetter = !isStandardGetSet;
					BlockParser.Parse(pProperty.Setter.CodeBlock, pBuilder, pCreator);
					BlockParser.InsideSetter = false;
					if (!isStandardGetSet)
						pBuilder.AppendLine("	return value;");
				}

				pBuilder.AppendLine();
				pBuilder.AppendLine("}");
			}

			pBuilder.AppendLine();
		}
Exemple #4
0
        public static void Parse(TheProperty pProperty, CodeBuilder pBuilder, FactoryExpressionCreator pCreator)
        {
            if (pProperty == null)
            {
                return;
            }
            bool   isInterface = pProperty.MyClass.IsInterface;
            string type        = As3Helpers.Convert(pProperty.ReturnType);

            if (pProperty.IsEmpty && !isInterface)
            {
                pBuilder.AppendFormat("private var _{0}:{1};", pProperty.Name, type);
                pBuilder.AppendLine();
            }

            TheClass parent           = pProperty.MyClass;
            bool     isStandardGetSet = false;

            while (parent.Base != null)
            {
                isStandardGetSet |= parent.FullName.StartsWith("flash.");
                parent            = parent.Base;
            }

            if (pProperty.Getter != null)              //Getter
            {
                if (isStandardGetSet)                  //base is flash, use standard setter/getter
                {
                    pBuilder.AppendFormat("{0}function get {1}():{2}{3}",
                                          As3Helpers.ConvertModifiers(pProperty.Getter.Modifiers, _notValidPropertyMod),
                                          pProperty.Name,
                                          type,
                                          isInterface ? ";" : " {"
                                          );
                }
                else
                {
                    bool isEnum = false;

                    foreach (string s in pProperty.MyClass.Implements)
                    {
                        if (!s.StartsWith("IEnumerator", StringComparison.Ordinal))
                        {
                            continue;
                        }

                        isEnum = true;
                        break;
                    }

                    isEnum &= pProperty.Getter.Name.Equals("get_Current");

                    //bool isEnum =
                    //    pProperty.Getter.Name.Equals("get_Current") &&
                    //    pProperty.MyClass.Implements.Contains()

                    pBuilder.AppendFormat("{0}function {1}():{2}{3}",
                                          As3Helpers.ConvertModifiers(pProperty.Getter.Modifiers, _notValidPropertyMod),
                                          pProperty.Getter.Name,
                                          isEnum ? "*" : type,
                                          isInterface ? ";" : " {"
                                          );
                }

                pBuilder.AppendLine();

                if (!isInterface)
                {
                    if (pProperty.IsEmpty)
                    {
                        pBuilder.Indent();
                        pBuilder.AppendFormat("return _{0};", pProperty.Name);
                        pBuilder.Unindent();
                    }
                    else
                    {
                        BlockParser.Parse(pProperty.Getter.CodeBlock, pBuilder, pCreator);
                    }

                    pBuilder.AppendLine();
                    pBuilder.AppendLine("}");
                    pBuilder.AppendLine();
                }
            }

            if (pProperty.Setter == null)
            {
                return;
            }

            if (isStandardGetSet)              //Setter
//base is flash, use standard setter/getter
            {
                pBuilder.AppendFormat("{0}function set {1}(value:{2}):void{3}",
                                      As3Helpers.ConvertModifiers(pProperty.Setter.Modifiers, _notValidPropertyMod),
                                      pProperty.Name,
                                      type,
                                      isInterface ? ";" : " {"
                                      );
            }
            else
            {
                pBuilder.AppendFormat("{0}function {1}(value:{2}):{2}{3}",
                                      As3Helpers.ConvertModifiers(pProperty.Setter.Modifiers, _notValidPropertyMod),
                                      pProperty.Setter.Name,
                                      type,
                                      isInterface ? ";" : " {"
                                      );
            }

            pBuilder.AppendLine();

            if (!isInterface)
            {
                if (pProperty.IsEmpty)
                {
                    pBuilder.Indent();
                    pBuilder.AppendFormat("_{0} = value;", pProperty.Name);
                    pBuilder.AppendLine();
                    pBuilder.Append("return value;");
                    pBuilder.Unindent();
                }
                else
                {
                    BlockParser.InsideSetter = !isStandardGetSet;
                    BlockParser.Parse(pProperty.Setter.CodeBlock, pBuilder, pCreator);
                    BlockParser.InsideSetter = false;
                    if (!isStandardGetSet)
                    {
                        pBuilder.AppendLine("	return value;");
                    }
                }

                pBuilder.AppendLine();
                pBuilder.AppendLine("}");
            }

            pBuilder.AppendLine();
        }