Esempio n. 1
0
		public override void EmitContainerJs (JsEmitContext jec)
		{
			VerifyClsCompliance ();

			var name = jec.MakeJsNamespaceName (this.NS.Name);
			bool is_global_ns = String.IsNullOrEmpty (name);

			if (!is_global_ns) {
				jec.Buf.Write ("\tvar ", name, ";\n",
				               "\t(function (", name, ") {\n", Location);
				jec.Buf.Indent ();

				jec.MarkNamespaceDefined (NS.Name);
			}

			base.EmitContainerJs (jec);

			if (!is_global_ns) {
				jec.Buf.Unindent ();
				jec.Buf.Write ("\t})(", name, " || (", name, " = {});\n");
			}
		}
Esempio n. 2
0
		public override void EmitJs (JsEmitContext jec)
		{
			if (!jec.CheckCanEmit (Location))
				return;

			if (!has_static_constructor && HasStaticFieldInitializer) {
				var c = DefineDefaultConstructor (true);
				c.Define ();
			}

			if (!(this.Parent is NamespaceContainer)) {
				jec.Report.Error (7075, Location, "JavaScript code generation for nested types not supported.");
				return;
			}


			Constructor constructor = null;

			foreach (var member in Members) {
				var c = member as Constructor;
				if (c != null) {
					if ((c.ModFlags & Modifiers.STATIC) != 0) {
						continue;
					} 
					if (constructor != null) {
						jec.Report.Error (7077, c.Location, "JavaScript generation not supported for overloaded constructors");
						return;
					}
					constructor = c;
				}
			}

			var nsc = (NamespaceContainer)this.Parent;
			
			jec.Buf.Write ("\tvar ", this.MemberName.Name, " = (function () {\n", Location);
			jec.Buf.Indent ();

			base.EmitJs (jec);

			jec.Buf.Write ("\treturn ", this.MemberName.Name, ";\n");

			jec.Buf.Unindent();
			jec.Buf.Write ("\t})();\n");

			var nsname = jec.MakeJsNamespaceName(nsc.NS.Name);

			jec.Buf.Write ("\t", nsname, ".", this.MemberName.Name, " = ", this.MemberName.Name, ";\n");
		}