protected override void BuildTypedef(CodeNamespace ns, CppTypedef typedef) { TypeDesc fieldType = GetTypeDesc(typedef.ElementType); string baseTypeName = ResolveCefType(fieldType.ToString()); string aliasTypeName = GetClassName(typedef.Name); if (aliasTypeName == baseTypeName) { throw new InvalidOperationException(); } var decl = new CodeStruct(aliasTypeName); decl.Attributes = CodeAttributes.Public | CodeAttributes.Unsafe | CodeAttributes.Partial; decl.Comments.AddVSDocComment(typedef.Comment, "summary"); var attr = new CustomCodeAttribute(typeof(StructLayoutAttribute)); attr.AddParameter(LayoutKind.Sequential); decl.CustomAttributes.Add(attr); var field = new CodeField(baseTypeName, "Base"); field.Attributes = CodeAttributes.Public; //field.CustomAttributes.Add(new CustomCodeAttribute(typeof(FieldOffsetAttribute)) { Parameters = { "0" } }); decl.Members.Add(field); ns.Types.Add(decl); }
public static void AddMethodImplForwardRefAttribute(this IList <CustomCodeAttribute> list) { var attr = new CustomCodeAttribute(typeof(MethodImplAttribute)); attr.AddParameter(MethodImplOptions.ForwardRef); list.Add(attr); }
protected override void BuildClass(CodeNamespace ns, CppClass @class) { if (@class.TypeKind != CppTypeKind.StructOrClass || @class.ClassKind != CppClassKind.Struct) { if (@class.Name == "CefStringBase") { return; } //if (@class.ClassKind == CppClassKind.Class) // return; Console.WriteLine(@class.Name); throw new NotImplementedException(); } string className = GetClassName(@class.Name); string sourceFile = @class.GetSourceFile(); if (sourceFile.EndsWith("_capi.h")) { string fname = Path.GetFileName(sourceFile); fname = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(sourceFile)), fname.Remove(fname.Length - 7) + ".h"); if (File.Exists(fname)) { string cppClassName = className.EndsWith("_t") ? className.Remove(className.Length - 2).ToUpperCamel() : className.ToUpperCamel(); string prevLine = null; foreach (string line in File.ReadLines(fname)) { if (line.IndexOf("class " + cppClassName + " ", StringComparison.OrdinalIgnoreCase) != -1) { if (prevLine.Contains("source=library")) { Extensions.StructTypes.Add(className, CefSourceKind.Library); } else if (prevLine.Contains("source=client")) { Extensions.StructTypes.Add(className, CefSourceKind.Client); } break; } prevLine = line; } } } var decl = new CodeStruct(className); decl.Attributes = CodeAttributes.Public | CodeAttributes.Unsafe | CodeAttributes.Partial; decl.Comments.AddVSDocComment(@class.Comment, "summary"); var attr = new CustomCodeAttribute(typeof(StructLayoutAttribute)); attr.AddParameter(LayoutKind.Sequential); decl.CustomAttributes.Add(attr); //CLSCompliant if (@class.Functions.Count > 0) { if (@class.Fields.Count > 0) { throw new NotSupportedException(); } foreach (CppFunction fn in @class.Functions) { DefineFunction(decl, fn); } } foreach (CppField field in @class.Fields) { DefineField(decl, field); } ns.Types.Add(decl); }