/// <summary>
        /// returns string name / string value pair of all attribs for the specified assembly
        /// </summary>
        /// <remarks>
        /// note that Assembly* values are pulled from AssemblyInfo file in project folder
        ///
        /// Trademark       = AssemblyTrademark string
        /// Debuggable      = True
        /// GUID            = 7FDF68D5-8C6F-44C9-B391-117B5AFB5467
        /// CLSCompliant    = True
        /// Product         = AssemblyProduct string
        /// Copyright       = AssemblyCopyright string
        /// Company         = AssemblyCompany string
        /// Description     = AssemblyDescription string
        /// Title           = AssemblyTitle string
        /// </remarks>
        private NameValueCollection AssemblyAttribs(Assembly a)
        {
            NameValueCollection nvc = new NameValueCollection();

            foreach (object attrib in a.GetCustomAttributes(false))
            {
                System.Diagnostics.DebuggableAttribute a1 = attrib as System.Diagnostics.DebuggableAttribute;
                if (a1 != null)
                {
                    if (string.IsNullOrEmpty(nvc["Debuggable"]))
                    {
                        nvc.Add("Debuggable", a1.IsJITTrackingEnabled.ToString());
                    }
                    continue;
                }
                System.CLSCompliantAttribute a2 = attrib as System.CLSCompliantAttribute;
                if (a2 != null)
                {
                    if (string.IsNullOrEmpty(nvc["CLSCompliant"]))
                    {
                        nvc.Add("CLSCompliant", a2.IsCompliant.ToString());
                    }
                    continue;
                }
                System.Runtime.InteropServices.GuidAttribute a3 = attrib as System.Runtime.InteropServices.GuidAttribute;
                if (a3 != null)
                {
                    if (string.IsNullOrEmpty(nvc["GUID"]))
                    {
                        nvc.Add("GUID", a3.Value.ToString());
                    }
                    continue;
                }
                AssemblyTrademarkAttribute a4 = attrib as AssemblyTrademarkAttribute;
                if (a4 != null)
                {
                    if (string.IsNullOrEmpty(nvc["Trademark"]))
                    {
                        nvc.Add("Trademark", a4.Trademark.ToString());
                    }
                    continue;
                }
                AssemblyProductAttribute a5 = attrib as AssemblyProductAttribute;
                if (a5 != null)
                {
                    if (string.IsNullOrEmpty(nvc["Product"]))
                    {
                        nvc.Add("Product", a5.Product.ToString());
                    }
                    continue;
                }
                AssemblyCopyrightAttribute a6 = attrib as AssemblyCopyrightAttribute;
                if (a6 != null)
                {
                    if (string.IsNullOrEmpty(nvc["Copyright"]))
                    {
                        nvc.Add("Copyright", a6.Copyright.ToString());
                    }
                    continue;
                }
                AssemblyCompanyAttribute a7 = attrib as AssemblyCompanyAttribute;
                if (a7 != null)
                {
                    if (string.IsNullOrEmpty(nvc["Company"]))
                    {
                        nvc.Add("Company", a7.Company.ToString());
                    }
                    continue;
                }
                AssemblyTitleAttribute a8 = attrib as AssemblyTitleAttribute;
                if (a8 != null)
                {
                    if (string.IsNullOrEmpty(nvc["Title"]))
                    {
                        nvc.Add("Title", a8.Title.ToString());
                    }
                    continue;
                }
                AssemblyDescriptionAttribute a9 = attrib as AssemblyDescriptionAttribute;
                if (a9 != null)
                {
                    if (string.IsNullOrEmpty(nvc["Description"]))
                    {
                        nvc.Add("Description", a9.Description.ToString());
                    }
                    continue;
                }
            }

            //-- add some extra values that are not in the AssemblyInfo, but nice to have
            nvc.Add("CodeBase", a.CodeBase.Replace("file:///", ""));
            nvc.Add("BuildDate", AssemblyBuildDate(a).ToString());
            nvc.Add("Version", a.GetName().Version.ToString());
            nvc.Add("FullName", a.FullName);

            return(nvc);
        }
Ejemplo n.º 2
0
 AttributeCollection ICustomTypeDescriptor.GetAttributes ()
 {
         object value = _staticAttributeCollection;
         if (value == null) {
                 CLSCompliantAttribute clsAttr = new CLSCompliantAttribute (true);
                 DefaultMemberAttribute defMemAttr = new DefaultMemberAttribute ("Item");
                 Attribute [] attrs = {clsAttr, defMemAttr};
                 value = new AttributeCollection (attrs);
         }
         System.Threading.Interlocked.CompareExchange (ref _staticAttributeCollection, value, null);
         return _staticAttributeCollection as AttributeCollection;
 }