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


C# FieldInfo.HasAttribute方法代码示例

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


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

示例1: CreateBehaviorFrom

    public Behavior CreateBehaviorFrom(FieldInfo behaviorField, Context context)
    {
      Type behaviorType = behaviorField.FieldType.GetGenericArguments().First();

      if(!behaviorType.HasAttribute<BehaviorsAttribute>())
      {
        throw new SpecificationUsageException("Behaviors require the BehaviorsAttribute on the type containing the Specifications. Attribute is missing from " + behaviorType.FullName);
      }

      object behaviorInstance = Activator.CreateInstance(behaviorType);

      if (behaviorType.GetPrivateFieldsOfType<Establish>().Any())
      {
        throw new SpecificationUsageException("You cannot have Establishs on Behaviors. Establish found in " + behaviorType.FullName);
      }
      
      if (behaviorType.GetPrivateFieldsOfType<Because>().Any())
      {
        throw new SpecificationUsageException("You cannot have Becauses on Behaviors. Because found in " + behaviorType.FullName);
      }

      if (behaviorType.GetPrivateFieldsWith(typeof(Behaves_like<>)).Any())
      {
        throw new SpecificationUsageException("You cannot nest Behaviors. Nested Behaviors found in " + behaviorType.FullName);
      }

      var isIgnored = behaviorField.HasAttribute<IgnoreAttribute>() ||
                      behaviorInstance.GetType().HasAttribute<IgnoreAttribute>();
      var behavior = new Behavior(behaviorInstance, context, isIgnored);

      IEnumerable<FieldInfo> itFieldInfos = behaviorType.GetPrivateFieldsOfType<It>();
      CreateBehaviorSpecifications(itFieldInfos, behavior);

      return behavior;
    }
开发者ID:benlovell,项目名称:machine.specifications,代码行数:35,代码来源:BehaviorFactory.cs

示例2: CreateSpecificationFromBehavior

    public Specification CreateSpecificationFromBehavior(Behavior behavior, FieldInfo specificationField)
    {
      bool isIgnored = behavior.IsIgnored || specificationField.HasAttribute<IgnoreAttribute>();
      Then then = (Then) specificationField.GetValue(behavior.Instance);
      string name = specificationField.Name.ToFormat();

      return new BehaviorSpecification(name, then, isIgnored, specificationField, behavior.Context, behavior);
    }
开发者ID:jhollingworth,项目名称:machine.specifications,代码行数:8,代码来源:SpecificationFactory.cs

示例3: CreateSpecification

    public Specification CreateSpecification(Context context, FieldInfo specificationField)
    {
      bool isIgnored = context.IsIgnored || specificationField.HasAttribute<IgnoreAttribute>();
      Then then = (Then) specificationField.GetValue(context.Instance);
      string name = specificationField.Name.ToFormat();

      return new Specification(name, then, isIgnored, specificationField);
    }
开发者ID:jhollingworth,项目名称:machine.specifications,代码行数:8,代码来源:SpecificationFactory.cs

示例4: CreateSpecificationFromBehavior

    public Specification CreateSpecificationFromBehavior(Behavior behavior, FieldInfo specificationField)
    {
      bool isIgnored = behavior.IsIgnored || specificationField.HasAttribute(new IgnoreAttributeFullName());
      var it = (Delegate) specificationField.GetValue(behavior.Instance);
      string name = specificationField.Name.ToFormat();

      return new BehaviorSpecification(name, specificationField.FieldType, it, isIgnored, specificationField, behavior.Context, behavior);
    }
开发者ID:hennys,项目名称:machine.specifications,代码行数:8,代码来源:SpecificationFactory.cs

示例5: CreateSpecification

    public Specification CreateSpecification(Context context, FieldInfo specificationField)
    {
      bool isIgnored = context.IsIgnored || specificationField.HasAttribute(new IgnoreAttributeFullName());
      var it = (Delegate) specificationField.GetValue(context.Instance);
      string name = specificationField.Name.ToFormat();

      return new Specification(name, specificationField.FieldType, it, isIgnored, specificationField);
    }
开发者ID:hennys,项目名称:machine.specifications,代码行数:8,代码来源:SpecificationFactory.cs

示例6: CreateSpecification

    public Specification CreateSpecification(Context context, FieldInfo specificationField)
    {
      bool isIgnored = context.IsIgnored || specificationField.HasAttribute<IgnoreAttribute>();
      It it = (It) specificationField.GetValue(context.Instance);
      string name = specificationField.Name.ReplaceUnderscores();

      return new Specification(name, it, isIgnored, specificationField);
    }
开发者ID:benlovell,项目名称:machine.specifications,代码行数:8,代码来源:SpecificationFactory.cs

示例7: CreateSpecificationFromBehavior

    public Specification CreateSpecificationFromBehavior(Behavior behavior, FieldInfo specificationField)
    {
      bool isIgnored = behavior.IsIgnored || specificationField.HasAttribute<IgnoreAttribute>();
      It it = (It) specificationField.GetValue(behavior.Instance);
      string name = specificationField.Name.ReplaceUnderscores();

      return new BehaviorSpecification(name, it, isIgnored, specificationField, behavior.Context, behavior);
    }
开发者ID:benlovell,项目名称:machine.specifications,代码行数:8,代码来源:SpecificationFactory.cs

示例8: CreateSpecification

    public Specification CreateSpecification(Context context, FieldInfo specificationField)
    {
      bool isIgnored = context.IsIgnored || specificationField.HasAttribute<IgnoreAttribute>();
      It it;
      if(typeof(IProvideFieldValues).IsAssignableFrom(context.Type))
        it = (It) context.Type.GetMethod("GetValue").Invoke(context.Instance, new[]{specificationField});
      else
        it = (It) specificationField.GetValue(context.Instance);
      string name = specificationField.Name.ToFormat();

      return new Specification(name, it, isIgnored, specificationField);
    }
开发者ID:joshperry,项目名称:machine.specifications,代码行数:12,代码来源:SpecificationFactory.cs

示例9: CreateBehaviorFrom

    public Behavior CreateBehaviorFrom(FieldInfo behaviorField, Context context)
    {
      var behaviorType = behaviorField.FieldType.GetGenericArguments().First();

      EnsureBehaviorHasBehaviorsAttribute(behaviorType);
      EnsureBehaviorDoesNotHaveFrameworkFieldsExceptIt(behaviorType);

      var behaviorInstance = Activator.CreateInstance(behaviorType);

      EnsureAllBehaviorFieldsAreInContext(behaviorType, context);

      var isIgnored = behaviorField.HasAttribute<IgnoreAttribute>() ||
                      behaviorInstance.GetType().HasAttribute<IgnoreAttribute>();
      var behavior = new Behavior(behaviorInstance, context, isIgnored);

      var itFieldInfos = behaviorType.GetInstanceFieldsOfType<Then>();
      CreateBehaviorSpecifications(itFieldInfos, behavior);

      return behavior;
    }
开发者ID:gshutler,项目名称:machine.specifications,代码行数:20,代码来源:BehaviorFactory.cs

示例10: InspectedProperty

        /// <summary>
        /// Initializes a new instance of the <see cref="InspectedProperty"/> class.
        /// </summary>
        /// <param name="type">
        /// The inspected type.
        /// </param>
        /// <param name="fieldInfo">
        /// The field info.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="type"/> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="fieldInfo"/> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If <paramref name="fieldInfo"/> 's declaring type has not been set.
        /// </exception>
        internal InspectedProperty(Type type, FieldInfo fieldInfo)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (fieldInfo == null)
            {
                throw new ArgumentNullException("fieldInfo");
            }

            if (fieldInfo.DeclaringType == null)
            {
                throw new ArgumentException("fieldInfo declaring type has not been set");
            }

            this.Name = fieldInfo.SerializableName();
            this.InspectedType = type;
            this.PropertyType = fieldInfo.FieldType;
            this.IsNotNullableValueType = this.PropertyType.IsNotNullableValueType();

            if (fieldInfo.DeclaringType != fieldInfo.ReflectedType)
            {
                fieldInfo = fieldInfo.DeclaringType.GetField(fieldInfo.Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            }

            try
            {
                this.Getter = DelegateFactory.CreateGetter(fieldInfo);
                this.Setter = DelegateFactory.CreateSetter(fieldInfo);
            }
            catch (Exception exception)
            {
                Logging.TraceException(exception);
            }

            this.Member = fieldInfo;

#if!HT4O_SERIALIZATION

            this.IdAttribute = fieldInfo.GetAttribute<IdAttribute>();

#endif
            this.IsTransient = fieldInfo.HasAttribute<TransientAttribute>() || fieldInfo.HasAttribute<NonSerializedAttribute>()
                               || fieldInfo.HasAttribute<IgnoreDataMemberAttribute>();

            this.Ignore = fieldInfo.HasAttribute<IgnoreAttribute>();
        }
开发者ID:andysoftdev,项目名称:ht4o,代码行数:67,代码来源:InspectedProperty.cs

示例11: CheckForStringError

		private static bool CheckForStringError(string value, FieldInfo field){
			if(field.HasAttribute(typeof(ComponentAttribute)) && !string.IsNullOrEmpty(value)){
				return TypeUtility.GetType(value)==null;
			}
			return string.IsNullOrEmpty(value);
		}
开发者ID:AlexGam,项目名称:TowerIsland,代码行数:6,代码来源:ErrorChecker.cs

示例12: IsIgnored

 private static bool IsIgnored(FieldInfo fi)
 {
     return fi.HasAttribute<IgnoreAttribute>() ||
         (Reflector.FindPropertyInfo(fi)?.HasAttribute<IgnoreAttribute>() ?? false);
 }
开发者ID:signumsoftware,项目名称:framework,代码行数:5,代码来源:ModifyInspector.cs


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