本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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>();
}
示例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);
}
示例12: IsIgnored
private static bool IsIgnored(FieldInfo fi)
{
return fi.HasAttribute<IgnoreAttribute>() ||
(Reflector.FindPropertyInfo(fi)?.HasAttribute<IgnoreAttribute>() ?? false);
}