public CSharpConverterOptions() { Plugins = new List <ICSharpConverterPlugin>() { new DefaultCommentConverter(), new DefaultGetCSharpNamePlugin(), new DefaultContainerResolver(), new DefaultTypedefConverter(), new DefaultEnumConverter(), new DefaultEnumItemConverter(), new DefaultFunctionConverter(), new DefaultParameterConverter(), new DefaultInterfaceConverter(), new DefaultStructConverter(), new DefaultFieldConverter(), new DefaultFunctionTypeConverter(), new DefaultTypeConverter(), new DefaultDllImportConverter(), new DefaultMappingRulesConverter(), }; MappingRules = new CppMappingRules(); DefaultNamespace = "LibNative"; DefaultOutputFilePath = "/LibNative.generated.cs"; DefaultClassLib = "libnative"; DefaultDllImportNameAndArguments = "\"libnative\""; GenerateAsInternal = false; GenerateEnumItemAsFields = true; TypedefCodeGenKind = CppTypedefCodeGenKind.Wrap; TypedefWrapWhiteList = new HashSet <string>(); Tags = new Dictionary <string, object>(); DefaultCharSet = CharSet.Ansi; AllowFixedSizeBuffers = true; DefaultMarshalForString = new CSharpMarshalAttribute(CSharpUnmanagedKind.LPStr); DefaultMarshalForBool = new CSharpMarshalAttribute(CSharpUnmanagedKind.U1); }
public static CppElementMappingRule MarshalAs(this CppElementMappingRule mappingRule, CSharpMarshalAttribute marshalAttribute, bool cloneAttribute = true) { if (marshalAttribute == null) { throw new ArgumentNullException(nameof(marshalAttribute)); } var clonedAttribute = cloneAttribute ? marshalAttribute.Clone() : marshalAttribute; mappingRule.CSharpElementActions.Add((converter, element, matches) => { var csField = element as CSharpField; var csParam = element as CSharpParameter; var csMethod = element as CSharpMethod; if (csField == null && csParam == null && csMethod == null) { return; } var type = csField?.FieldType ?? csParam?.ParameterType ?? csMethod?.ReturnType; // Should not happen, but in case if (type == null) { return; } if (type is CSharpTypeWithAttributes cppTypeWithAttributes) { for (var i = cppTypeWithAttributes.Attributes.Count - 1; i >= 0; i--) { var attr = cppTypeWithAttributes.Attributes[i]; if (attr is CSharpMarshalAttribute) { cppTypeWithAttributes.Attributes.RemoveAt(i); cppTypeWithAttributes.Attributes.Insert(i, clonedAttribute); return; } } cppTypeWithAttributes.Attributes.Add(clonedAttribute); } else { var typeWithAttributes = new CSharpTypeWithAttributes(type); typeWithAttributes.Attributes.Add(clonedAttribute); if (csField != null) { csField.FieldType = typeWithAttributes; } else if (csParam != null) { csParam.ParameterType = typeWithAttributes; } else if (csMethod != null) { csMethod.ReturnType = typeWithAttributes; } } }); return(mappingRule); }