コード例 #1
0
ファイル: CodeClass.cs プロジェクト: zgramana/mono
        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);
        }
コード例 #2
0
ファイル: CodeClass.cs プロジェクト: nlhepler/mono
		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;
		}