private static void TranslateClass(TextWriter writer, CppSharp.AST.TranslationUnit unit) { foreach (var @class in unit.Classes) { if (@class.Fields.Count == 0) { continue; } writer.WriteLine("public struct " + @class.Name + "{"); foreach (var field in @class.Fields) { string marshalTag = TypeHeloer.GetMarshalTag(field.Type); if (!string.IsNullOrEmpty(marshalTag)) { writer.WriteLine("\t" + marshalTag); } string type = TypeHeloer.GetSystemTypeName(field.Type, true); writer.Write("\tpublic "); writer.Write(type); writer.Write(" "); writer.WriteLine(field.Name + ";"); writer.WriteLine(); } writer.WriteLine("};"); writer.WriteLine(); } }
private static void TranslatFunction(TextWriter writer, CppSharp.AST.TranslationUnit unit) { /* * [DllImport(AVCODEC), SuppressUnmanagedCodeSecurity] * public static extern int avcodec_default_get_buffer2(IntPtr pAVCodecContext, IntPtr pAVFrame, int flags); */ foreach (var function in unit.Functions) { writer.WriteLine("[DllImport(" + unit.FileNameWithoutExtension.ToUpper() + "), SuppressUnmanagedCodeSecurity]"); writer.Write("public static extern "); writer.Write(TypeHeloer.GetSystemTypeName(function.ReturnType.Type, true)); writer.Write(" "); writer.Write(function.Name); writer.Write("(\r\n"); for (int i = 0; i < function.Parameters.Count; i++) { var param = function.Parameters[i]; string marshalTag = TypeHeloer.GetMarshalTag(param.Type); if (!string.IsNullOrEmpty(marshalTag)) { writer.WriteLine("\t" + marshalTag); } writer.Write("\t" + TypeHeloer.GetSystemTypeName(param.Type, true)); writer.Write(" "); if (!string.IsNullOrEmpty(param.Name)) { writer.Write(param.Name); } else { writer.Write(" __arg" + i.ToString()); } if (i != (function.Parameters.Count - 1)) { writer.Write(", \r\n"); } } writer.Write(");"); writer.Write("\r\n\r\n"); } }