本文整理汇总了C#中System.Attribute.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# Attribute.FirstOrDefault方法的具体用法?C# Attribute.FirstOrDefault怎么用?C# Attribute.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Attribute
的用法示例。
在下文中一共展示了Attribute.FirstOrDefault方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindTransactionAttribute
protected override ITransactionAttribute FindTransactionAttribute(Attribute[] attributes)
{
if (attributes == null)
{
return null;
}
var attribute = attributes.FirstOrDefault(attr => attr is TransactionAttribute) as TransactionAttribute;
if(attribute == null)
{
return null;
}
var ruleBasedTransactionAttribute = new RuleBasedTransactionAttribute
{
PropagationBehavior = attribute.TransactionPropagation,
TransactionIsolationLevel = attribute.IsolationLevel,
ReadOnly = attribute.ReadOnly,
EnterpriseServicesInteropOption =
attribute.EnterpriseServicesInteropOption
};
IEnumerable<Attribute> rollBackFor = attribute.RollbackFor.Select(type => new RollbackRuleAttribute(type) as Attribute);
IEnumerable<Attribute> noRollBackFor = attribute.NoRollbackFor.Select(type => new NoRollbackRuleAttribute(type) as Attribute);
IList<Attribute> rollBackRules = rollBackFor.Union(noRollBackFor).ToList();
ruleBasedTransactionAttribute.RollbackRules = rollBackRules.ToList();
return ruleBasedTransactionAttribute;
}
示例2: GenericField
//For generic automatic editors. Passing a MemberInfo will also check for attributes
public static object GenericField(string name, object value, Type t, MemberInfo member = null, object instance = null)
{
if (t == null){
GUILayout.Label("NO TYPE PROVIDED!");
return value;
}
//Preliminary Hides
if (typeof(Delegate).IsAssignableFrom(t)){
return value;
}
name = name.SplitCamelCase();
//
IEnumerable<Attribute> attributes = new Attribute[0];
if (member != null){
//Hide class?
if (t.GetCustomAttributes(typeof(HideInInspector), true ).FirstOrDefault() != null){
return value;
}
attributes = member.GetCustomAttributes(true).Cast<Attribute>();
//Hide field?
if (attributes.Any(a => a is HideInInspector) ){
return value;
}
//Is required?
if (attributes.Any(a => a is RequiredFieldAttribute)){
if ( (value == null || value.Equals(null) ) ||
(t == typeof(string) && string.IsNullOrEmpty((string)value) ) ||
(typeof(BBParameter).IsAssignableFrom(t) && (value as BBParameter).isNull) )
{
GUI.backgroundColor = lightRed;
}
}
}
if (member != null){
var nameAtt = attributes.FirstOrDefault(a => a is NameAttribute) as NameAttribute;
if (nameAtt != null){
name = nameAtt.name;
}
if (instance != null){
var showAtt = attributes.FirstOrDefault(a => a is ShowIfAttribute) as ShowIfAttribute;
if (showAtt != null){
var targetField = instance.GetType().GetField(showAtt.fieldName);
if (targetField == null || targetField.FieldType != typeof(bool)){
GUILayout.Label(string.Format("[ShowIf] Error: bool \"{0}\" does not exist.", showAtt.fieldName));
} else {
if ((bool)targetField.GetValue(instance) != showAtt.show){
return value;
}
}
}
}
}
//Before everything check BBParameter
if (typeof(BBParameter).IsAssignableFrom(t)){
return BBParameterField(name, (BBParameter)value, false, member);
}
//Cutstom object drawers
var objectDrawer = GetCustomDrawer(t);
if (objectDrawer != null && !(objectDrawer is NoDrawer) ){
return objectDrawer.DrawGUI(name, value, member as FieldInfo, null, instance);
}
//Cutstom attribute drawers
foreach(CustomDrawerAttribute att in attributes.OfType<CustomDrawerAttribute>()){
var attributeDrawer = GetCustomDrawer(att.GetType());
if (attributeDrawer != null && !(attributeDrawer is NoDrawer)){
return attributeDrawer.DrawGUI(name, value, member as FieldInfo, att, instance);
}
}
//Then check UnityObjects
if ( typeof(UnityObject).IsAssignableFrom(t) ) {
if (t == typeof(Component) && (Component)value != null)
return ComponentField(name, (Component)value, typeof(Component));
return EditorGUILayout.ObjectField(name, (UnityObject)value, t, true);
}
//Force UnityObject field?
if (member != null && attributes.Any(a => a is ForceObjectFieldAttribute)){
return EditorGUILayout.ObjectField(name, value as UnityObject, t, true );
}
//Restricted popup values?
if (member != null){
var popAtt = attributes.FirstOrDefault(a => a is PopupFieldAttribute) as PopupFieldAttribute;
if (popAtt != null){
if (popAtt.staticPath != null){
//.........这里部分代码省略.........