public static CodeCustomAttribute Create (Type attributeType, Type [] ctorArgTypes, CodeLiteral [] ctorArgs, MemberInfo [] members, CodeLiteral [] values)
		{
			ArrayList props = new ArrayList ();
			ArrayList pvalues  = new ArrayList ();
			ArrayList fields = new ArrayList ();
			ArrayList fvalues = new ArrayList ();
			for (int i = 0; i < members.Length; i++) {
				if (members [i] == null)
					throw new ArgumentException (String.Format ("MemberInfo at {0} was null for type {1}.", i, attributeType));
				if (members [i] is PropertyInfo) {
					props.Add ((PropertyInfo) members [i]);
					pvalues.Add (values [i].Value);
				} else {
					fields.Add ((FieldInfo) members [i]);
					fvalues.Add (values [i].Value);
				}
			}

			ConstructorInfo ci = attributeType.GetConstructor (ctorArgTypes);
			CustomAttributeBuilder cab = new CustomAttributeBuilder (
				ci, ctorArgs,
				(PropertyInfo []) props.ToArray (typeof (PropertyInfo)), pvalues.ToArray (),
				(FieldInfo []) fields.ToArray (typeof (FieldInfo)), fvalues.ToArray ());

			CodeCustomAttribute attr = new CodeCustomAttribute (
				cab, attributeType, ci, ctorArgs, members, values);

			return attr;
		}
Beispiel #2
0
        public CodeCustomAttribute CreateCustomAttribute(Type attributeType, Type [] ctorArgTypes, CodeLiteral [] ctorArgs, FieldInfo [] fields, CodeLiteral [] fieldValues)
        {
            CodeCustomAttribute cca = CodeCustomAttribute.Create(
                attributeType, ctorArgTypes, ctorArgs, fields, fieldValues);

            SetCustomAttribute(cca);
            return(cca);
        }
Beispiel #3
0
        public CodeCustomAttribute CreateCustomAttribute(Type attributeType, Type [] ctorArgTypes, object [] ctorArgs, string [] namedArgFieldNames, object [] namedArgValues)
        {
            CodeCustomAttribute cca = CodeCustomAttribute.Create(
                attributeType, ctorArgTypes, ctorArgs, namedArgFieldNames, namedArgValues);

            SetCustomAttribute(cca);
            return(cca);
        }
Beispiel #4
0
 void SetCustomAttribute(CodeCustomAttribute cca)
 {
     if (methodBase is MethodBuilder)
     {
         ((MethodBuilder)methodBase).SetCustomAttribute(cca.Builder);
     }
     else if (methodBase is ConstructorBuilder)
     {
         ((ConstructorBuilder)methodBase).SetCustomAttribute(cca.Builder);
     }
     customAttributes.Add(cca);
 }
Beispiel #5
0
        public static CodeCustomAttribute Create(Type attributeType, Type [] ctorArgTypes, CodeLiteral [] ctorArgs, MemberInfo [] members, CodeLiteral [] values)
        {
            ArrayList props   = new ArrayList();
            ArrayList pvalues = new ArrayList();
            ArrayList fields  = new ArrayList();
            ArrayList fvalues = new ArrayList();

            for (int i = 0; i < members.Length; i++)
            {
                if (members [i] == null)
                {
                    throw new ArgumentException(String.Format("MemberInfo at {0} was null for type {1}.", i, attributeType));
                }
                if (members [i] is PropertyInfo)
                {
                    props.Add((PropertyInfo)members [i]);
                    pvalues.Add(values [i].Value);
                }
                else
                {
                    fields.Add((FieldInfo)members [i]);
                    fvalues.Add(values [i].Value);
                }
            }

            ConstructorInfo        ci  = attributeType.GetConstructor(ctorArgTypes);
            CustomAttributeBuilder cab = new CustomAttributeBuilder(
                ci, ctorArgs,
                (PropertyInfo [])props.ToArray(typeof(PropertyInfo)), pvalues.ToArray(),
                (FieldInfo [])fields.ToArray(typeof(FieldInfo)), fvalues.ToArray());

            CodeCustomAttribute attr = new CodeCustomAttribute(
                cab, attributeType, ci, ctorArgs, members, values);

            return(attr);
        }
Beispiel #6
0
		void SetCustomAttribute (CodeCustomAttribute cca)
		{
			if (methodBase is MethodBuilder)
				((MethodBuilder) methodBase).SetCustomAttribute (cca.Builder);
			else if (methodBase is ConstructorBuilder)
				((ConstructorBuilder) methodBase).SetCustomAttribute (cca.Builder);
			customAttributes.Add (cca);
		}
Beispiel #7
0
 void SetCustomAttribute(CodeCustomAttribute cca)
 {
     PropertyBuilder.SetCustomAttribute(cca.Builder);
     customAttributes.Add(cca);
 }
		void SetCustomAttribute (CodeCustomAttribute cca)
		{
			PropertyBuilder.SetCustomAttribute (cca.Builder);
			customAttributes.Add (cca);
		}
Beispiel #9
0
        public void PrintCode(CodeWriter cw)
        {
            for (int n = 0; n < customAttributes.Count; n++)
            {
                CodeCustomAttribute cca = customAttributes [n] as CodeCustomAttribute;
                if (n > 0)
                {
                    cw.WriteLine("");
                }
                cca.PrintCode(cw);
            }

/*			if ((typeBuilder.Attributes & TypeAttributes.Abstract) != 0) cw.Write ("abstract ");
 *                      if ((typeBuilder.Attributes & TypeAttributes.NestedAssembly) != 0) cw.Write ("internal ");
 *                      if ((typeBuilder.Attributes & TypeAttributes.NestedPrivate) != 0) cw.Write ("private ");
 */         if ((typeBuilder.Attributes & TypeAttributes.Public) != 0)
            {
                cw.Write("public ");
            }
            cw.Write("class ").Write(typeBuilder.Name);

            bool dots = false;

            if (baseType != null && baseType != typeof(object))
            {
                cw.Write(" : " + baseType);
                dots = true;
            }

            if (interfaces != null && interfaces.Length > 0)
            {
                if (!dots)
                {
                    cw.Write(" : ");
                }
                else
                {
                    cw.Write(", ");
                }
                for (int n = 0; n < interfaces.Length; n++)
                {
                    if (n > 0)
                    {
                        cw.Write(", ");
                    }
                    cw.Write(interfaces[n].ToString());
                }
            }

            cw.EndLine().WriteLineInd("{");

            foreach (FieldInfo f in fields)
            {
                cw.BeginLine();
                ArrayList atts = (ArrayList)fieldAttributes [f];
                foreach (CodeCustomAttribute a in atts)
                {
                    a.PrintCode(cw);
                }
                if ((f.Attributes & FieldAttributes.Static) != 0)
                {
                    cw.Write("static ");
                }
                cw.Write(f.FieldType.Name + " ");
                cw.Write(f.Name + ";");
                cw.EndLine();
                cw.WriteLine("");
            }

            for (int n = 0; n < properties.Count; n++)
            {
                CodeProperty prop = properties [n] as CodeProperty;
                if (n > 0)
                {
                    cw.WriteLine("");
                }
                prop.PrintCode(cw);
            }

            for (int n = 0; n < methods.Count; n++)
            {
                CodeMethod met = methods[n] as CodeMethod;
                if (n > 0)
                {
                    cw.WriteLine("");
                }
                met.PrintCode(cw);
            }
            cw.WriteLineUnind("}");
        }