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


C# CodeWriter.Close方法代码示例

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


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

示例1: TypeGen

	static void TypeGen (Type t)
	{
		//TODO: we only handle ordinary classes for now
		/*
			 else if (t.IsSubclassOf (typeof (Delegate))) {
			 Console.WriteLine ("Ignoring delegate: " + t.Name);
			 return;
			 }
			 */

		cur_type = NsToC (ns) + "_" + CamelToC (t.Name);
		//CurType = NsToFlat (ns) + t.Name;
		CurType = CsTypeToG (t);
		if (t.IsInterface)
			CurTypeClass = GToGI (CurType);
		else
			CurTypeClass = GToGC (CurType);

		//ns = t.Namespace;
		string fname = NsToFlat (ns).ToLower () + t.Name.ToLower ();
		C = new CodeWriter (target_dir + fname + ".c");
		H = new CodeWriter (target_dir + fname + ".h");
		Hindex.WriteLine ("#include <" + fname + ".h" + ">");


		string H_id = "__" + NsToFlat (ns).ToUpper () + "_" + t.Name.ToUpper () + "_H__";
		H.WriteLine ("#ifndef " + H_id);
		H.WriteLine ("#define " + H_id);
		H.WriteLine ();

		H.WriteLine ("#include <glib.h>");
		H.WriteLine ("#include <glib-object.h>");

		foreach (string include in extincludes)
			H.WriteLine ("#include <" + include + ">");

		H.WriteLine ();

		if (t.BaseType != null && IsRegistered (t.BaseType) && !IsExternal (t.BaseType))
			H.WriteLine ("#include \"" + NsToFlat (t.BaseType.Namespace).ToLower () + t.BaseType.Name.ToLower () + ".h\"");

		foreach (string ext_ns in namespaces)
			H.WriteLine ("#include \"" + NsToFlat (ext_ns).ToLower () + "types.h\"");

		H.WriteLine ();

		H.WriteLine ("#ifdef __cplusplus");
		H.WriteLine ("extern \"C\" {", false);
		H.WriteLine ("#endif /* __cplusplus */");
		H.WriteLine ();

		C.WriteLine ("#include \"" + fname + ".h" + "\"");

		Type[] ifaces;
		ifaces = t.GetInterfaces ();
		foreach (Type iface in ifaces) {
			if (!IsRegistered (iface))
				continue;

			string iface_fname = NsToFlat (ns).ToLower () + iface.Name.ToLower ();
			C.WriteLine ("#include \"" + iface_fname + ".h" + "\"");
		}

		C.WriteLine ("#include <mono/metadata/object.h>");
		C.WriteLine ("#include <mono/metadata/debug-helpers.h>");
		C.WriteLine ("#include <mono/metadata/appdomain.h>");
		C.WriteLine ();

		if (t.IsClass)
			ClassGen (t);
		else if (t.IsInterface)
			ClassGen (t);
		else if (t.IsEnum)
			EnumGen (t);

		H.WriteLine ();
		H.WriteLine ("#ifdef __cplusplus");
		H.WriteLine ("}", false);
		H.WriteLine ("#endif /* __cplusplus */");
		H.WriteLine ();

		H.WriteLine ("#endif /* " + H_id + " */");

		C.Close ();
		H.Close ();
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:86,代码来源:cilc.cs

示例2: Generate

	public static void Generate (string assembly, string target)
	{
		target_dir = target + Path.DirectorySeparatorChar;

		if (Directory.Exists (target_dir)) {
			Console.WriteLine ("Error: Target directory " + target_dir + " already exists.");
			return;
		}

		Directory.CreateDirectory (target_dir);

		Assembly a = Assembly.LoadFrom (assembly);

		Console.WriteLine ();
		Console.WriteLine ("References (not followed):");
		foreach (AssemblyName reference in a.GetReferencedAssemblies ())
			Console.WriteLine ("  " + reference.Name);
		Console.WriteLine ();

		dllname = Path.GetFileName (assembly);
		AssemblyGen (a);

		//we might not want to do this in future
		File.Copy (dllname, target_dir + dllname);

		string soname = "lib" + NsToFlat (Path.GetFileNameWithoutExtension (assembly)).ToLower () + ".so";

		//create the static makefile
		StreamWriter makefile = new StreamWriter (File.Create (target_dir + "Makefile"));
		StreamReader sr = new StreamReader (Assembly.GetAssembly (typeof(cilc)).GetManifestResourceStream ("res-Makefile"));

		makefile.Write (sr.ReadToEnd ());
		sr.Close ();
		makefile.Close ();

		//create makefile defs
		CodeWriter makefile_defs = new CodeWriter (target_dir + "defs.mk");
		makefile_defs.Indenter = "\t";
		makefile_defs.WriteLine ("ASSEMBLY = " + assembly);
		makefile_defs.WriteLine ("SONAME = " + soname);
		makefile_defs.WriteLine (@"OBJS = $(shell ls *.c | sed -e 's/\.c/.o/')");

		if (extpkgs != String.Empty) {
			makefile_defs.WriteLine ("EXTRAINCLUDES = $(shell pkg-config --cflags" + extpkgs + ")");
			makefile_defs.WriteLine ("EXTRALIBS = $(shell pkg-config --libs" + extpkgs + ")");
		}
		makefile_defs.Close ();

		Console.WriteLine ();

		//identify hits on types that were registered too late
		foreach (string tn in registered_types) {
			if (registry_hits.Contains (tn)) {
				Console.WriteLine ("Warning: " + tn + " was incorrectly registered after it was needed instead of before. Consider re-ordering.");
			}
		}

		MakeReport (registry_hits, "Type registry missed hits", 20);
		Console.WriteLine ();
		//TODO: this count is now wrong
		Console.WriteLine (registered_types.Count + " types generated/seen in " + namespaces.Length + " namespaces; " + warnings_ignored + " types ignored");
		Console.WriteLine ();
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:63,代码来源:cilc.cs

示例3: NamespaceGen


//.........这里部分代码省略.........

		string Hindex_id = "__" + NsToFlat (ns).ToUpper () + "_H__";
		Hindex.WriteLine ("#ifndef " + Hindex_id);
		Hindex.WriteLine ("#define " + Hindex_id);
		Hindex.WriteLine ();

		string Hdecls_id = "__" + NsToFlat (ns).ToUpper () + "_DECLS_H__";
		Hdecls.WriteLine ("#ifndef " + Hdecls_id);
		Hdecls.WriteLine ("#define " + Hdecls_id);
		Hdecls.WriteLine ();

		Cindex.WriteLine ("#include <glib.h>");
		Cindex.WriteLine ("#include <glib-object.h>");
		Cindex.WriteLine ("#include <mono/jit/jit.h>");
		Cindex.WriteLine ();
		Cindex.WriteLine ("#include <mono/metadata/object.h>");
		Cindex.WriteLine ("#include <mono/metadata/debug-helpers.h>");
		Cindex.WriteLine ("#include <mono/metadata/appdomain.h>");
		Cindex.WriteLine ();
		Cindex.WriteLine ("#ifdef CILC_BUNDLE");
		Cindex.WriteLine ("#include \"bundle.h\"");
		Cindex.WriteLine ("#endif");
		Cindex.WriteLine ();

		Cindex.WriteLine ("MonoDomain *" + NsToC (ns) + "_get_mono_domain (void)");
		Cindex.WriteLine ("{");
		Cindex.WriteLine ("static MonoDomain *domain = NULL;");
		Cindex.WriteLine ("if (domain != NULL) return domain;");
		Cindex.WriteLine ("mono_config_parse (NULL);");
		Cindex.WriteLine ("domain = mono_jit_init (\"cilc\");");
		Cindex.WriteLine ();
		Cindex.WriteLine ("#ifdef CILC_BUNDLE");
		Cindex.WriteLine ("mono_register_bundled_assemblies (bundled);");
		Cindex.WriteLine ("#endif");
		Cindex.WriteLine ();

		Cindex.WriteLine ("return domain;");
		Cindex.WriteLine ("}");
		Cindex.WriteLine ();

		Cindex.WriteLine ("MonoAssembly *" + NsToC (ns) + "_get_mono_assembly (void)");
		Cindex.WriteLine ("{");
		Cindex.WriteLine ("static MonoAssembly *assembly = NULL;");
		Cindex.WriteLine ("if (assembly != NULL) return assembly;");
		Cindex.WriteLine ("assembly = mono_domain_assembly_open (" + NsToC (ns) + "_get_mono_domain (), \"" + dllname + "\");");
		Cindex.WriteLine ();

		Cindex.WriteLine ("return assembly;");
		Cindex.WriteLine ("}");
		Cindex.WriteLine ();


		Cindex.WriteLine ("MonoObject *" + NsToC (ns) + "_cilc_glib_gobject_get_mobject (GObject *_handle)");
		Cindex.WriteLine ("{");
		//FIXME: instantiate monobject if it doesn't exist
		Cindex.WriteLine ("return g_object_get_data (G_OBJECT (" + "_handle" + "), \"mono-object\");");
		Cindex.WriteLine ("}");

		Cindex.WriteLine ("gpointer " + NsToC (ns) + "_cilc_glib_mobject_get_gobject (MonoObject *_mono_object)");
		Cindex.WriteLine ("{");
		Cindex.WriteLine ("static MonoAssembly *_mono_assembly = NULL;");
		Cindex.WriteLine ("static MonoMethod *_mono_method = NULL;");
		Cindex.WriteLine ("static MonoClass *_mono_class = NULL;");
		Cindex.WriteLine ("gpointer *retval;");
		Cindex.WriteLine ();
		Cindex.WriteLine ("if (_mono_assembly == NULL) {");
		Cindex.WriteLine ("_mono_assembly = mono_domain_assembly_open (" + NsToC (ns) + "_get_mono_domain (), \"" + "glib-sharp" + "\");");
		Cindex.WriteLine ("}");
		Cindex.WriteLine ("if (_mono_class == NULL) {");
		Cindex.WriteLine ("_mono_class = (MonoClass*) mono_class_from_name ((MonoImage*) mono_assembly_get_image (_mono_assembly), \"GLib\", \"Object\");");
		Cindex.WriteLine ("}");
		Cindex.WriteLine ("if (_mono_method == NULL) {");
		Cindex.WriteLine ("MonoMethodDesc *_mono_method_desc = mono_method_desc_new (\":get_Handle()\", FALSE);");
		Cindex.WriteLine ("_mono_method = mono_method_desc_search_in_class (_mono_method_desc, _mono_class);");
		Cindex.WriteLine ("}");
		Cindex.WriteLine ();
		Cindex.WriteLine ("retval = (gpointer *) mono_object_unbox (mono_runtime_invoke (_mono_method, _mono_object, NULL, NULL));");
		Cindex.WriteLine ("return (gpointer ) *retval;");
		Cindex.WriteLine ("}");
		Cindex.WriteLine ();


		Console.Write ("Generating sources in " + ns);
		foreach (Type t in types) {
			TypeGen (t);
			Console.Write (".");
		}

		Console.WriteLine ();

		Hindex.WriteLine ();
		Hindex.WriteLine ("#endif /* " + Hindex_id + " */");

		Hdecls.WriteLine ();
		Hdecls.WriteLine ("#endif /* " + Hdecls_id + " */");

		Cindex.Close ();
		Hindex.Close ();
		Hdecls.Close ();
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:101,代码来源:cilc.cs

示例4: Generate

	public static void Generate (string fname, string name)
	{
		StreamReader sr = new StreamReader (fname);
		XmlSerializer sz = new XmlSerializer (typeof (xcb));
		xcb xcb = (xcb)sz.Deserialize (sr);

		extName = xcb.extensionxname == null ? "" : xcb.extensionxname;
		isExtension = extName != "";

		cw = new CodeWriter (name + ".cs");
		cwt = new CodeWriter (name + "Types.cs");
		cwi = new CodeWriter (name + "Iface.cs");

		cw.WriteLine ("using System;", cwt, cwi);
		cw.WriteLine ("using System.Collections;", cwt);
		cw.WriteLine ("using System.Collections.Generic;", cwt);
		cw.WriteLine ("using System.Runtime.InteropServices;", cwt);
		cw.WriteLine ("using Mono.Unix;", cwt);
		cw.WriteLine ("using Xnb.Protocol." + "Xnb" + ";", cwt);
		cw.WriteLine ("using Xnb.Protocol." + "XProto" + ";", cwt);
		cw.WriteLine ("", cwt, cwi);
		//cw.WriteLine ("namespace Xnb", cwt);

		cw.WriteLine ("namespace Xnb");
		cwt.WriteLine ("namespace Xnb.Protocol." + name);
		
		cw.WriteLine ("{", cwt);
		cw.WriteLine ("using Protocol." + name + ";");
		cw.WriteLine ("public class " + name + " : Extension");
		cwi.WriteLine ("public interface I" + name);
		cw.WriteLine ("{", cwi);
		cw.WriteLine ("public override string XName");
		cw.WriteLine ("{");
		cw.WriteLine ("get {");
		cw.WriteLine ("return \"" + extName + "\";");
		cw.WriteLine ("}");
		cw.WriteLine ("}");
		cw.WriteLine ();

		cwt.WriteLine ("#pragma warning disable 0169, 0414");

		foreach (object o in xcb.Items) {
			if (o == null)
				continue;
			else if (o is @xidtype)
				GenXidType (o as @xidtype);
			else if (o is @errorcopy)
				GenErrorCopy (o as @errorcopy);
			else if (o is @eventcopy)
				GenEventCopy (o as @eventcopy);
			else if (o is @struct)
				GenStruct (o as @struct);
			else if (o is @union)
				GenUnion (o as @union);
			else if (o is @enum)
				GenEnum (o as @enum);
			else if (o is @event)
				GenEvent (o as @event, name);
			else if (o is @request) {
				GenRequest (o as @request, name);
				GenFunction (o as @request, name);
			} else if (o is @error)
				GenError (o as @error, name);
		}

		cwt.WriteLine ("#pragma warning restore 0169, 0414");

		cwi.WriteLine ("}");
		cw.WriteLine ("}");
		cw.WriteLine ("}", cwt);

		cw.Close ();
		cwt.Close ();
		cwi.Close ();
	}
开发者ID:emtees,项目名称:old-code,代码行数:75,代码来源:Generator.cs


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