Пример #1
0
        public void Exists()
        {
            Type type = typeof(ComVisibleAttributeTests);
            ComVisibleAttribute attribute = Assert.IsType <ComVisibleAttribute>(Assert.Single(type.GetCustomAttributes(typeof(ComVisibleAttribute), inherit: false)));

            Assert.True(attribute.Value);
        }
Пример #2
0
        private void WriteMethods(StreamWriter writer)
        {
            writer.WriteLine();
            writer.WriteLine("//<editor-fold defaultstate=\"collapsed\" desc=\"Interop Methods\">");

            foreach (var method in ComponentType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
            {
                ///Construtores, acessores de propriedades e de eventos são ignorados
                if (method.IsConstructor || method.Name.StartsWith("get_") || method.Name.StartsWith("set_") || method.Name.StartsWith("add_") || method.Name.StartsWith("remove_"))
                {
                    continue;
                }

                ///Métodos com ComVisible=False são overloads e devem ser implementados diretamente em Java, não devem ser exportados.
                ComVisibleAttribute comVisibleAttribute = (ComVisibleAttribute)Attribute.GetCustomAttribute(method, typeof(ComVisibleAttribute));
                if (comVisibleAttribute != null && comVisibleAttribute.Value == false)
                {
                    continue;
                }

                WriteMethod(writer, method);
            }

            writer.WriteLine();
            writer.WriteLine();
            writer.WriteLine("//</editor-fold>");
        }
Пример #3
0
        private void AnalyzeAssembly()
        {
            bool comVisible = false;
            bool hasGuid    = false;
            bool isSigned   = false;

            foreach (object item in Attributes)
            {
                ComVisibleAttribute comAttribute = item as ComVisibleAttribute;
                if (null != comAttribute && comAttribute.Value)
                {
                    comVisible = true;
                }

                GuidAttribute guidAttribute = item as GuidAttribute;
                if (null != guidAttribute)
                {
                    hasGuid = true;
                }
            }

            isSigned = (Name.GetPublicKeyToken().Length != 0);

            Result.Add("Assembly-ComVisible", comVisible);
            Result.Add("Assembly-HasGuid", hasGuid);
            Result.Add("Assembly-IsSigned", isSigned);
        }
Пример #4
0
 internal static bool ComVisibleAttributeExists(IEnumerable <object> customAttributes)
 {
     foreach (object item in customAttributes)
     {
         ComVisibleAttribute attribute = item as ComVisibleAttribute;
         if (null != attribute && attribute.Value)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #5
0
        public void Explicitly_AssertThat_SingleCustomAttributeOfSpecifiedTypeIsAppliedToTheInspectedAssembly()
        {
            // Arrange
            AssemblyService service = new();

            // Act
            Assembly assembly = service.GetAssembly();

            // Assert
            ComVisibleAttribute attribute = Test.That(assembly).HasAttribute <ComVisibleAttribute>();

            Assert.IsFalse(attribute.Value);
        }
Пример #6
0
        internal static bool AssemblyIsComVisible(Assembly assembly, IEnumerable <object> attributes)
        {
            if (null == attributes)
            {
                attributes = assembly.GetCustomAttributes(true);
            }

            foreach (object item in attributes)
            {
                ComVisibleAttribute comVisible = item as ComVisibleAttribute;
                if (null != comVisible && comVisible.Value == true)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #7
0
        public AssemblyInformation(Assembly assembly)
        {
            // Get values from the assembly.
            AssemblyTitleAttribute titleAttr =
                GetAssemblyAttribute <AssemblyTitleAttribute>(assembly);

            if (titleAttr != null)
            {
                Title = titleAttr.Title;
            }

            AssemblyDescriptionAttribute assemblyAttr =
                GetAssemblyAttribute <AssemblyDescriptionAttribute>(assembly);

            if (assemblyAttr != null)
            {
                Description =
                    assemblyAttr.Description;
            }

            AssemblyCompanyAttribute companyAttr =
                GetAssemblyAttribute <AssemblyCompanyAttribute>(assembly);

            if (companyAttr != null)
            {
                Company = companyAttr.Company;
            }

            AssemblyProductAttribute productAttr =
                GetAssemblyAttribute <AssemblyProductAttribute>(assembly);

            if (productAttr != null)
            {
                Product = productAttr.Product;
            }

            AssemblyCopyrightAttribute copyrightAttr =
                GetAssemblyAttribute <AssemblyCopyrightAttribute>(assembly);

            if (copyrightAttr != null)
            {
                Copyright = copyrightAttr.Copyright;
            }

            AssemblyTrademarkAttribute trademarkAttr =
                GetAssemblyAttribute <AssemblyTrademarkAttribute>(assembly);

            if (trademarkAttr != null)
            {
                Trademark = trademarkAttr.Trademark;
            }

            AssemblyVersion = assembly.GetName().Version.ToString();

            AssemblyFileVersionAttribute fileVersionAttr =
                GetAssemblyAttribute <AssemblyFileVersionAttribute>(assembly);

            if (fileVersionAttr != null)
            {
                FileVersion =
                    fileVersionAttr.Version;
            }

            GuidAttribute guidAttr = GetAssemblyAttribute <GuidAttribute>(assembly);

            if (guidAttr != null)
            {
                Guid = guidAttr.Value;
            }

            NeutralResourcesLanguageAttribute languageAttr =
                GetAssemblyAttribute <NeutralResourcesLanguageAttribute>(assembly);

            if (languageAttr != null)
            {
                NeutralLanguage =
                    languageAttr.CultureName;
            }

            ComVisibleAttribute comAttr =
                GetAssemblyAttribute <ComVisibleAttribute>(assembly);

            if (comAttr != null)
            {
                IsComVisible = comAttr.Value;
            }
        }
Пример #8
0
 public CodeAttributeDeclaration Convert(ComVisibleAttribute attribute)
 {
     return(new CodeAttributeDeclaration(new CodeTypeReference(attribute.GetType()), new CodeAttributeArgument(new CodePrimitiveExpression(attribute.Value))));
 }
Пример #9
0
        public void Ctor_Visible(bool visibility)
        {
            var attribute = new ComVisibleAttribute(visibility);

            Assert.Equal(visibility, attribute.Value);
        }