Example #1
0
        public CodeFieldReference DefineField(string name, Type type, FieldAttributes attrs, CodeExpression initialValue, params CodeCustomAttribute [] customAttributes)
        {
            FieldBuilder fb = typeBuilder.DefineField(GetFieldName(name), type, attrs);

            foreach (CodeCustomAttribute a in customAttributes)
            {
                fb.SetCustomAttribute(a.Builder);
            }
            fieldAttributes [fb] = new ArrayList(customAttributes);
            fields.Add(fb);
            CodeFieldReference fr;

            if ((attrs & FieldAttributes.Static) != 0)
            {
                fr = new CodeFieldReference(fb);
            }
            else
            {
                fr = new CodeFieldReference(new CodeArgumentReference(TypeBuilder, 0, "this"), fb);
            }

            if (null != (object)initialValue)
            {
                CodeBuilder cb = (attrs & FieldAttributes.Static) == 0 ? GetInstanceInitBuilder() : GetClassInitBuilder();
                cb.Assign(fr, initialValue);
            }
            return(fr);
        }
Example #2
0
		public CodeFieldReference DefineField (string name, Type type, FieldAttributes attrs, CodeExpression initialValue, params CodeCustomAttribute [] customAttributes)
		{
			FieldBuilder fb = typeBuilder.DefineField (GetFieldName (name), type, attrs);
			foreach (CodeCustomAttribute a in customAttributes)
				fb.SetCustomAttribute (a.Builder);
			fieldAttributes [fb] = new ArrayList (customAttributes);
			fields.Add (fb);
			CodeFieldReference fr;
			if ((attrs & FieldAttributes.Static) != 0)
				fr = new CodeFieldReference (fb);
			else
				fr = new CodeFieldReference (new CodeArgumentReference (TypeBuilder, 0, "this"), fb);
			
			if (null != (object) initialValue) {
				CodeBuilder cb = (attrs & FieldAttributes.Static) == 0 ? GetInstanceInitBuilder () : GetClassInitBuilder (); 
				cb.Assign (fr, initialValue);
			}
			return fr;
		}