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


C# MemberInfo.HasAttribute方法代码示例

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


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

示例1: ShouldInject

        /// <summary>
        /// Returns a value indicating whether the specified member should be injected.
        /// </summary>
        /// <param name="member">The member in question.</param>
        /// <returns><c>True</c> if the member should be injected; otherwise <c>false</c>.</returns>
        public virtual bool ShouldInject(MemberInfo member)
        {
            Ensure.ArgumentNotNull(member, "member");

            var propertyInfo = member as PropertyInfo;

            if (propertyInfo != null)
            {
            #if !SILVERLIGHT
                bool injectNonPublic = Settings.InjectNonPublic;
            #else
                const bool injectNonPublic = false;
            #endif // !SILVERLIGHT

            #if !WINRT
                var setMethod = propertyInfo.GetSetMethod(injectNonPublic);
            #else
                var setMethod = propertyInfo.SetMethod;
                if (setMethod != null && !injectNonPublic)
                {
                    if (!setMethod.IsPublic)
                        setMethod = null;
                }
            #endif

                return member.HasAttribute(Settings.InjectAttribute) && setMethod != null;
            }

            return member.HasAttribute(Settings.InjectAttribute);
        }
开发者ID:remogloor,项目名称:ninject,代码行数:35,代码来源:StandardInjectionHeuristic.cs

示例2: CreateForMember

        static InjectableInfo CreateForMember(MemberInfo memInfo, Type parentType)
        {
            var identifier = memInfo.AllAttributes<InjectAttribute>().Select(x => x.Identifier)
                .Concat(memInfo.AllAttributes<InjectOptionalAttribute>().Select(x => x.Identifier)).FirstOrDefault();

            Type memberType;
            Action<object, object> setter;

            if (memInfo is FieldInfo)
            {
                var fieldInfo = (FieldInfo)memInfo;
                setter = ((object injectable, object value) => fieldInfo.SetValue(injectable, value));
                memberType = fieldInfo.FieldType;
            }
            else
            {
                Assert.That(memInfo is PropertyInfo);
                var propInfo = (PropertyInfo)memInfo;
                setter = ((object injectable, object value) => propInfo.SetValue(injectable, value, null));
                memberType = propInfo.PropertyType;
            }

            return new InjectableInfo(
                memInfo.HasAttribute(typeof(InjectOptionalAttribute)),
                identifier,
                memInfo.Name,
                memberType,
                parentType,
                setter);
        }
开发者ID:IllusiveS,项目名称:Asteroids,代码行数:30,代码来源:TypeAnalyzer.cs

示例3: CreateForMember

        static InjectableInfo CreateForMember(MemberInfo memInfo, Type enclosingType)
        {
            var injectAttr = memInfo.Attribute<InjectAttribute>();

            var info = new InjectableInfo()
            {
                Optional = memInfo.HasAttribute(typeof(InjectOptionalAttribute)),
                Identifier = (injectAttr == null ? null : injectAttr.Identifier),
                SourceName = memInfo.Name,
                EnclosingType = enclosingType,
            };

            if (memInfo is FieldInfo)
            {
                var fieldInfo = (FieldInfo)memInfo;
                info.Setter = ((object injectable, object value) => fieldInfo.SetValue(injectable, value));
                info.ContractType = fieldInfo.FieldType;
            }
            else
            {
                Assert.That(memInfo is PropertyInfo);
                var propInfo = (PropertyInfo)memInfo;
                info.Setter = ((object injectable, object value) => propInfo.SetValue(injectable, value, null));
                info.ContractType = propInfo.PropertyType;
            }

            return info;
        }
开发者ID:nintorii,项目名称:Zenject,代码行数:28,代码来源:TypeAnalyzer.cs

示例4: ShouldInject

        /// <summary>
        /// Returns a value indicating whether the specified member should be injected.
        /// </summary>
        /// <param name="member">The member in question.</param>
        /// <returns><c>True</c> if the member should be injected; otherwise <c>false</c>.</returns>
        public virtual bool ShouldInject(MemberInfo member)
        {
            var propertyInfo = member as PropertyInfo;

            if (propertyInfo != null)
            {
                bool injectNonPublic = Settings.InjectNonPublic;

                var setMethod = propertyInfo.SetMethod;
                if (setMethod != null && !injectNonPublic)
                {
                    if (!setMethod.IsPublic)
                        setMethod = null;
                }

                return member.HasAttribute(Settings.InjectAttribute) && setMethod != null;
            }

            return member.HasAttribute(Settings.InjectAttribute);
        }
开发者ID:LuckyStarry,项目名称:Ninject,代码行数:25,代码来源:StandardInjectionHeuristic.cs

示例5: ShouldInject

 /// <summary>
 /// Returns a value indicating whether the specified member should be injected.
 /// </summary>
 /// <param name="member">The member in question.</param>
 /// <returns><c>True</c> if the member should be injected; otherwise <c>false</c>.</returns>
 public bool ShouldInject(MemberInfo member)
 {
     Ensure.ArgumentNotNull(member, "member");
     return member.HasAttribute(Settings.InjectAttribute);
 }
开发者ID:shijucv,项目名称:ninject,代码行数:10,代码来源:StandardInjectionHeuristic.cs

示例6: IsInterceptable

        private bool IsInterceptable(MembersCollector collector, MemberInfo member)
        {
            if (collector.Type.IsInterface)
				return true;
			if (member.HasAttribute(typeof(NonInterceptableAttribute)))
				return false;
			if (member is MethodInfo && (member as MethodInfo).ContainsGenericParameters)
				return false;
			return true;
        }
开发者ID:grbbod,项目名称:drconnect-jungo,代码行数:10,代码来源:CompositeTypeContributor.cs

示例7: HasExpansions

 public static bool HasExpansions(Type type, MemberInfo mi)
 {
     return GetFieldExpansion(type, mi) != null || mi is MethodInfo && mi.HasAttribute<MethodExpanderAttribute>();
 }
开发者ID:signumsoftware,项目名称:framework,代码行数:4,代码来源:ExpressionCleaner.cs

示例8: IsInterceptable

 private bool IsInterceptable(MembersCollector collector, MemberInfo member)
 {
     return collector.Type.IsInterface || member.HasAttribute(typeof(IInterceptable));
 }
开发者ID:rohancragg,项目名称:n2cms,代码行数:4,代码来源:CompositeTypeContributor.cs


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