dimanche 1 février 2015

field 'FIELD' is never assigned to, and will always have its default value


Vote count:

0





private struct TOKEN_USER
{
internal SID_AND_ATTRIBUTES User;
}

[StructLayout(LayoutKind.Sequential)]
private struct SID_AND_ATTRIBUTES
{
internal IntPtr Sid;
private int Attributes;
}


Initializing the structure to default:



TOKEN_USER tokenUser = default(TOKEN_USER);


Then making the two required calls to retrieve the pointer to the structure: (not relevant to the question) using this:



GetTokenInformation(tokenhandle, TokenInformationClass.TokenUser, sid, sidlength, ref sidlength);


and then marshalling back to a structure.



tokenUser = (TOKEN_USER)Marshal.PtrToStructure(sid, tokenUser.GetType());


which works, but the compiler warns me that the 'User' field in TOKEN_USER is unassigned.


R# suggests me initializing it from the constructor:



public TOKEN_USER(SID_AND_ATTRIBUTES user) : this(user)
{
}


However, this doesn't compile, with error "Constructor cannot call itself". My question is, should i just assign it to SID_AND_ATTRIBUTES (default) to meet the compiler's requirement, or ignore it?



asked 34 secs ago







field 'FIELD' is never assigned to, and will always have its default value

Aucun commentaire:

Enregistrer un commentaire