Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Attribute on auto-properties for backing fields #7880

Closed
zdimension opened this issue Jan 11, 2016 · 2 comments
Closed

Proposal: Attribute on auto-properties for backing fields #7880

zdimension opened this issue Jan 11, 2016 · 2 comments

Comments

@zdimension
Copy link

Recently, I started writing some game engin that reads some 15 years old file format (Tomb Raider II levels) and these levels are made of structures (look here) that contains arrays. Most are fixed-size.
So I needed to do something like that:

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public ushort[] SomeArray { get; set; }

It works, but if I replace ushort by a structure, here tr2_colour, I get an error.

public struct tr2_colour
{
    public byte Red;
    public byte Green;
    public byte Blue;
}

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public tr2_colour[] Palette { get; set; }

I get this error: Attribute 'System.Runtime.InteropServices.MarshalAsAttribute' is not valid on this declaration type. It is valid on Field, Parameter, ReturnValue only.
So I need to make that property a property with backing field so that I can put the MarshalAs on the field that looks like that private tr2_colour[] _palette; and then it works.
It'd be great if it was possible to put attributes on auto-properties so that they go automatically on the backing field.

@HaloFour
Copy link

Check out #7004.

@zdimension
Copy link
Author

Ah I'm sorry I didn't see it. I think I can close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants