Exemplo n.º 1
0
        private void enumerateCustomAttributes()
        {
            // Handle of enumeration
            uint enumHandle = 0;

            uint tkType = 0;

            uint[] customAttributes = new uint[10];
            uint   attributeCount   = 0;

            _import.EnumCustomAttributes(ref enumHandle, _token, tkType, customAttributes, Convert.ToUInt32(customAttributes.Length), out attributeCount);

            _attributes = new List <MetadataCustomAttribute>();

            for (uint attributeIndex = 0; attributeIndex < attributeCount; ++attributeIndex)
            {
                _attributes.Add(new MetadataCustomAttribute(_import, customAttributes[attributeIndex], _token));
            }

            _import.CloseEnum(enumHandle);
        }
Exemplo n.º 2
0
		public unsafe static uint[] GetCustomAttributeTokens(IMetaDataImport mdi, uint token) {
			if (mdi == null)
				return new uint[0];
			IntPtr iter = IntPtr.Zero;
			try {
				uint cTokens;
				int hr = mdi.EnumCustomAttributes(ref iter, token, 0, IntPtr.Zero, 0, out cTokens);
				if (hr < 0)
					return new uint[0];

				uint ulCount = 0;
				hr = mdi.CountEnum(iter, ref ulCount);
				if (hr < 0 || ulCount == 0)
					return new uint[0];

				hr = mdi.ResetEnum(iter, 0);
				if (hr < 0)
					return new uint[0];

				uint[] tokens = new uint[ulCount];
				fixed (uint* p = &tokens[0])
					hr = mdi.EnumCustomAttributes(ref iter, token, 0, new IntPtr(p), (uint)tokens.Length, out cTokens);
				if (hr < 0)
					return new uint[0];
				return tokens;
			}
			finally {
				if (iter != IntPtr.Zero)
					mdi.CloseEnum(iter);
			}
		}