本文整理汇总了C#中System.Type.IsDefined方法的典型用法代码示例。如果您正苦于以下问题:C# Type.IsDefined方法的具体用法?C# Type.IsDefined怎么用?C# Type.IsDefined使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.IsDefined方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildTable
private LitTable BuildTable(Type type)
{
LitTable table = null;
if (!type.IsDefined(typeof(TableAttribute), false))
{
if (!type.IsDefined(typeof(SPResultAttribute), false))
throw new LightException("no TableAttribute or SPResultAttribute found on " + type.FullName);
else
table = new LitTable(type, null, null);
}
else
{
TableAttribute tableAttr = (TableAttribute)type.GetCustomAttributes(typeof(TableAttribute), false)[0];
string name = tableAttr.Name;
string schema = tableAttr.Schema;
if (name == null || name.Length == 0)
name = type.Name;
table = new LitTable(type, name, schema);
}
FindInherited(type, table);
ProcessFields(type, table);
ProcessProperties(type, table);
ProcessMethods(type, table);
return table;
}
示例2: GetConversionCost
/// <inheritdoc />
public ConversionCost GetConversionCost(Type sourceType, Type targetType, IConverter elementConverter)
{
if (typeof(XPathNavigator).IsAssignableFrom(sourceType)
&& targetType.IsDefined(typeof(XmlTypeAttribute), true)
&& targetType.IsDefined(typeof(XmlRootAttribute), true))
return ConversionCost.Typical;
return ConversionCost.Invalid;
}
示例3: DrawAndGetNewValue
public object DrawAndGetNewValue(Type memberType, string memberName, object value, Entity entity, int index, IComponent component)
{
if(memberType.IsDefined(typeof(FlagsAttribute), false)) {
return EditorGUILayout.EnumMaskField(memberName, (Enum)value);
}
return EditorGUILayout.EnumPopup(memberName, (Enum)value);
}
示例4: GetLifecycle
/// <summary>
/// 获取生命周期
/// </summary>
public static Lifecycle GetLifecycle(Type type)
{
if (!type.IsDefined(typeof(LifeCycleAttribute), false))
return Lifecycle.Singleton;
return type.GetCustomAttribute<LifeCycleAttribute>(false).Lifetime;
}
示例5: AddTypeToLookupTables
private void AddTypeToLookupTables(Type type)
{
if (type == null)
{
return;
}
// we've seen it already
if (_typeByName.ContainsKey(type.Name))
{
return;
}
// look this Type up by name
_typeByName[type.Name] = type;
if (!type.IsDefined(typeof(JsonApiResourceTypeAttribute), true))
{
return;
}
var attribute =
type.GetCustomAttributes(typeof(JsonApiResourceTypeAttribute), true).FirstOrDefault() as JsonApiResourceTypeAttribute;
if (attribute != null)
{
_typeByJsonApiResourceTypeName[attribute.JsonApiResourceTypeName] = type;
}
}
示例6: Handle
/// <summary>
/// Handles the specified Type depending on the scanning strategy
/// of the <see cref="TypeConfiguration"/>.
/// </summary>
/// <param name="type">Type to handle.</param>
internal void Handle( Type type )
{
switch ( ScanningStrategy )
{
case ScanFor.TypesThatAreDecoratedWithThisAttribute:
if ( type.IsDefined( Type, true ) )
{
Action( type );
}
break;
case ScanFor.TypesThatImplementThisInterface:
if ( Type.IsAssignableFrom( type ) && type.IsInterface == false )
{
Action( type );
}
break;
case ScanFor.TypesThatInheritFromThisAbstractClass:
if ( Type.IsAssignableFrom( type ) && type.IsAbstract == false )
{
Action( type );
}
break;
case ScanFor.TypesThatInheritFromThisClass:
if ( Type.IsAssignableFrom( type ) && type != Type )
{
Action( type );
}
break;
default:
Action( type );
break;
}
}
示例7: PortableEnum
/// <summary>
/// Constructor from an enumerated type
/// </summary>
/// <param name="enumType">A type representing an existing enumeration</param>
/// <exception cref="System.ArgumentException">Throw if the type if not an enumerated type</exception>
public PortableEnum(Type enumType)
{
if (!enumType.IsEnum)
{
throw new ArgumentException("Parameter is not an enumerated type");
}
_entries = new Dictionary<string, long>();
string[] names = Enum.GetNames(enumType);
Array values = Enum.GetValues(enumType);
for (int i = 0; i < names.Length; ++i)
{
long v = (long)Convert.ChangeType(values.GetValue(i), typeof(long));
_entries.Add(names[i], v);
}
if (enumType.IsDefined(typeof(FlagsAttribute), false))
{
_isFlags = true;
}
else
{
_isFlags = false;
}
_value = 0;
_name = enumType.Name;
}
示例8: CreateMemberSetters
private MemberSetter[] CreateMemberSetters(Type type)
{
var selfMembers = type
.GetProperties(bindingFlags)
.Where(m => m.CanWrite)
.Union(type.GetFields(bindingFlags).Cast<MemberInfo>())
.Where(m => m.IsDefined(typeof (InjectAttribute), true))
.ToArray();
MemberSetter[] baseSetters = null;
if (!type.IsDefined<FrameworkBoundaryAttribute>(false))
{
var baseType = type.BaseType;
if (baseType != typeof (object))
baseSetters = GetMembers(baseType);
}
if (selfMembers.Length == 0 && baseSetters != null)
return baseSetters;
var baseMembersCount = baseSetters == null ? 0 : baseSetters.Length;
var result = new MemberSetter[selfMembers.Length + baseMembersCount];
if (baseMembersCount > 0)
Array.Copy(baseSetters, 0, result, 0, baseMembersCount);
for (var i = 0; i < selfMembers.Length; i++)
{
var member = selfMembers[i];
var resultIndex = i + baseMembersCount;
result[resultIndex].member = member;
result[resultIndex].setter = MemberAccessorsFactory.GetSetter(member);
}
return result;
}
示例9: FindInherited
private void FindInherited(Type type, LitTable table)
{
if (type.IsDefined(typeof(MapAttribute), false))
{
object[] attrs = type.GetCustomAttributes(typeof(MapAttribute), false);
foreach (MapAttribute attr in attrs)
{
IDataBridge data = null;
BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
MemberInfo member = type.GetProperty(attr.Field, flags);
if (member != null)
{
data = new PropertyBridge((PropertyInfo)member);
}
else
{
member = type.GetField(attr.Field, flags);
if (member != null)
data = new FieldBridge((FieldInfo)member);
else
throw new LightException("member " + attr.Field + " not found in class " + type.Name);
}
if (attr.Name == null || attr.Name.Length == 0)
attr.Name = member.Name;
SqlColumn column = new SqlColumn(table, attr.Name, data);
if (attr.Alias == null || attr.Alias.Length == 0)
column.Alias = attr.Field;
else
column.Alias = attr.Alias;
column.IsID = attr.ID;
column.IsPK = attr.PK;
table.Add(column);
}
}
}
示例10: ProcessType
protected void ProcessType(Type type)
{
if (type.IsDefined(typeof(MapClassAttribute), false))
{
m_classDescriptors.Add(CreateMapping(type));
}
}
示例11: ReadJson
/// <inheritdoc/>
public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
{
if (HandleNullableTypes(ref objectType) && reader.TokenType == JsonToken.Null)
return null;
if (reader.TokenType == JsonToken.String || !objectType.IsDefined(typeof(FlagsAttribute), false))
{
return Enum.Parse(objectType, serializer.Deserialize<String>(reader));
}
else
{
var enumNames = (String[])serializer.Deserialize(reader, typeof(String[]));
if (enumNames == null)
throw new JsonReaderException(NucleusStrings.JsonValueCannotBeNull);
var enumValue = 0ul;
for (int i = 0; i < enumNames.Length; i++)
{
enumValue |= Convert.ToUInt64(Enum.Parse(objectType, enumNames[i]));
}
return Enum.ToObject(objectType, enumValue);
}
}
示例12: CreateViewModelConfig
public ViewModelConfig CreateViewModelConfig(Type type)
{
if (!type.IsBaseObject() && !type.IsDefined(typeof(ComplexTypeAttribute))) return null;
string serviceName = "";
if (type.IsBaseObject())
{
if (type.IsAssignableFrom(typeof(HCategory)))
serviceName = typeof(IBaseCategoryService<>).GetTypeName();
else if (type.IsAssignableFrom(typeof(ICategorizedItem)))
serviceName = typeof(IBaseCategorizedItemService<>).GetTypeName();
else
serviceName = typeof(IBaseObjectService<>).GetTypeName();
}
return new ViewModelConfig(
mnemonic: type.GetTypeName(),
entity: type.GetTypeName(),
listView: new ListView(),
detailView: new DetailView(),
lookupProperty:
type.IsBaseObject()
? (type.GetProperty("Title") ?? type.GetProperty("Name") ?? type.GetProperty("ID")).Name
: "",
service: serviceName);
}
示例13: IsCompilerGenerated
private bool IsCompilerGenerated(Type t)
{
if (t == null)
return false;
return t.IsDefined(typeof(CompilerGeneratedAttribute), false) || IsCompilerGenerated(t.DeclaringType);
}
示例14: getGroups
private static void getGroups(string fieldName, Type type, object original, object translation,
NumberSystem originalNumSys, NumberSystem translationNumSys, Dictionary<object, TranslationGroup> dic,
ref TranslationGroup ungrouped, IEnumerable<object> classGroups, string path)
{
if (!type.IsDefined<LingoStringClassAttribute>(true))
{
if (fieldName == null)
throw new ArgumentException(@"Type ""{0}"" must be marked with the [LingoStringClass] attribute.".Fmt(type.FullName), "type");
else
throw new ArgumentException(@"Field ""{0}.{1}"" must either be marked with the [LingoIgnore] attribute, or be of type TrString, TrStringNumbers, or a type with the [LingoStringClass] attribute.".Fmt(type.FullName, fieldName), "type");
}
var thisClassGroups = type.GetCustomAttributes(true).OfType<LingoInGroupAttribute>().Select(attr => attr.Group);
if (classGroups != null)
thisClassGroups = thisClassGroups.Concat(classGroups);
foreach (var f in type.GetFields(BindingFlags.Public | BindingFlags.Instance))
{
if (f.FieldType == typeof(TrString) || f.FieldType == typeof(TrStringNum))
{
string notes = f.GetCustomAttributes<LingoNotesAttribute>().Select(lna => lna.Notes).FirstOrDefault();
var trInfo = f.FieldType == typeof(TrString)
? (TranslationInfo) new TrStringInfo
{
Label = path + f.Name,
Notes = notes,
NewOriginal = ((TrString) f.GetValue(original)).Translation,
TranslationTr = (TrString) f.GetValue(translation)
}
: (TranslationInfo) new TrStringNumInfo((TrStringNum) f.GetValue(original), (TrStringNum) f.GetValue(translation), originalNumSys, translationNumSys)
{
Label = path + f.Name,
Notes = notes
};
var groups = f.GetCustomAttributes<LingoInGroupAttribute>().Select(attr => attr.Group).Concat(thisClassGroups);
if (!groups.Any())
{
if (ungrouped == null)
ungrouped = new TranslationGroup { Label = "Ungrouped strings", Notes = "This group contains strings not found in any other group." };
ungrouped.Infos.Add(trInfo);
}
else
{
foreach (var group in groups)
{
TranslationGroup grp;
if (!dic.TryGetValue(group, out grp))
{
grp = createGroup(group);
dic[group] = grp;
}
grp.Infos.Add(trInfo);
}
}
}
else if (!f.IsDefined<LingoIgnoreAttribute>(true))
getGroups(f.Name, f.FieldType, f.GetValue(original), f.GetValue(translation), originalNumSys, translationNumSys, dic, ref ungrouped, thisClassGroups, path + f.Name + " / ");
}
}
示例15: AllowsUnauthorized
private Boolean AllowsUnauthorized(Type authorizedControllerType, MethodInfo method)
{
if (method.IsDefined(typeof(AuthorizeAttribute), false)) return false;
if (method.IsDefined(typeof(AllowAnonymousAttribute), false)) return true;
if (method.IsDefined(typeof(AllowUnauthorizedAttribute), false)) return true;
while (authorizedControllerType != typeof(Controller))
{
if (authorizedControllerType.IsDefined(typeof(AuthorizeAttribute), false)) return false;
if (authorizedControllerType.IsDefined(typeof(AllowAnonymousAttribute), false)) return true;
if (authorizedControllerType.IsDefined(typeof(AllowUnauthorizedAttribute), false)) return true;
authorizedControllerType = authorizedControllerType.BaseType;
}
return true;
}