diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs
index 35f63b22..d7e86de1 100644
--- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs
+++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs
@@ -361,6 +361,12 @@ namespace CppSharp.Generators.CSharp
private void GenerateClassMarshals(Class @class)
{
+ WriteLine("int CppSharp.Runtime.ICppMarshal.NativeDataSize");
+ WriteStartBraceIndent();
+ WriteLine("get {{ return {0}; }}", @class.Layout.DataSize);
+ WriteCloseBraceIndent();
+ NewLine();
+
WriteLine("void CppSharp.Runtime.ICppMarshal.MarshalManagedToNative(global::System.IntPtr instance)");
WriteStartBraceIndent();
WriteCloseBraceIndent();
diff --git a/src/Runtime/Interfaces.cs b/src/Runtime/Interfaces.cs
index 67569c82..40eb3465 100644
--- a/src/Runtime/Interfaces.cs
+++ b/src/Runtime/Interfaces.cs
@@ -25,6 +25,11 @@ namespace CppSharp.Runtime
{
public interface ICppMarshal
{
+ ///
+ /// Gets the native data size for the object.
+ ///
+ int NativeDataSize { get; }
+
///
/// Converts the managed data to unmanaged data.
/// ///