private Widget GetWidget (CustomAttributeCollection cac)
		{
			FontDescription fd = FontDescription.FromString ("Courier 10 Pitch 10");

			VBox vbox = new VBox (false, 0);

			ScrolledWindow sw = new ScrolledWindow ();
			sw.AddWithViewport (vbox);
			
			if ((cac != null) && (cac.Count > 0)) {
				foreach (CustomAttribute ca in cac) {
 					TextView textview = new TextView ();
					textview.Editable = false;
					textview.Buffer.Text = Format (ca);
					textview.ModifyFont (fd);
					
					Expander expander = new Expander (ca.Constructor.DeclaringType.FullName);
					expander.Add (textview);
					
					vbox.Add (expander);
				}
			}
			
			sw.ShowAll ();
			return sw;
 		}
 public void AddRange(CustomAttributeCollection value)
 {
     foreach (CustomAttribute attr in value)
     {
         Add(attr);
     }
 }
		static void AddAttributes(IProjectContent pc, IList<IAttribute> list, CustomAttributeCollection attributes)
		{
			foreach (CustomAttribute att in attributes) {
				DefaultAttribute a = new DefaultAttribute(CreateType(pc, null, att.Constructor.DeclaringType));
				// Currently Cecil returns string instead of TypeReference for typeof() arguments to attributes
				var parameters = att.Constructor.Parameters;
				for (int i = 0; i < Math.Min(parameters.Count, att.ConstructorParameters.Count); i++) {
					object o = att.ConstructorParameters[i];
					if (parameters[i].ParameterType.FullName == "System.Type" && o is string) {
						try {
							a.PositionalArguments.Add(ReflectionReturnType.Parse(pc, (string)o));
						} catch (ReflectionTypeNameSyntaxError ex) {
							LoggingService.Warn("parsing '" + o + "'", ex);
							a.PositionalArguments.Add(o);
						}
					} else {
						a.PositionalArguments.Add(o);
					}
				}
				foreach (DictionaryEntry entry in att.Properties) {
					a.NamedArguments.Add(entry.Key.ToString(), entry.Value);
				}
				list.Add(a);
			}
		}
Beispiel #4
0
		static void AddAttributes(IProjectContent pc, IList<IAttribute> list, CustomAttributeCollection attributes)
		{
			foreach (CustomAttribute att in attributes) {
				DefaultAttribute a = new DefaultAttribute(att.Constructor.DeclaringType.FullName);
				// TODO: add only attributes marked "important", and include attribute arguments
				list.Add(a);
			}
		}
		static void AddAttributes(IProjectContent pc, IList<IAttribute> list, CustomAttributeCollection attributes)
		{
			foreach (CustomAttribute att in attributes) {
				DefaultAttribute a = new DefaultAttribute(CreateType(pc, null, att.Constructor.DeclaringType));
				foreach (object o in att.ConstructorParameters) {
					a.PositionalArguments.Add(o);
				}
				foreach (DictionaryEntry entry in att.Properties) {
					a.NamedArguments.Add(entry.Key.ToString(), entry.Value);
				}
				list.Add(a);
			}
		}
        public override void VisitCustomAttributeCollection(CustomAttributeCollection customAttrs)
        {
            if (customAttrs.Count == 0)
                return;

            CustomAttributeTable caTable = m_tableWriter.GetCustomAttributeTable ();
            foreach (CustomAttribute ca in customAttrs) {
                MetadataToken parent;
                if (customAttrs.Container is AssemblyDefinition)
                    parent = new MetadataToken (TokenType.Assembly, 1);
                else if (customAttrs.Container is ModuleDefinition)
                    parent = new MetadataToken (TokenType.Module, 1);
                else if (customAttrs.Container is IMetadataTokenProvider)
                    parent = (customAttrs.Container as IMetadataTokenProvider).MetadataToken;
                else
                    throw new ReflectionException ("Unknown Custom Attribute parent");

                uint value = ca.IsReadable ?
                    m_sigWriter.AddCustomAttribute (GetCustomAttributeSig (ca), ca.Constructor) :
                    m_mdWriter.AddBlob (m_mod.GetAsByteArray (ca));
                CustomAttributeRow caRow = m_rowWriter.CreateCustomAttributeRow (
                    parent,
                    ca.Constructor.MetadataToken,
                    value);

                caTable.Rows.Add (caRow);
            }
        }
 public void AddRange(CustomAttributeCollection value)
 {
     foreach (CustomAttribute attr in value)
         Add(attr);
 }
        public virtual void VisitCustomAttributeCollection(CustomAttributeCollection customAttrs)
        {

        }
 public virtual void VisitCustomAttributeCollection(CustomAttributeCollection customAttrs)
 {
     foreach (CustomAttribute ca in customAttrs)
     {
         VisitCustomAttribute(ca);
     }
 }
Beispiel #10
0
 private void Visit(CustomAttributeCollection attributes)
 {
   foreach (CustomAttribute attributeReference in attributes)
   {
     _modelCreator.HasAttribute(attributeReference.Constructor.DeclaringType.ToTypeKey());
   }
 }
Beispiel #11
0
		AttributeData (XmlDocument doc, XmlNode parent, CustomAttributeCollection attributes)
			: base (doc, parent)
		{
			atts = attributes;
		}
 private static string FindSecurityAttribute(CustomAttributeCollection attributes)
 {
     foreach (CustomAttribute attr in attributes)
     {
         var t = attr.Constructor.DeclaringType.ToString();
         if (t == "System.Security.SecurityCriticalAttribute")
             return "SecurityCritical";
         if (t == "System.Security.SecuritySafeCriticalAttribute")
             return "SecuritySafeCritical";
     }
     return null;
 }
		private static bool CheckForAttribute (string attrName, CustomAttributeCollection cac)
		{
			foreach (CustomAttribute ca in cac) {
				if (ca.Constructor.DeclaringType.FullName == attrName)
					return true;
			}
			return false;
		}
		public override void VisitCustomAttributeCollection (CustomAttributeCollection customAttrs)
		{
			foreach (CustomAttribute attr in customAttrs)
				VisitCustomAttribute (attr);
		}
		public static void AddAttributes (AbstractMember member, CustomAttributeCollection attributes)
		{
			foreach (CustomAttribute customAttribute in attributes) {
				member.Add (new DomCecilAttribute (customAttribute));
			}
		}
Beispiel #16
0
		private CustomAttribute DoFindObsolete(CustomAttributeCollection attrs)
		{
			foreach (CustomAttribute attr in attrs)
			{
				Log.DebugLine(this, "attr.Name: {0}", attr.Constructor.DeclaringType.Name);
				if (attr.Constructor.DeclaringType.Name ==  "ObsoleteAttribute")
					return attr;
			}
			
			return null;
		}
		public override void VisitCustomAttributeCollection (CustomAttributeCollection customAttrs)
		{
			VisitCollection (customAttrs);
		}
        private void InitializeCustomAttributes(SetCustomAttributeDelegate setCustomAttribute, CustomAttributeCollection attributes)
        {
            foreach (CustomAttribute attribute in attributes)
            {
                attribute.Resolve();

                ConstructorInfo constructor = ResolveConstructor(attribute.Constructor);
                object[] constructorArgs = CollectionUtils.ToArray<object>(attribute.ConstructorParameters);
                Type attributeType = constructor.ReflectedType;

                PropertyInfo[] namedProperties = new PropertyInfo[attribute.Properties.Count];
                object[] propertyValues = new object[attribute.Properties.Count];
                int i = 0;
                foreach (DictionaryEntry entry in attribute.Properties)
                {
                    namedProperties[i] = GetProperty(attributeType, (string)entry.Key);
                    propertyValues[i] = entry.Value;
                    i += 1;
                }

                FieldInfo[] namedFields = new FieldInfo[attribute.Fields.Count];
                object[] fieldValues = new object[attribute.Fields.Count];
                i = 0;
                foreach (DictionaryEntry entry in attribute.Fields)
                {
                    namedFields[i] = GetField(attributeType, (string)entry.Key);
                    fieldValues[i] = entry.Value;
                    i += 1;
                }

                WorkaroundCecilBug82814(ref constructorArgs, CollectionUtils.ConvertAllToArray<ParameterInfo, Type>(constructor.GetParameters(),
                    delegate(ParameterInfo parameter) { return parameter.ParameterType; }));
                WorkaroundCecilBug82814(ref propertyValues, CollectionUtils.ConvertAllToArray<PropertyInfo, Type>(namedProperties,
                    delegate(PropertyInfo property) { return property.PropertyType; }));
                WorkaroundCecilBug82814(ref fieldValues, CollectionUtils.ConvertAllToArray<FieldInfo, Type>(namedFields,
                    delegate(FieldInfo field) { return field.FieldType; }));

                CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(
                    constructor, constructorArgs,
                    namedProperties, propertyValues,
                    namedFields, fieldValues);
                setCustomAttribute(attributeBuilder);
            }
        }
Beispiel #19
0
		public static void OutputAttributes (XmlDocument doc, XmlNode parent, CustomAttributeCollection attributes)
		{
			AttributeData ad = new AttributeData (doc, parent, attributes);
			ad.DoOutput ();
		}
 private void AddUsedTypesFromAttributes(CustomAttributeCollection attrs, List<UsedClass> usedT)
 {
     foreach (CustomAttribute attr in attrs)
     {
         AddTypeToList(attr.Constructor.DeclaringType, ClassUse.Attribute, usedT);
     }
 }
Beispiel #21
0
 public virtual void VisitCustomAttributeCollection(CustomAttributeCollection customAttrs)
 {
 }
Beispiel #22
0
 private void DoWriteAttributes(CustomAttributeCollection attrs)
 {
     foreach (CustomAttribute attrs in type.CustomAttributes)
     {
         m_writer.Write("[{0}(]", attr.Constructor.Name);
         for (int i = 0; i < attr.ConstructorParameters.Count; ++i)
         {
             m_writer.WriteLine("{0}", attr.ConstructorParameters[0]);
             if (i + 1 < attr.ConstructorParameters.Count)
                 m_writer.WriteLine(", ");
         }
         m_writer.WriteLine(")]");
     }
 }