当前位置: 首页>>代码示例>>C#>>正文


C# ITypeInfo.HasMethodWithAttribute方法代码示例

本文整理汇总了C#中ITypeInfo.HasMethodWithAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeInfo.HasMethodWithAttribute方法的具体用法?C# ITypeInfo.HasMethodWithAttribute怎么用?C# ITypeInfo.HasMethodWithAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITypeInfo的用法示例。


在下文中一共展示了ITypeInfo.HasMethodWithAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanBuildFrom

        /// <summary>
        /// Checks to see if the provided Type is a fixture.
        /// To be considered a fixture, it must be a non-abstract
        /// class with one or more attributes implementing the
        /// IFixtureBuilder interface or one or more methods
        /// marked as tests.
        /// </summary>
        /// <param name="typeInfo">The fixture type to check</param>
        /// <returns>True if the fixture can be built, false if not</returns>
        public bool CanBuildFrom(ITypeInfo typeInfo)
        {
            if (typeInfo.IsAbstract && !typeInfo.IsSealed)
                return false;

            if (typeInfo.IsDefined<IFixtureBuilder>(true))
                return true;

            // Generics must have an attribute in order to provide
            // them with arguments to determine the specific type.
            // TODO: What about automatic fixtures? Should there
            // be some kind of error shown?
            if (typeInfo.IsGenericTypeDefinition)
                return false;

            return typeInfo.HasMethodWithAttribute(typeof(IImplyFixture));
        }
开发者ID:textmetal,项目名称:main,代码行数:26,代码来源:DefaultSuiteBuilder.cs

示例2: IsValidFixtureType

        private bool IsValidFixtureType(ITypeInfo typeInfo, ref string reason)
        {
            if (typeInfo.IsAbstract)
            {
                reason = string.Format("{0} is an abstract class", typeInfo.FullName);
                return false;
            }

            if (!typeInfo.HasConstructor(new Type[0]))
            {
                reason = string.Format("{0} does not have a default constructor", typeInfo.FullName);
                return false;
            }

            var invalidAttributes = new Type[] { 
                typeof(SetUpAttribute), 
                typeof(TearDownAttribute),
#pragma warning disable 618 // Obsolete Attributes
                typeof(TestFixtureSetUpAttribute), 
                typeof(TestFixtureTearDownAttribute) };
#pragma warning restore

            foreach (Type invalidType in invalidAttributes)
                if (typeInfo.HasMethodWithAttribute(invalidType))
                {
                    reason = invalidType.Name + " attribute not allowed in a SetUpFixture";
                    return false;
                }

            return true;
        }
开发者ID:alfeg,项目名称:nunit,代码行数:31,代码来源:SetUpFixtureAttribute.cs


注:本文中的ITypeInfo.HasMethodWithAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。