Inheritance: System.Attribute
Esempio n. 1
0
        // Assembler
        static void Ilasm(string il, string res, string assembly, DebuggableAttribute debug)
        {
            var ilasm = ToolLocationHelper.GetPathToDotNetFrameworkFile("ilasm.exe", TargetDotNetFrameworkVersion.Version20);

            // DLL or EXE
            var args = Path.GetExtension(assembly).Replace('.', '/');

            // Debugging
            if (File.Exists(Path.ChangeExtension(assembly, "pdb")))
            {
                if (debug.IsJITOptimizerDisabled)
                {
                    if (debug.DebuggingFlags.HasFlag(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints))
                    {
                        args += " /debug=impl";
                    }
                    else
                    {
                        args += " /debug";
                    }
                }
                else
                {
                    if (debug.DebuggingFlags.HasFlag(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints))
                    {
                        args += " /debug=opt";
                    }
                    else
                    {
                        args += " /pdb";
                    }
                }
            }

            // Optimization
            if (!debug.DebuggingFlags.HasFlag(DebuggableAttribute.DebuggingModes.DisableOptimizations))
            {
                args += " /optimize /fold";
            }

            Run(ilasm, "\"{0}\" /noautoinherit /resource=\"{1}\" /out=\"{2}\" {3}", il, res, assembly, args);
        }
        // NYI: /addmodule support
        // TODO: Add tests for assembly attributes emitted into netmodules which suppress synthesized CompilationRelaxationsAttribute/RuntimeCompatibilityAttribute

        #endregion

        #region DebuggableAttribute

        private void VerifyDebuggableAttribute(CSharpAttributeData attribute, SourceAssemblySymbol sourceAssembly, DebuggableAttribute.DebuggingModes expectedDebuggingMode)
        {
            ModuleSymbol module = sourceAssembly.Modules[0];
            NamespaceSymbol diagnosticsNS = Get_System_Diagnostics_NamespaceSymbol(module);

            NamedTypeSymbol debuggableAttributeType = diagnosticsNS.GetTypeMember("DebuggableAttribute");
            var debuggableAttributeCtor = (MethodSymbol)sourceAssembly.DeclaringCompilation.GetWellKnownTypeMember(WellKnownMember.System_Diagnostics_DebuggableAttribute__ctorDebuggingModes);

            Assert.Equal(debuggableAttributeType, attribute.AttributeClass);
            Assert.Equal(debuggableAttributeCtor, attribute.AttributeConstructor);

            Assert.Equal(1, attribute.CommonConstructorArguments.Length);
            attribute.VerifyValue(0, TypedConstantKind.Enum, (int)expectedDebuggingMode);

            Assert.Equal(0, attribute.CommonNamedArguments.Length);
        }
        /// <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);
        }
 public CodeAttributeDeclaration Convert(DebuggableAttribute attribute)
 {
     return new CodeAttributeDeclaration(new CodeTypeReference(attribute.GetType()), new CodeAttributeArgument(new CodePrimitiveExpression(attribute.DebuggingFlags)));
 }