当前位置: 首页>>代码示例>>C#>>正文


C# GenerationInfo.OpenStream方法代码示例

本文整理汇总了C#中GtkSharp.Generation.GenerationInfo.OpenStream方法的典型用法代码示例。如果您正苦于以下问题:C# GenerationInfo.OpenStream方法的具体用法?C# GenerationInfo.OpenStream怎么用?C# GenerationInfo.OpenStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GtkSharp.Generation.GenerationInfo的用法示例。


在下文中一共展示了GenerationInfo.OpenStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Generate

        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = Name;

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name);

            sw.WriteLine ("namespace " + NS + " {");
            sw.WriteLine ();
            sw.WriteLine ("\tusing System;");
            sw.WriteLine ("\tusing System.Runtime.InteropServices;");
            sw.WriteLine ();

            sw.WriteLine ("#region Autogenerated code");
            if (IsDeprecated)
                sw.WriteLine ("\t[Obsolete]");
            sw.Write ("\t{0} class " + Name, IsInternal ? "internal" : "public");
            sw.WriteLine (" {");
            sw.WriteLine ();

            GenProperties (gen_info, null);
            GenMethods (gen_info, null, null);

            sw.WriteLine ("#endregion");
            AppendCustom(sw, gen_info.CustomDir);

            sw.WriteLine ("\t}");
            sw.WriteLine ("}");

            sw.Close ();
            gen_info.Writer = null;
        }
开发者ID:Yetangitu,项目名称:f-spot,代码行数:31,代码来源:ClassGen.cs

示例2: Generate

        public override void Generate(GenerationInfo gen_info)
        {
            Method copy = methods["Copy"] as Method;
            Method free = methods["Free"] as Method;
            methods.Remove ("Copy");
            methods.Remove ("Free");

            gen_info.CurrentType = QualifiedName;

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
            base.Generate (gen_info);
            sw.WriteLine ("\t\tpublic static explicit operator GLib.Value (" + QualifiedName + " boxed)");
            sw.WriteLine ("\t\t{");

            sw.WriteLine ("\t\t\tGLib.Value val = GLib.Value.Empty;");
            sw.WriteLine ("\t\t\tval.Init (" + QualifiedName + ".GType);");
            sw.WriteLine ("\t\t\tval.Val = boxed;");
            sw.WriteLine ("\t\t\treturn val;");
            sw.WriteLine ("\t\t}");
            sw.WriteLine ();
            sw.WriteLine ("\t\tpublic static explicit operator " + QualifiedName + " (GLib.Value val)");
            sw.WriteLine ("\t\t{");

            sw.WriteLine ("\t\t\treturn (" + QualifiedName + ") val.Val;");
            sw.WriteLine ("\t\t}");

            if (copy != null && copy.IsDeprecated) {
                sw.WriteLine ();
                sw.WriteLine ("\t\t[Obsolete(\"This is a no-op\")]");
                sw.WriteLine ("\t\tpublic " + QualifiedName + " Copy() {");
                sw.WriteLine ("\t\t\treturn this;");
                sw.WriteLine ("\t\t}");
            }

            if (free != null && free.IsDeprecated) {
                sw.WriteLine ();
                sw.WriteLine ("\t\t[Obsolete(\"This is a no-op\")]");
                sw.WriteLine ("\t\tpublic " + QualifiedName + " Free () {");
                sw.WriteLine ("\t\t\treturn this;");
                sw.WriteLine ("\t\t}");
            }

            sw.WriteLine ("#endregion");
                        AppendCustom(sw, gen_info.CustomDir);
                        sw.WriteLine ("\t}");
                        sw.WriteLine ("}");
            sw.Close ();
            gen_info.Writer = null;
            Statistics.BoxedCount++;
        }
开发者ID:nuxleus,项目名称:gtk-sharp,代码行数:50,代码来源:BoxedGen.cs

示例3: Generate

        public override void Generate(GenerationInfo gen_info)
        {
            Method copy = methods["Copy"] as Method;
            methods.Remove ("Copy");
            methods.Remove ("Free");

            gen_info.CurrentType = Name;

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
            base.Generate (gen_info);
            sw.WriteLine ("\t\t[DllImport(\"glibsharpglue-2\")]");
            sw.WriteLine ("\t\tstatic extern IntPtr glibsharp_value_get_boxed (ref GLib.Value val);");
            sw.WriteLine ();
            sw.WriteLine ("\t\t[DllImport(\"glibsharpglue-2\")]");
            sw.WriteLine ("\t\tstatic extern void glibsharp_value_set_boxed (ref GLib.Value val, ref " + QualifiedName + " boxed);");
            sw.WriteLine ();
            sw.WriteLine ("\t\tpublic static explicit operator GLib.Value (" + QualifiedName + " boxed)");
            sw.WriteLine ("\t\t{");

            sw.WriteLine ("\t\t\tGLib.Value val = GLib.Value.Empty;");
            sw.WriteLine ("\t\t\tval.Init (" + QualifiedName + ".GType);");
            sw.WriteLine ("\t\t\tglibsharp_value_set_boxed (ref val, ref boxed);");
            sw.WriteLine ("\t\t\treturn val;");
            sw.WriteLine ("\t\t}");
            sw.WriteLine ();
            sw.WriteLine ("\t\tpublic static explicit operator " + QualifiedName + " (GLib.Value val)");
            sw.WriteLine ("\t\t{");

            sw.WriteLine ("\t\t\tIntPtr boxed_ptr = glibsharp_value_get_boxed (ref val);");
            sw.WriteLine ("\t\t\treturn New (boxed_ptr);");
            sw.WriteLine ("\t\t}");

            if (copy != null && copy.IsDeprecated) {
                sw.WriteLine ();
                sw.WriteLine ("\t\t[Obsolete(\"This is a no-op\")]");
                sw.WriteLine ("\t\tpublic " + QualifiedName + " Copy() {");
                sw.WriteLine ("\t\t\treturn this;");
                sw.WriteLine ("\t\t}");
            }

            sw.WriteLine ("#endregion");
                        AppendCustom(sw, gen_info.CustomDir);
                        sw.WriteLine ("\t}");
                        sw.WriteLine ("}");
            sw.Close ();
            gen_info.Writer = null;
            Statistics.BoxedCount++;
        }
开发者ID:Yetangitu,项目名称:f-spot,代码行数:48,代码来源:BoxedGen.cs

示例4: Generate

		public override void Generate (GenerationInfo gen_info)
		{
			StreamWriter sw = gen_info.OpenStream (Name);

			sw.WriteLine ("namespace " + NS + " {");
			sw.WriteLine ();
			sw.WriteLine ("\tusing System;");
			sw.WriteLine ("\tusing System.Runtime.InteropServices;");
			sw.WriteLine ();

			sw.WriteLine ("#region Autogenerated code");
					
			if (Elem.GetAttribute("type") == "flags")
				sw.WriteLine ("\t[Flags]");
			if (Elem.HasAttribute("gtype"))
				sw.WriteLine ("\t[GLib.GType (typeof (" + NS + "." + Name + "GType))]");

			string access = IsInternal ? "internal" : "public";
			sw.WriteLine ("\t" + access + " enum " + Name + enum_type + " {");
			sw.WriteLine ();
				
			foreach (string member in members)
				sw.WriteLine (member);

			sw.WriteLine ("\t}");

			if (Elem.HasAttribute ("gtype")) {
				sw.WriteLine ();
				sw.WriteLine ("\tinternal class " + Name + "GType {");
				sw.WriteLine ("\t\t[DllImport (\"" + LibraryName + "\")]");
				sw.WriteLine ("\t\tstatic extern IntPtr " + Elem.GetAttribute ("gtype") + " ();");
				sw.WriteLine ();
				sw.WriteLine ("\t\tpublic static GLib.GType GType {");
				sw.WriteLine ("\t\t\tget {");
				sw.WriteLine ("\t\t\t\treturn new GLib.GType (" + Elem.GetAttribute ("gtype") + " ());");
				sw.WriteLine ("\t\t\t}");
				sw.WriteLine ("\t\t}");
				sw.WriteLine ("\t}");
			}

			sw.WriteLine ("#endregion");
			sw.WriteLine ("}");
			sw.Close ();
			Statistics.EnumCount++;
		}
开发者ID:ystk,项目名称:debian-gtk-sharp2,代码行数:45,代码来源:EnumGen.cs

示例5: Generate

        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = QualifiedName;

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
            base.Generate (gen_info);
            if (GetMethod ("GetType") == null && GetMethod ("GetGType") == null) {
                sw.WriteLine ("\t\tprivate static GLib.GType GType {");
                sw.WriteLine ("\t\t\tget { return GLib.GType.Pointer; }");
                sw.WriteLine ("\t\t}");
            }
            sw.WriteLine ("#endregion");
            sw.WriteLine ("\t}");
            sw.WriteLine ("}");
            sw.Close ();
            gen_info.Writer = null;
            Statistics.StructCount++;
        }
开发者ID:pabloescribano,项目名称:gtk-sharp,代码行数:18,代码来源:StructGen.cs

示例6: Generate

		public override void Generate (GenerationInfo gen_info)
		{
			bool need_close = false;
			if (gen_info.Writer == null) {
				gen_info.Writer = gen_info.OpenStream (Name, NS);
				need_close = true;
			}

			StreamWriter sw = gen_info.Writer;
			
			sw.WriteLine ("namespace " + NS + " {");
			sw.WriteLine ();
			sw.WriteLine ("\tusing System;");
			sw.WriteLine ("\tusing System.Collections;");
			sw.WriteLine ("\tusing System.Collections.Generic;");
			sw.WriteLine ("\tusing System.Runtime.InteropServices;");
			sw.WriteLine ();

			sw.WriteLine ("#region Autogenerated code");
			if (IsDeprecated)
				sw.WriteLine ("\t[Obsolete]");
			string access = IsInternal ? "internal" : "public";
			sw.WriteLine ("\t" + access + " partial class {0} : {1} IEquatable<{0}> {{", Name, Parent == null ? "GLib.IWrapper," : (Parent.QualifiedName + ","));
			sw.WriteLine ();

			GenNativeStruct (gen_info);
			GenNativeAccessor (gen_info);
			GenFields (gen_info);
			sw.WriteLine ();
			GenCtors (gen_info);
			GenMethods (gen_info, null, this);
			GenEqualsAndHash (sw);

			if (!need_close)
				return;

			sw.WriteLine ("#endregion");

			sw.WriteLine ("\t}");
			sw.WriteLine ("}");
			sw.Close ();
			gen_info.Writer = null;
		}
开发者ID:liberostelios,项目名称:gtk-sharp,代码行数:43,代码来源:NativeStructGen.cs

示例7: Generate

        public override void Generate(GenerationInfo gen_info)
        {
            GenerateAdapter (gen_info);
            StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);

            sw.WriteLine ("namespace " + NS + " {");
            sw.WriteLine ();
            sw.WriteLine ("\tusing System;");
            sw.WriteLine ();
            sw.WriteLine ("#region Autogenerated code");
            string access = IsInternal ? "internal" : "public";
            sw.WriteLine ("\t" + access + " interface " + Name + " : GLib.IWrapper {");
            sw.WriteLine ();

            foreach (Signal sig in sigs.Values) {
                sig.GenerateDecl (sw);
                sig.GenEventHandler (gen_info);
            }

            foreach (Method method in methods.Values) {
                if (IgnoreMethod (method, this))
                    continue;
                method.GenerateDecl (sw);
            }

            foreach (Property prop in props.Values)
                prop.GenerateDecl (sw, "\t\t");

            AppendCustom (sw, gen_info.CustomDir);

            sw.WriteLine ("\t}");
            GenerateImplementorIface (sw);
            sw.WriteLine ("#endregion");
            sw.WriteLine ("}");
            sw.Close ();
            gen_info.Writer = null;
            Statistics.IFaceCount++;
        }
开发者ID:saraa,项目名称:fishtastic,代码行数:38,代码来源:InterfaceGen.cs

示例8: GenEventHandler

        public void GenEventHandler(GenerationInfo gen_info)
        {
            if (IsEventHandler)
                return;

            string ns = container_type.NS;

            StreamWriter sw = gen_info.OpenStream (EventHandlerName);

            sw.WriteLine ("namespace " + ns + " {");
            sw.WriteLine ();
            sw.WriteLine ("\tusing System;");

            sw.WriteLine ();
            sw.WriteLine ("\tpublic delegate void " + EventHandlerName + "(object o, " + EventArgsName + " args);");
            sw.WriteLine ();
            sw.WriteLine ("\tpublic class " + EventArgsName + " : GLib.SignalArgs {");
            for (int i = 0; i < parms.Count; i++) {
                sw.WriteLine ("\t\tpublic " + parms[i].CSType + " " + parms[i].StudlyName + "{");
                if (parms[i].PassAs != "out") {
                    sw.WriteLine ("\t\t\tget {");
                    if (SymbolTable.Table.IsInterface (parms [i].CType))
                        sw.WriteLine ("\t\t\t\treturn {0}Adapter.GetObject (Args [{1}] as GLib.Object);", parms [i].CSType, i);
                    else
                        sw.WriteLine ("\t\t\t\treturn ({0}) Args [{1}];", parms [i].CSType, i);
                    sw.WriteLine ("\t\t\t}");
                }
                if (parms[i].PassAs != "") {
                    sw.WriteLine ("\t\t\tset {");
                    if (SymbolTable.Table.IsInterface (parms [i].CType))
                        sw.WriteLine ("\t\t\t\tArgs [{0}] = value is {1}Adapter ? (value as {1}Adapter).Implementor : value;", i, parms [i].CSType);
                    else
                        sw.WriteLine ("\t\t\t\tArgs[" + i + "] = (" + parms[i].CSType + ")value;");
                    sw.WriteLine ("\t\t\t}");
                }
                sw.WriteLine ("\t\t}");
                sw.WriteLine ();
            }
            sw.WriteLine ("\t}");
            sw.WriteLine ("}");
            sw.Close ();
        }
开发者ID:shana,项目名称:gtk-sharp,代码行数:42,代码来源:Signal.cs

示例9: GenerateAdapter

        void GenerateAdapter(GenerationInfo gen_info)
        {
            StreamWriter sw = gen_info.Writer = gen_info.OpenStream (AdapterName);

            sw.WriteLine ("namespace " + NS + " {");
            sw.WriteLine ();
            sw.WriteLine ("\tusing System;");
            sw.WriteLine ("\tusing System.Runtime.InteropServices;");
            sw.WriteLine ();
            sw.WriteLine ("#region Autogenerated code");
            sw.WriteLine ("\tpublic partial class " + AdapterName + " : GLib.GInterfaceAdapter, " + QualifiedName + " {");
            sw.WriteLine ();

            if (!IsConsumeOnly) {
                GenerateClassStruct (gen_info);
                GenerateStaticCtor (sw);
                GenerateCallbacks (sw);
                GenerateInitialize (sw);
            }
            GenerateCtors (sw);
            GenerateGType (sw);
            GenerateHandleProp (sw);
            GenerateGetObject (sw);
            if (!IsConsumeOnly)
                GenerateImplementorProp (sw);

            GenProperties (gen_info, null);

            foreach (Signal sig in sigs.Values)
                sig.GenEvent (sw, null, "GLib.Object.GetObject (Handle)");

            Method temp = GetMethod ("GetType");
            if (temp != null)
                Methods.Remove ("GetType");
            GenMethods (gen_info, null, this);
            if (temp != null)
                Methods ["GetType"] = temp;

            sw.WriteLine ("#endregion");

            sw.WriteLine ("\t}");
            sw.WriteLine ("}");
            sw.Close ();
            gen_info.Writer = null;
        }
开发者ID:knocte,项目名称:gtk-sharp,代码行数:45,代码来源:InterfaceGen.cs

示例10: GenEventHandler

		public void GenEventHandler (GenerationInfo gen_info)
		{
			if (IsEventHandler)
				return;

			string ns = container_type.NS;

			StreamWriter sw = gen_info.OpenStream (EventHandlerName);
			
			sw.WriteLine ("namespace " + ns + " {");
			sw.WriteLine ();
			sw.WriteLine ("\tusing System;");

			sw.WriteLine ();
			sw.WriteLine ("\tpublic delegate void " + EventHandlerName + "(object o, " + EventArgsName + " args);");
			sw.WriteLine ();
			sw.WriteLine ("\tpublic class " + EventArgsName + " : GLib.SignalArgs {");
			for (int i = 1; i < parms.Count; i++) {
				sw.WriteLine ("\t\tpublic " + parms[i].CSType + " " + parms[i].StudlyName + "{");
				if (parms[i].PassAs != "out") {
					sw.WriteLine ("\t\t\tget {");
					sw.WriteLine ("\t\t\t\treturn (" + parms[i].CSType + ") Args[" + (i - 1) + "];");
					sw.WriteLine ("\t\t\t}");
				}
				if (parms[i].PassAs != "") {
					sw.WriteLine ("\t\t\tset {");
					sw.WriteLine ("\t\t\t\tArgs[" + (i - 1) + "] = (" + parms[i].CSType + ")value;");
					sw.WriteLine ("\t\t\t}");
				}
				sw.WriteLine ("\t\t}");
				sw.WriteLine ();
			}
			sw.WriteLine ("\t}");
			sw.WriteLine ("}");
			sw.Close ();
		}
开发者ID:rubenv,项目名称:tripod,代码行数:36,代码来源:Signal.cs

示例11: GenerateMapper

        private static void GenerateMapper(DirectoryInfo dir_info, GenerationInfo gen_info)
        {
            StreamWriter sw = gen_info.OpenStream ("ObjectManager");

            sw.WriteLine ("namespace GtkSharp." + Studlify (dir_info.assembly_name) + " {");
            sw.WriteLine ();
            sw.WriteLine ("\tpublic class ObjectManager {");
            sw.WriteLine ();
            sw.WriteLine ("\t\tstatic bool initialized = false;");
            sw.WriteLine ("\t\t// Call this method from the appropriate module init function.");
            sw.WriteLine ("\t\tpublic static void Initialize ()");
            sw.WriteLine ("\t\t{");
            sw.WriteLine ("\t\t\tif (initialized)");
            sw.WriteLine ("\t\t\t\treturn;");
            sw.WriteLine ("");
            sw.WriteLine ("\t\t\tinitialized = true;");

            foreach (string key in dir_info.objects.Keys) {
                if (GetExpected(key) != ((string) dir_info.objects[key]))
                    sw.WriteLine ("\t\t\tGLib.GType.Register ({0}.GType, typeof ({0}));", dir_info.objects [key]);
            }

            sw.WriteLine ("\t\t}");
            sw.WriteLine ("\t}");
            sw.WriteLine ("}");
            sw.Close ();
        }
开发者ID:Dynalon,项目名称:clutter-sharp,代码行数:27,代码来源:ObjectGen.cs

示例12: Generate

        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = Name;

            string asm_name = gen_info.AssemblyName.Length == 0 ? NS.ToLower () + "-sharp" : gen_info.AssemblyName;
            DirectoryInfo di = GetDirectoryInfo (gen_info.Dir, asm_name);

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);

            sw.WriteLine ("namespace " + NS + " {");
            sw.WriteLine ();
            sw.WriteLine ("\tusing System;");
            sw.WriteLine ("\tusing System.Collections;");
            sw.WriteLine ("\tusing System.Runtime.InteropServices;");
            sw.WriteLine ();

            SymbolTable table = SymbolTable.Table;

            sw.WriteLine ("#region Autogenerated code");
            if (IsDeprecated)
                sw.WriteLine ("\t[Obsolete]");
            foreach (string attr in custom_attrs)
                sw.WriteLine ("\t" + attr);
            sw.Write ("\t{0} {1}class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : "");
            string cs_parent = table.GetCSType(Elem.GetAttribute("parent"));
            if (cs_parent != "") {
                di.objects.Add (CName, QualifiedName);
                sw.Write (" : " + cs_parent);
            }
            foreach (string iface in interfaces) {
                if (Parent != null && Parent.Implements (iface))
                    continue;
                sw.Write (", " + table.GetCSType (iface));
            }
            foreach (string iface in managed_interfaces) {
                if (Parent != null && Parent.Implements (iface))
                    continue;
                sw.Write (", " + iface);
            }
            sw.WriteLine (" {");
            sw.WriteLine ();

            GenCtors (gen_info);
            GenProperties (gen_info, null);
            GenFields (gen_info);
            GenChildProperties (gen_info);

            bool has_sigs = (sigs != null && sigs.Count > 0);
            if (!has_sigs) {
                foreach (string iface in interfaces) {
                    InterfaceGen igen = table.GetClassGen (iface) as InterfaceGen;
                    if (igen != null && igen.Signals != null) {
                        has_sigs = true;
                        break;
                    }
                }
            }

            if (has_sigs && Elem.HasAttribute("parent")) {
                GenSignals (gen_info, null);
            }

            GenClassMembers (gen_info, cs_parent);
            GenMethods (gen_info, null, null);

            if (interfaces.Count != 0) {
                Hashtable all_methods = new Hashtable ();
                foreach (Method m in Methods.Values)
                    all_methods[m.Name] = m;
                Hashtable collisions = new Hashtable ();
                foreach (string iface in interfaces) {
                    ClassBase igen = table.GetClassGen (iface);
                    foreach (Method m in igen.Methods.Values) {
                        Method collision = all_methods[m.Name] as Method;
                        if (collision != null && collision.Signature.Types == m.Signature.Types)
                            collisions[m.Name] = true;
                        else
                            all_methods[m.Name] = m;
                    }
                }

                foreach (string iface in interfaces) {
                    if (Parent != null && Parent.Implements (iface))
                        continue;
                    InterfaceGen igen = table.GetClassGen (iface) as InterfaceGen;
                    igen.GenMethods (gen_info, collisions, this);
                    igen.GenProperties (gen_info, this);
                    igen.GenSignals (gen_info, this);
                    igen.GenVirtualMethods (gen_info, this);
                }
            }

            foreach (XmlElement str in strings) {
                sw.Write ("\t\tpublic static string " + str.GetAttribute ("name"));
                sw.WriteLine (" {\n\t\t\t get { return \"" + str.GetAttribute ("value") + "\"; }\n\t\t}");
            }

            if (cs_parent != String.Empty && GetExpected (CName) != QualifiedName) {
                sw.WriteLine ();
                sw.WriteLine ("\t\tstatic " + Name + " ()");
//.........这里部分代码省略.........
开发者ID:Dynalon,项目名称:clutter-sharp,代码行数:101,代码来源:ObjectGen.cs

示例13: Generate

		public override void Generate (GenerationInfo gen_info)
		{
			gen_info.CurrentType = QualifiedName;

			sig = new Signature (parms);

			StreamWriter sw = gen_info.OpenStream (Name, NS);

			sw.WriteLine ("namespace " + NS + " {");
			sw.WriteLine ();
			sw.WriteLine ("\tusing System;");
			sw.WriteLine ();
			sw.WriteLine ("\t{0} delegate " + retval.CSType + " " + Name + "(" + sig.ToString() + ");", IsInternal ? "internal" : "public");
			sw.WriteLine ();
			sw.WriteLine ("}");

			sw.Close ();
			
			GenWrapper (gen_info);

			Statistics.CBCount++;
		}
开发者ID:liberostelios,项目名称:gtk-sharp,代码行数:22,代码来源:CallbackGen.cs

示例14: GenWrapper

		public string GenWrapper (GenerationInfo gen_info)
		{
			string wrapper = Name + "Native";
			string qualname = MarshalType;

			if (!Validate ())
				return String.Empty;

			body = new MethodBody (parms);

			StreamWriter save_sw = gen_info.Writer;
			StreamWriter sw = gen_info.Writer = gen_info.OpenStream (qualname, NS);

			sw.WriteLine ("namespace " + NS + "Sharp {");
			sw.WriteLine ();
			sw.WriteLine ("\tusing System;");
			sw.WriteLine ("\tusing System.Runtime.InteropServices;");
			sw.WriteLine ();
			sw.WriteLine ("#region Autogenerated code");
			sw.WriteLine ("\t[UnmanagedFunctionPointer (CallingConvention.Cdecl)]");
			sw.WriteLine ("\tinternal delegate " + retval.MarshalType + " " + wrapper + "(" + parms.ImportSignature + ");");
			sw.WriteLine ();
			GenInvoker (gen_info, sw);
			sw.WriteLine ("\tinternal class " + Name + "Wrapper {");
			sw.WriteLine ();
			ManagedCallString call = new ManagedCallString (parms);
			sw.WriteLine ("\t\tpublic " + retval.MarshalType + " NativeCallback (" + parms.ImportSignature + ")");
			sw.WriteLine ("\t\t{");
			string unconditional = call.Unconditional ("\t\t\t");
			if (unconditional.Length > 0)
				sw.WriteLine (unconditional);
			sw.WriteLine ("\t\t\ttry {");
			string call_setup = call.Setup ("\t\t\t\t");
			if (call_setup.Length > 0)
				sw.WriteLine (call_setup);
			if (retval.CSType == "void")
				sw.WriteLine ("\t\t\t\tmanaged ({0});", call);
			else
				sw.WriteLine ("\t\t\t\t{0} __ret = managed ({1});", retval.CSType, call);
			string finish = call.Finish ("\t\t\t\t");
			if (finish.Length > 0)
				sw.WriteLine (finish);
			sw.WriteLine ("\t\t\t\tif (release_on_call)\n\t\t\t\t\tgch.Free ();");
			Parameter cnt = retval.CountParameter;
			if (cnt != null)
				sw.WriteLine ("\t\t\t\t{0} = {1}{2};", cnt.Name, cnt.CSType == "int" ? String.Empty : "(" + cnt.MarshalType + ")(" + cnt.CSType + ")", "__ret.Length");
			if (retval.CSType != "void")
				sw.WriteLine ("\t\t\t\treturn {0};", retval.ToNative ("__ret"));

			/* If the function expects one or more "out" parameters(error parameters are excluded) or has a return value different from void and bool, exceptions
			*  thrown in the managed function have to be considered fatal meaning that an exception is to be thrown and the function call cannot not return
			*/
			bool fatal = (retval.MarshalType != "void" && retval.MarshalType != "bool") || call.HasOutParam;
			sw.WriteLine ("\t\t\t} catch (Exception e) {");
			sw.WriteLine ("\t\t\t\tGLib.ExceptionManager.RaiseUnhandledException (e, " + (fatal ? "true" : "false") + ");");
			if (fatal) {
				sw.WriteLine ("\t\t\t\t// NOTREACHED: Above call does not return.");
				sw.WriteLine ("\t\t\t\tthrow e;");
			} else if (retval.MarshalType == "bool") {
				sw.WriteLine ("\t\t\t\treturn false;");
			}
			sw.WriteLine ("\t\t\t}");
			sw.WriteLine ("\t\t}");
			sw.WriteLine ();
			sw.WriteLine ("\t\tbool release_on_call = false;");
			sw.WriteLine ("\t\tGCHandle gch;");
			sw.WriteLine ();
			sw.WriteLine ("\t\tpublic void PersistUntilCalled ()");
			sw.WriteLine ("\t\t{");
			sw.WriteLine ("\t\t\trelease_on_call = true;");
			sw.WriteLine ("\t\t\tgch = GCHandle.Alloc (this);");
			sw.WriteLine ("\t\t}");
			sw.WriteLine ();
			sw.WriteLine ("\t\tinternal " + wrapper + " NativeDelegate;");
			sw.WriteLine ("\t\t" + NS + "." + Name + " managed;");
			sw.WriteLine ();
			sw.WriteLine ("\t\tpublic " + Name + "Wrapper (" + NS + "." + Name + " managed)");
			sw.WriteLine ("\t\t{");
			sw.WriteLine ("\t\t\tthis.managed = managed;");
			sw.WriteLine ("\t\t\tif (managed != null)");
			sw.WriteLine ("\t\t\t\tNativeDelegate = new " + wrapper + " (NativeCallback);");
			sw.WriteLine ("\t\t}");
			sw.WriteLine ();
			sw.WriteLine ("\t\tpublic static " + NS + "." + Name + " GetManagedDelegate (" + wrapper + " native)");
			sw.WriteLine ("\t\t{");
			sw.WriteLine ("\t\t\tif (native == null)");
			sw.WriteLine ("\t\t\t\treturn null;");
			sw.WriteLine ("\t\t\t" + Name + "Wrapper wrapper = (" + Name + "Wrapper) native.Target;");
			sw.WriteLine ("\t\t\tif (wrapper == null)");
			sw.WriteLine ("\t\t\t\treturn null;");
			sw.WriteLine ("\t\t\treturn wrapper.managed;");
			sw.WriteLine ("\t\t}");
			sw.WriteLine ("\t}");
			sw.WriteLine ("#endregion");
			sw.WriteLine ("}");
			sw.Close ();
			gen_info.Writer = save_sw;
			return NS + "Sharp." + Name + "Wrapper";
		}
开发者ID:liberostelios,项目名称:gtk-sharp,代码行数:99,代码来源:CallbackGen.cs

示例15: Generate

		public override void Generate (GenerationInfo gen_info)
		{
			bool need_close = false;
			if (gen_info.Writer == null) {
				gen_info.Writer = gen_info.OpenStream (Name, NS);
				need_close = true;
			}

			StreamWriter sw = gen_info.Writer;
			
			sw.WriteLine ("namespace " + NS + " {");
			sw.WriteLine ();
			sw.WriteLine ("\tusing System;");
			sw.WriteLine ("\tusing System.Collections;");
			sw.WriteLine ("\tusing System.Collections.Generic;");
			sw.WriteLine ("\tusing System.Runtime.InteropServices;");
			sw.WriteLine ();
			
			sw.WriteLine ("#region Autogenerated code");
			if (IsDeprecated)
				sw.WriteLine ("\t[Obsolete]");
			if (Union)
				sw.WriteLine ("\t[StructLayout(LayoutKind.Explicit)]");
			else
				sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
			string access = IsInternal ? "internal" : "public";
			sw.WriteLine ("\t" + access + " partial struct {0} : IEquatable<{0}> {{", Name);
			sw.WriteLine ();

			need_read_native = false;
			GenFields (gen_info);
			sw.WriteLine ();
			GenCtors (gen_info);
			GenMethods (gen_info, null, this);
			if (need_read_native)
				GenReadNative (sw);
			GenEqualsAndHash (sw);

			if (!need_close)
				return;

			sw.WriteLine ("#endregion");

			sw.WriteLine ("\t}");
			sw.WriteLine ("}");
			sw.Close ();
			gen_info.Writer = null;
		}
开发者ID:liberostelios,项目名称:gtk-sharp,代码行数:48,代码来源:StructBase.cs


注:本文中的GtkSharp.Generation.GenerationInfo.OpenStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。