Example #1
0
        private IReadOnlyList <StatementSyntaxNode> GenerateClassFields(ITypeBuilder type, IReadOnlyList <FieldSyntaxNode> fields, CodeGenerationStore store,
                                                                        ISyntaxNode syntaxNode)
        {
            var definedFields   = new List <IFieldInfo>();
            var initExpressions = new List <StatementSyntaxNode>();

            store.Fields.Add(type, definedFields);
            foreach (var field in fields)
            {
                var fieldType = store.TypeDefLookup(field.Type);

                typeChecker !.AssertTypeIsNotVoid(fieldType);

                var definedField = type.DefineField(field.Name, fieldType, FieldAttributes.Public);
                definedFields.Add(definedField);
                if (field.Expression != null)
                {
                    initExpressions.Add(new ExpressionEqualsExpressionSyntaxNode(field, new VariableSyntaxNode(field, field.Name), field.Expression));
                }
            }

            initExpressions.Add(new BaseClassConstructorSyntax(syntaxNode));

            return(initExpressions);
        }
Example #2
0
        public IFieldBuilder DefineField(string name, Type type, FieldAttributes attributes)
        {
            ArgumentUtility.CheckNotNullOrEmpty("name", name);
            ArgumentUtility.CheckNotNull("type", type);

            var emittableType = EmittableOperandProvider.GetEmittableType(type);
            var fieldBuilder  = _typeBuilder.DefineField(name, emittableType, attributes);

            return(new FieldBuilderDecorator(fieldBuilder, EmittableOperandProvider));
        }