Example #1
0
 public SymbolScope(SymbolScope outerScope)
 {
     mOuterScope       = outerScope;
     mNamespace        = $"ns{Guid.NewGuid():N}".Substring(0, 10);
     mStructureBuilder = new DynamicStructureBuilder(mNamespace);
     mDeclaredSymbols  = new Dictionary <Symbol, object>();
 }
Example #2
0
        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);
        }
Example #3
0
 public static IDynamicBufferBuilder Create([NotNull] DynamicStructureBuilder context, [NotNull] string typeName) => new DynamicStructure(context, typeName);