diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 018f675f..ee22f3ac 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -308,12 +308,12 @@ namespace CppSharp.Generators.CSharp } PushBlock(BlockKind.Class); - GenerateDeclarationCommon(@class); + GenerateDeclarationCommon(@class); GenerateClassSpecifier(@class); NewLine(); WriteStartBraceIndent(); - + if (!@class.IsAbstractImpl) GenerateClassInternals(@class); @@ -569,7 +569,7 @@ namespace CppSharp.Generators.CSharp // private classes must be visible to because the internal structs can be used in dependencies // the proper fix is InternalsVisibleTo var keywords = new List(); - + keywords.Add(@class.Access == AccessSpecifier.Protected ? "protected internal" : "public"); keywords.Add("unsafe"); @@ -833,7 +833,7 @@ namespace CppSharp.Generators.CSharp var marshal = new CSharpMarshalManagedToNativePrinter(ctx); ctx.Declaration = field; - var arrayType = field.Type as ArrayType; + var arrayType = field.Type as ArrayType ?? field.QualifiedType.Type.Desugar() as ArrayType; if (arrayType != null && @class.IsValueType) { @@ -1077,7 +1077,7 @@ namespace CppSharp.Generators.CSharp }; TypePrinter.PopContext(); - var arrayType = field.Type as ArrayType; + var arrayType = field.Type as ArrayType ?? field.QualifiedType.Type.Desugar() as ArrayType; if (arrayType != null && @class.IsValueType) ctx.ReturnVarName = HandleValueArray(arrayType, field); @@ -1284,7 +1284,7 @@ namespace CppSharp.Generators.CSharp private void GenerateVariable(Class @class, Variable variable) { PushBlock(BlockKind.Variable); - + GenerateDeclarationCommon(variable); WriteLine("public static {0} {1}", variable.Type, variable.Name); WriteStartBraceIndent(); @@ -1423,7 +1423,7 @@ namespace CppSharp.Generators.CSharp if (Context.ParserOptions.IsMicrosoftAbi) WriteLine("__OriginalVTables = new void*[] {{ {0} }};", string.Join(", ", - @class.Layout.VTablePointers.Select(v => + @class.Layout.VTablePointers.Select(v => $"*(void**) ({Helpers.InstanceIdentifier} + {v.Offset})"))); else WriteLine( @@ -1565,7 +1565,7 @@ namespace CppSharp.Generators.CSharp if (method.IsGenerated) { WriteLine("{0}.{1}({2});", Helpers.TargetIdentifier, - method.Name, string.Join(", ", marshals)); + method.Name, string.Join(", ", marshals)); } else { @@ -2156,7 +2156,7 @@ namespace CppSharp.Generators.CSharp else if (method.ExplicitInterfaceImpl != null) Write("{0} {1}.{2}(", method.OriginalReturnType, method.ExplicitInterfaceImpl.Name, functionName); - else if (method.OperatorKind == CXXOperatorKind.Conversion || + else if (method.OperatorKind == CXXOperatorKind.Conversion || method.OperatorKind == CXXOperatorKind.ExplicitConversion) Write("{0} {1}(", functionName, method.OriginalReturnType); else @@ -2277,7 +2277,7 @@ namespace CppSharp.Generators.CSharp Class @class; return p.Type.IsPointerToPrimitiveType() && p.Usage == ParameterUsage.InOut && p.HasDefaultValue ? "ref param" + index++ - : (( p.Type.TryGetClass(out @class) && @class.IsInterface) ? "param" + index++ + : (( p.Type.TryGetClass(out @class) && @class.IsInterface) ? "param" + index++ : ExpressionPrinter.VisitParameter(p)); } @@ -2361,7 +2361,7 @@ namespace CppSharp.Generators.CSharp } else { - WriteLine("return {0}.GetHashCode();", Helpers.InstanceIdentifier); + WriteLine("return {0}.GetHashCode();", Helpers.InstanceIdentifier); } WriteCloseBraceIndent(); } @@ -2729,7 +2729,7 @@ namespace CppSharp.Generators.CSharp if (needsFixedThis && operatorParam == null) WriteCloseBraceIndent(); - + var numFixedBlocks = @params.Count(param => param.HasUsingBlock); for(var i = 0; i < numFixedBlocks; ++i) WriteCloseBraceIndent(); diff --git a/tests/CSharp/CSharp.cs b/tests/CSharp/CSharp.cs index 09b0dea9..e1e587d8 100644 --- a/tests/CSharp/CSharp.cs +++ b/tests/CSharp/CSharp.cs @@ -33,7 +33,7 @@ namespace CppSharp.Tests ctx.SetClassAsValueType("QPoint"); ctx.SetClassAsValueType("QSize"); ctx.SetClassAsValueType("QRect"); - + ctx.SetClassAsValueType("StructTestArrayTypeFromTypedef"); ctx.IgnoreClassWithName("IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor"); } diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index 5b247d57..24bc8b2c 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -1169,4 +1169,10 @@ struct DLL_API ForwardDeclaredStruct { }; DLL_API ForwardDeclaredStruct* createForwardDeclaredStruct(int i); -DLL_API int useForwardDeclaredStruct(ForwardDeclaredStruct* s); \ No newline at end of file +DLL_API int useForwardDeclaredStruct(ForwardDeclaredStruct* s); + +typedef char charsArrayType[13]; +struct StructTestArrayTypeFromTypedef +{ + charsArrayType arr; +}; \ No newline at end of file