public SymbolScope(SymbolScope outerScope) { mOuterScope = outerScope; mNamespace = $"ns{Guid.NewGuid():N}".Substring(0, 10); mStructureBuilder = new DynamicStructureBuilder(mNamespace); mDeclaredSymbols = new Dictionary <Symbol, object>(); }
private DynamicStructure([NotNull] DynamicStructureBuilder 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(DynamicStructureBuilder), $"The {nameof(DynamicStructureBuilder)} was already disposed."); } 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] DynamicStructureBuilder context, [NotNull] string typeName) => new DynamicStructure(context, typeName);