예제 #1
0
        internal void DefineBuilders()
        {
            if (realField == null)
            {
                // resolve attributes
                FieldAttributes field_attrs = Enums.ToFieldAttributes(memberDesc.MemberAttributes);
                field_attrs |= FieldAttributes.Literal;

                Debug.Assert((field_attrs & FieldAttributes.Static) != 0);

                // convert name to CLR notation:
                var clrName = qualifiedName.ToClrNotation(0, 0);

                // type
                Type type = Types.Object[0];
                if (this.HasValue && this.Value != null)
                {
                    type = this.Value.GetType();
                }

                // define public static const field:
                if (scriptTypeBuilder != null)  // const in SSA or MSA
                {
                    realField = scriptTypeBuilder.DefineField(clrName, type, field_attrs);
                }
                else // const in Pure or Transient
                {
                    ModuleBuilder module_builder = this.DeclaringModuleBuilder.AssemblyBuilder.RealModuleBuilder;

                    // represent the class constant as a static initonly field

                    realField = ReflectionUtils.DefineGlobalField(module_builder, clrName, type, field_attrs);
                }

                Debug.Assert(realField != null);

                // set value
                if (this.HasValue)
                {
                    ((FieldBuilder)realField).SetConstant(this.Value);
                }
            }
        }