76 lines
1.9 KiB
C#
76 lines
1.9 KiB
C#
using System.Runtime.InteropServices;
|
|||
|
|
using Microsoft.Cci;
|
||
|
|
using Microsoft.CodeAnalysis.Emit;
|
||
|
|
|
||
|
|
namespace Microsoft.CodeAnalysis.CodeGen;
|
||
|
|
|
||
|
|
internal sealed class ExplicitSizeStruct : DefaultTypeDef, INestedTypeDefinition, INamedTypeDefinition, ITypeDefinition, IDefinition, IReference, ITypeReference, INamedTypeReference, INamedEntity, ITypeDefinitionMember, ITypeMemberReference, INestedTypeReference
|
||
|
|
{
|
||
|
|
private readonly uint _size;
|
||
|
|
|
||
|
|
private readonly ushort _alignment;
|
||
|
|
|
||
|
|
private readonly INamedTypeDefinition _containingType;
|
||
|
|
|
||
|
|
private readonly ITypeReference _sysValueType;
|
||
|
|
|
||
|
|
public override ushort Alignment => _alignment;
|
||
|
|
|
||
|
|
public override LayoutKind Layout => LayoutKind.Explicit;
|
||
|
|
|
||
|
|
public override uint SizeOf => _size;
|
||
|
|
|
||
|
|
public string Name
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
if (_alignment != 1)
|
||
|
|
{
|
||
|
|
return $"__StaticArrayInitTypeSize={_size}_Align={_alignment}";
|
||
|
|
}
|
||
|
|
return $"__StaticArrayInitTypeSize={_size}";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public ITypeDefinition ContainingTypeDefinition => _containingType;
|
||
|
|
|
||
|
|
public TypeMemberVisibility Visibility => TypeMemberVisibility.Private;
|
||
|
|
|
||
|
|
public override bool IsValueType => true;
|
||
|
|
|
||
|
|
public override INestedTypeReference AsNestedTypeReference => this;
|
||
|
|
|
||
|
|
internal ExplicitSizeStruct(uint size, ushort alignment, PrivateImplementationDetails containingType, ITypeReference sysValueType)
|
||
|
|
{
|
||
|
|
_size = size;
|
||
|
|
_alignment = alignment;
|
||
|
|
_containingType = containingType;
|
||
|
|
_sysValueType = sysValueType;
|
||
|
|
}
|
||
|
|
|
||
|
|
public override string ToString()
|
||
|
|
{
|
||
|
|
return _containingType.ToString() + "." + Name;
|
||
|
|
}
|
||
|
|
|
||
|
|
public override ITypeReference GetBaseClass(EmitContext context)
|
||
|
|
{
|
||
|
|
return _sysValueType;
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void Dispatch(MetadataVisitor visitor)
|
||
|
|
{
|
||
|
|
visitor.Visit(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
public ITypeReference GetContainingType(EmitContext context)
|
||
|
|
{
|
||
|
|
return _containingType;
|
||
|
|
}
|
||
|
|
|
||
|
|
public override INestedTypeDefinition AsNestedTypeDefinition(EmitContext context)
|
||
|
|
{
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
}
|