Пример #1
0
 public void CopyTo(DmdCustomAttributeData[] destination, ref int index)
 {
     if (Count == 0)
     {
         return;
     }
     destination[index++] = new DmdCustomAttributeData(ctor, null, null, isPseudoCustomAttribute: true);
 }
Пример #2
0
        // Reads the new (.NET 2.0+) DeclSecurity blob format
        DmdCustomAttributeData[] ReadBinaryFormat(SecurityAction action)
        {
            int numAttrs = (int)reader.ReadCompressedUInt32();

            DmdCustomAttributeData[]? res = new DmdCustomAttributeData[numAttrs];

            IList <DmdType>?genericTypeArguments = null;
            int             w = 0;

            for (int i = 0; i < numAttrs; i++)
            {
                var name = ReadUTF8String();
                var type = DmdTypeNameParser.ParseThrow(module, name ?? string.Empty, genericTypeArguments);
                reader.ReadCompressedUInt32();                // int blobLength
                int numNamedArgs = (int)reader.ReadCompressedUInt32();
                var namedArgs    = DmdCustomAttributeReader.ReadNamedArguments(module, reader, type, numNamedArgs, genericTypeArguments);
                if (namedArgs is null)
                {
                    throw new IOException();
                }
                var(ctor, ctorArguments) = GetConstructor(type, action);
                Debug.Assert(!(ctor is null));
                if (ctor is null)
                {
                    continue;
                }
                res[w++] = new DmdCustomAttributeData(ctor, ctorArguments, namedArgs, isPseudoCustomAttribute: false);
            }
            if (res.Length != w)
            {
                if (w == 0)
                {
                    return(Array.Empty <DmdCustomAttributeData>());
                }
                Array.Resize(ref res, w);
            }

            return(res !);
        }
 static string?GetString(DmdCustomAttributeData ca, string propertyName)
 {
     if (ca is null)
     {
         return(null);
     }
     foreach (var arg in ca.NamedArguments)
     {
         if (arg.IsField)
         {
             continue;
         }
         if (arg.MemberName != propertyName)
         {
             continue;
         }
         if (arg.TypedValue.ArgumentType != arg.TypedValue.ArgumentType.AppDomain.System_String)
         {
             continue;
         }
         return(arg.TypedValue.Value as string);
     }
     return(null);
 }