__GetCustomAttributes() public method

public __GetCustomAttributes ( Type attributeType, bool inherit ) : IList
attributeType Type
inherit bool
return IList
コード例 #1
0
ファイル: AttributeMap.cs プロジェクト: GeorchW/protobuf-net
        public static AttributeMap[] Create(TypeModel model, Assembly assembly)
        {

#if FEAT_IKVM
            const bool inherit = false;
            System.Collections.Generic.IList<CustomAttributeData> all = assembly.__GetCustomAttributes(model.MapType(typeof(Attribute)), inherit);
            AttributeMap[] result = new AttributeMap[all.Count];
            int index = 0;
            foreach (CustomAttributeData attrib in all)
            {
                result[index++] = new AttributeDataMap(attrib);
            }
            return result;
#else
#if WINRT || COREFX
            Attribute[] all = System.Linq.Enumerable.ToArray(assembly.GetCustomAttributes());
#else
            const bool inherit = false;
            object[] all = assembly.GetCustomAttributes(inherit);
#endif
            AttributeMap[] result = new AttributeMap[all.Length];
            for(int i = 0 ; i < all.Length ; i++)
            {
                result[i] = new ReflectionAttributeMap((Attribute)all[i]);
            }
            return result;
#endif
        }
コード例 #2
0
 bool InternalsVisible(Assembly assembly)
 {
     #if PHONE8 || SILVERLIGHT || FX11
     return false;
     #else
     if (Helpers.IsNullOrEmpty(assemblyName)) return false;
     if (knownTrustedAssemblies != null)
     {
         if (knownTrustedAssemblies.IndexOfReference(assembly) >= 0)
         {
             return true;
         }
     }
     if (knownUntrustedAssemblies != null)
     {
         if (knownUntrustedAssemblies.IndexOfReference(assembly) >= 0)
         {
             return false;
         }
     }
     bool isTrusted = false;
     Type attributeType = MapType(typeof(System.Runtime.CompilerServices.InternalsVisibleToAttribute));
     if(attributeType == null) return false;
     #if FEAT_IKVM
     foreach (CustomAttributeData attrib in assembly.__GetCustomAttributes(attributeType, false))
     {
         if (attrib.ConstructorArguments.Count == 1)
         {
             string privelegedAssembly = attrib.ConstructorArguments[0].Value as string;
             if (privelegedAssembly == assemblyName)
             {
                 isTrusted = true;
                 break;
             }
         }
     }
     #else
     foreach(System.Runtime.CompilerServices.InternalsVisibleToAttribute attrib in assembly.GetCustomAttributes(attributeType, false))
     {
         if (attrib.AssemblyName == assemblyName)
         {
             isTrusted = true;
             break;
         }
     }
     #endif
     if (isTrusted)
     {
         if (knownTrustedAssemblies == null) knownTrustedAssemblies = new BasicList();
         knownTrustedAssemblies.Add(assembly);
     }
     else
     {
         if (knownUntrustedAssemblies == null) knownUntrustedAssemblies = new BasicList();
         knownUntrustedAssemblies.Add(assembly);
     }
     return isTrusted;
     #endif
 }