示例#1
0
        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 override void VisitCustomAttributeCollection(CustomAttributeCollection customAttrs)
 {
     foreach (CustomAttribute attr in customAttrs)
     {
         VisitCustomAttribute(attr);
     }
 }
示例#3
0
        internal ParameterDefinition(MetadataImage image, MetadataRow <ParameterAttributes, ushort, uint> row)
            : base(row.MetadataToken)
        {
            _image     = image;
            Attributes = row.Column1;
            Sequence   = row.Column2;
            _name      = new LazyValue <string>(() => image.Header.GetStream <StringStream>().GetStringByOffset(row.Column3));

            _method = new LazyValue <MethodDefinition>(() =>
            {
                var table     = image.Header.GetStream <TableStream>().GetTable(MetadataTokenType.Method);
                var methodRow = table.GetRowClosestToKey(5, row.MetadataToken.Rid);
                return((MethodDefinition)table.GetMemberFromRow(image, methodRow));
            });

            _constant = new LazyValue <Constant>(() =>
            {
                var table       = (ConstantTable)image.Header.GetStream <TableStream>().GetTable(MetadataTokenType.Constant);
                var constantRow = table.FindConstantOfOwner(row.MetadataToken);
                return(constantRow != null ? (Constant)table.GetMemberFromRow(image, constantRow) : null);
            });

            _fieldMarshal = new LazyValue <FieldMarshal>(() =>
            {
                var table      = (FieldMarshalTable)image.Header.GetStream <TableStream>().GetTable(MetadataTokenType.FieldMarshal);
                var marshalRow = table.FindFieldMarshalOfOwner(row.MetadataToken);
                return(marshalRow != null ? (FieldMarshal)table.GetMemberFromRow(image, marshalRow) : null);
            });

            CustomAttributes = new CustomAttributeCollection(this);
        }
示例#4
0
 public virtual void VisitCustomAttributeCollection(CustomAttributeCollection customAttrs)
 {
     foreach (CustomAttribute ca in customAttrs)
     {
         VisitCustomAttribute(ca);
     }
 }
 public MethodSpecification(IMethodDefOrRef method, GenericInstanceMethodSignature signature)
     : base(new MetadataToken(MetadataTokenType.MethodSpec))
 {
     _method          = new LazyValue <IMethodDefOrRef>(method);
     _signature       = new LazyValue <GenericInstanceMethodSignature>(signature);
     CustomAttributes = new CustomAttributeCollection(this);
 }
示例#6
0
        public FieldDefinition(string name, FieldAttributes attributes, FieldSignature signature)
            : base(new MetadataToken(MetadataTokenType.Field))
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (signature == null)
            {
                throw new ArgumentNullException(nameof(signature));
            }

            _name      = new LazyValue <string>(name);
            Attributes = attributes;
            _signature = new LazyValue <FieldSignature>(signature);

            _constant      = new LazyValue <Constant>();
            _declaringType = new LazyValue <TypeDefinition>();
            _fieldRva      = new LazyValue <FieldRva>();
            _fieldMarshal  = new LazyValue <FieldMarshal>();
            _fieldLayout   = new LazyValue <FieldLayout>();
            _pinvokeMap    = new LazyValue <ImplementationMap>();

            CustomAttributes = new CustomAttributeCollection(this);
        }
 public StandAloneSignature(CallingConventionSignature signature, MetadataImage image)
     : base(new MetadataToken(MetadataTokenType.StandAloneSig))
 {
     Image            = image;
     _signature       = new LazyValue <CallingConventionSignature>(signature);
     CustomAttributes = new CustomAttributeCollection(this);
 }
示例#8
0
 internal ModuleReference(MetadataImage image, MetadataRow <uint> row)
     : base(row.MetadataToken)
 {
     Referrer         = image.Assembly;
     _name            = new LazyValue <string>(() => image.Header.GetStream <StringStream>().GetStringByOffset(row.Column1));
     CustomAttributes = new CustomAttributeCollection(this);
 }
示例#9
0
        public void InjectAttributeOn(ICustomAttributeProvider provider, string attributeType)
        {
            //Info("{1}: {0}", provider, attributeType);
            CustomAttributeCollection attributes = provider.CustomAttributes;

            attributes.Add(new CustomAttribute(DefaultConstructorReferenceFor(attributeType)));
        }
示例#10
0
        internal EventDefinition(MetadataImage image, MetadataRow <EventAttributes, uint, uint> row)
            : base(row.MetadataToken)
        {
            _image     = image;
            Attributes = row.Column1;
            _name      = new LazyValue <string>(() => image.Header.GetStream <StringStream>().GetStringByOffset(row.Column2));

            _eventType = new LazyValue <ITypeDefOrRef>(() =>
            {
                var enoder         = image.Header.GetStream <TableStream>().GetIndexEncoder(CodedIndex.TypeDefOrRef);
                var eventTypeToken = enoder.DecodeIndex(row.Column3);
                IMetadataMember member;
                return(image.TryResolveMember(eventTypeToken, out member) ? (ITypeDefOrRef)member : null);
            });

            _eventMap = new LazyValue <EventMap>(() =>
            {
                var table  = image.Header.GetStream <TableStream>().GetTable(MetadataTokenType.EventMap);
                var mapRow = table.GetRowClosestToKey(1, row.MetadataToken.Rid);
                return(mapRow != null ? (EventMap)table.GetMemberFromRow(image, mapRow) : null);
            });

            CustomAttributes = new CustomAttributeCollection(this);
            Semantics        = new MethodSemanticsCollection(this);
        }
 private void AddUsedTypesFromAttributes(CustomAttributeCollection attrs, List <UsedClass> usedT)
 {
     foreach (CustomAttribute attr in attrs)
     {
         AddTypeToList(attr.Constructor.DeclaringType, ClassUse.Attribute, usedT);
     }
 }
示例#12
0
        private void RemapCustomAttributes(CustomAttributeCollection customAttributes)
        {
            foreach (var customAttribute in customAttributes)
            {
                var ctor = customAttribute.Constructor;

                if (ctor.IsMemberRef)
                {
                    RemapMemberRef((MemberRef)ctor);
                }
                else
                {
                    throw new NotImplementedException();
                }

                for (var i = customAttribute.ConstructorArguments.Count - 1; i >= 0; i--)
                {
                    var caArgument = customAttribute.ConstructorArguments[i];

                    var modifiedCAArgument = new CAArgument(RemapReference(caArgument.Type), caArgument.Value);

                    customAttribute.ConstructorArguments.RemoveAt(i);
                    customAttribute.ConstructorArguments.Insert(i, modifiedCAArgument);
                }
            }
        }
示例#13
0
        public TypeReference(MetadataImage image, MetadataRow <uint, uint, uint> row)
            : base(row.MetadataToken)
        {
            _image = image;
            var stringStream = image.Header.GetStream <StringStream>();
            var tableStream  = image.Header.GetStream <TableStream>();

            _resolutionScope = new LazyValue <IResolutionScope>(() =>
            {
                var resolutionScopeToken = tableStream.GetIndexEncoder(CodedIndex.ResolutionScope).DecodeIndex(row.Column1);
                IMetadataMember resolutionScope;
                return(image.TryResolveMember(resolutionScopeToken, out resolutionScope)
                    ? resolutionScope as IResolutionScope
                    : null);
            });

            _name = new LazyValue <string>(() =>
            {
                return(stringStream.GetStringByOffset(row.Column2));
            });
            _namespace = new LazyValue <string>(() =>
            {
                return(stringStream.GetStringByOffset(row.Column3));
            });

            CustomAttributes = new CustomAttributeCollection(this);
        }
示例#14
0
 public static void AddAttributes(AbstractMember member, CustomAttributeCollection attributes)
 {
     foreach (CustomAttribute customAttribute in attributes)
     {
         member.Add(new DomCecilAttribute(customAttribute));
     }
 }
 private static void ClearCustomAttributes(CustomAttributeCollection collection)
 {
     foreach (var type in s_RemovedTypes)
     {
         collection.RemoveAll(type.FullName);
     }
 }
示例#16
0
        internal ManifestResource(MetadataImage image, MetadataRow <uint, ManifestResourceAttributes, uint, uint> row)
            : base(row.MetadataToken)
        {
            Owner      = image.Assembly;
            Offset     = row.Column1;
            Attributes = row.Column2;

            _name = new LazyValue <string>(() =>
                                           image.Header.GetStream <StringStream>().GetStringByOffset(row.Column3));

            _implementation = new LazyValue <IImplementation>(() =>
            {
                var encoder             = image.Header.GetStream <TableStream>().GetIndexEncoder(CodedIndex.Implementation);
                var implementationToken = encoder.DecodeIndex(row.Column4);
                IMetadataMember member;
                return(image.TryResolveMember(implementationToken, out member)
                    ? (IImplementation)member
                    : null);
            });

            _data = new LazyValue <byte[]>(() =>
                                           IsEmbedded && Image != null
                ? Image.Header.NetDirectory.ResourcesManifest.GetResourceData(Offset)
                : null);

            CustomAttributes = new CustomAttributeCollection(this);
        }
示例#17
0
 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);
     }
 }
        public void Ctor_4_0()
        {
            CustomAttributeCollection attr_coll = new CustomAttributeCollection();

            Attribute [] attributes = attr_coll.GetAttributes();
            Assert.AreEqual(true, attributes == null, "#A0");
        }
示例#19
0
        /// <summary>
        /// Determines whether the custom attribute collection has an enabled process properties attribute.
        /// </summary>
        /// <param name="attributes">The attributes.</param>
        /// <returns>
        ///     <c>true</c> if the custom attribute collection has an enabled process properties attribute; otherwise, <c>false</c>.
        /// </returns>
        private bool HasEnabledProcessPropertiesAttribute(CustomAttributeCollection attributes)
        {
            if (attributes == null || attributes.Count == 0)
            {
                return(false);
            }

            foreach (CustomAttribute attribute in attributes)
            {
                if (attribute.Constructor.DeclaringType.FullName.Equals(_processPropertiesAttribute))
                {
                    if (attribute.ConstructorParameters.Count == 1 && attribute.ConstructorParameters[0] != null)
                    {
                        return(Convert.ToBoolean(attribute.ConstructorParameters[0], CultureInfo.InvariantCulture));
                    }

                    if (attribute.Properties["Enabled"] != null)
                    {
                        return(Convert.ToBoolean(attribute.Properties["Enabled"], CultureInfo.InvariantCulture));
                    }

                    return(true);
                }
            }

            return(false);
        }
示例#20
0
        internal PropertyDefinition(MetadataImage image, MetadataRow <PropertyAttributes, uint, uint> row)
            : base(row.MetadataToken)
        {
            _image     = image;
            Attributes = row.Column1;

            _name = new LazyValue <string>(() =>
                                           image.Header.GetStream <StringStream>().GetStringByOffset(row.Column2));

            _signature = new LazyValue <PropertySignature>(()
                                                           => PropertySignature.FromReader(image, image.Header.GetStream <BlobStream>().CreateBlobReader(row.Column3)));

            _propertyMap = new LazyValue <PropertyMap>(() =>
            {
                var table  = image.Header.GetStream <TableStream>().GetTable(MetadataTokenType.PropertyMap);
                var mapRow = table.GetRowClosestToKey(1, row.MetadataToken.Rid);
                return(mapRow != null ? (PropertyMap)table.GetMemberFromRow(image, mapRow) : null);
            });

            _constant = new LazyValue <Constant>(() =>
            {
                var table       = (ConstantTable)image.Header.GetStream <TableStream>().GetTable(MetadataTokenType.Constant);
                var constantRow = table.FindConstantOfOwner(row.MetadataToken);
                return(constantRow != null ? (Constant)table.GetMemberFromRow(image, constantRow) : null);
            });

            CustomAttributes = new CustomAttributeCollection(this);
            Semantics        = new MethodSemanticsCollection(this);
        }
示例#21
0
 public TypeSpecification(MetadataImage image, MetadataRow <uint> row)
     : base(row.MetadataToken)
 {
     _signature = new LazyValue <TypeSignature>(() =>
                                                TypeSignature.FromReader(image, image.Header.GetStream <BlobStream>().CreateBlobReader(row.Column1)));
     CustomAttributes = new CustomAttributeCollection(this);
 }
示例#22
0
        public MethodDefinition(string name, MethodAttributes attributes, MethodSignature signature)
            : base(new MetadataToken(MetadataTokenType.Method))
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (signature == null)
            {
                throw new ArgumentNullException("signature");
            }

            _name          = new LazyValue <string>(name);
            Attributes     = attributes;
            ImplAttributes = MethodImplAttributes.IL | MethodImplAttributes.Managed;
            _signature     = new LazyValue <MethodSignature>(signature);
            Parameters     = new DelegatedMemberCollection <MethodDefinition, ParameterDefinition>(this, GetParamOwner, SetParamOwner);
            _methodBody    = new LazyValue <MethodBody>();
            _pinvokeMap    = new LazyValue <ImplementationMap>();

            _declaringType       = new LazyValue <TypeDefinition>();
            CustomAttributes     = new CustomAttributeCollection(this);
            SecurityDeclarations = new SecurityDeclarationCollection(this);
            GenericParameters    = new GenericParameterCollection(this);
        }
 public static void AddIfNotExists(CustomAttributeCollection customAttributes)
 {
     if (!IsDefined(customAttributes))
     {
         Build(customAttributes.Add());
     }
 }
示例#24
0
 public MemberReference(IMemberRefParent parent, string name, MemberSignature signature)
     : base(new MetadataToken(MetadataTokenType.MemberRef))
 {
     _parent          = new LazyValue <IMemberRefParent>(parent);
     _name            = new LazyValue <string>(name);
     _signature       = new LazyValue <MemberSignature>(signature);
     CustomAttributes = new CustomAttributeCollection(this);
 }
示例#25
0
 private static void SubstituteAttributeScopeReferences(Context context, CustomAttributeCollection customAttributes)
 {
     foreach (CustomAttribute attr in customAttributes)
     {
         SubstituteAttributeParameterScopeReferences(context, attr.ConstructorParameters);
         SubstituteAttributeParameterScopeReferences(context, attr.Properties);
     }
 }
示例#26
0
        public InterfaceImplementation(ITypeDefOrRef @interface)
            : base(new MetadataToken(MetadataTokenType.InterfaceImpl))
        {
            _class     = new LazyValue <TypeDefinition>();
            _interface = new LazyValue <ITypeDefOrRef>(@interface);

            CustomAttributes = new CustomAttributeCollection(this);
        }
示例#27
0
        public TypeReference(IResolutionScope resolutionScope, string @namespace, string name)
            : base(new MetadataToken(MetadataTokenType.TypeRef))
        {
            _resolutionScope = new LazyValue <IResolutionScope>(resolutionScope);
            _namespace       = new LazyValue <string>(@namespace);
            _name            = new LazyValue <string>(name);

            CustomAttributes = new CustomAttributeCollection(this);
        }
示例#28
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);
     }
 }
示例#29
0
        public SecurityDeclaration(SecurityAction action, PermissionSetSignature permissionSet)
            : base(new MetadataToken(MetadataTokenType.DeclSecurity))
        {
            Action         = action;
            _parent        = new LazyValue <IHasSecurityAttribute>();
            _permissionSet = new LazyValue <PermissionSetSignature>(permissionSet);

            CustomAttributes = new CustomAttributeCollection(this);
        }
示例#30
0
        public FileReference(string name, FileAttributes attributes, DataBlobSignature hashValue)
            : base(new MetadataToken(MetadataTokenType.File))
        {
            _name      = new LazyValue <string>(name);
            _hashValue = new LazyValue <DataBlobSignature>(hashValue);
            Attributes = attributes;

            CustomAttributes = new CustomAttributeCollection(this);
        }
示例#31
0
		public void AttributesTest ()
		{
			SerializableAttribute serializable_attr = new SerializableAttribute ();
			FlagsAttribute flags_attr = new FlagsAttribute ();

			CustomAttributeCollection attr_coll = new CustomAttributeCollection (serializable_attr, flags_attr);
			Attribute [] attributes = attr_coll.GetAttributes ();
			Assert.AreEqual (true, attributes != null, "#A0");
			Assert.AreEqual (2, attributes.Length, "#A1");

			// The property is supposed to be giving us the same instance in all the invocations
			Assert.AreSame (attributes, attr_coll.GetAttributes (), "#A2");
		}
示例#32
0
 public static bool Compare(this CustomAttributeCollection source, CustomAttributeCollection n)
 {
     return Compare<CustomAttribute>(source,n);
 }
示例#33
0
 public static bool Compare(this CustomAttributeCollection source, CustomAttributeCollection n, Func<CustomAttribute, CustomAttribute, bool> checkitem)
 {
     return Compare<CustomAttribute>(source,n,checkitem);
 }
示例#34
0
 public static bool Compare(this CustomAttributeCollection source, CustomAttributeCollection n, Func<CustomAttribute, CustomAttribute, Action<string, string>, bool> checkitem, Action<string, string> errAct)
 {
     return Compare<CustomAttribute>(source,n,checkitem,errAct);
 }
示例#35
0
		public void Ctor_4_0 ()
		{
			CustomAttributeCollection attr_coll = new CustomAttributeCollection ();
			Attribute [] attributes = attr_coll.GetAttributes ();
			Assert.AreEqual (true, attributes == null, "#A0");
		}
示例#36
0
		/// <inheritdoc/>
		protected override void InitializeCustomAttributes() {
			var list = readerModule.MetaData.GetCustomAttributeRidList(Table.Field, origRid);
			var tmp = new CustomAttributeCollection((int)list.Length, list, (list2, index) => readerModule.ReadCustomAttribute(((RidList)list2)[index]));
			Interlocked.CompareExchange(ref customAttributes, tmp, null);
		}
        public virtual ICustomAttributeCollection TransformCustomAttributeCollection(ICustomAttributeCollection attributes)
        {
            ICustomAttribute[] array = new ICustomAttribute[attributes.Count];
            for (int i = 0; i < attributes.Count; i++)
            {
                array[i] = this.TransformCustomAttribute(attributes[i]);
            }

            ICustomAttributeCollection target = new CustomAttributeCollection();
            target.AddRange(array);
            return target;
        }