private AcceleratedDynamicBuffer([NotNull] DynamicHardwareConstantBufferContext context, [NotNull] string typeName) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (typeName.NormalizeNull() == null) { throw new ArgumentNullException(nameof(typeName)); } if (context.ContainsBuilder(typeName.Trim())) { throw new ArgumentException(nameof(typeName), $"The type \"{typeName}\" was already defined in the given context."); } var module = context.GetModuleBuilder(); if (module == null) { throw new ObjectDisposedException(nameof(DynamicHardwareConstantBufferContext), $"The {nameof(DynamicHardwareConstantBufferContext)} was already disposed."); } mProvider = context.GetProvider(); mTypeName = typeName; mTypeBuilder = module.DefineType(typeName.Trim(), TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.ExplicitLayout | TypeAttributes.Serializable | TypeAttributes.AnsiClass, typeof(ValueType)); mFieldNames = new List <StringKey>(); mFields = new Dictionary <StringKey, FieldInfo>(); mFieldBuilders = new Dictionary <StringKey, FieldBuilder>(); var structLayoutAttributeConstructor = typeof(StructLayoutAttribute).GetConstructor(new[] { typeof(LayoutKind) }).AssertNotNull(); var structLayoutAttributeBuilder = new CustomAttributeBuilder(structLayoutAttributeConstructor, new object[] { LayoutKind.Sequential }); mContext = context; mTypeName = typeName; mTypeBuilder.SetCustomAttribute(structLayoutAttributeBuilder); mContext.AddBuilder(mTypeName, this); }
public static IDynamicBufferBuilder Create([NotNull] DynamicHardwareConstantBufferContext context, [NotNull] string typeName) => new AcceleratedDynamicBuffer(context, typeName);