本文整理汇总了C#中Type.GetCustomAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetCustomAttributes方法的具体用法?C# Type.GetCustomAttributes怎么用?C# Type.GetCustomAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.GetCustomAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterExtensionType
static void RegisterExtensionType (Type type)
{
ExtensionInfo ext = new ExtensionInfo();
ext.Type = type;
object[] ats = type.GetCustomAttributes (typeof(XmlFormatExtensionPrefixAttribute), true);
foreach (XmlFormatExtensionPrefixAttribute at in ats)
ext.NamespaceDeclarations.Add (new XmlQualifiedName (at.Prefix, at.Namespace));
ats = type.GetCustomAttributes (typeof(XmlFormatExtensionAttribute), true);
if (ats.Length > 0)
{
XmlFormatExtensionAttribute at = (XmlFormatExtensionAttribute)ats[0];
ext.ElementName = at.ElementName;
if (at.Namespace != null) ext.Namespace = at.Namespace;
}
XmlRootAttribute root = new XmlRootAttribute ();
root.ElementName = ext.ElementName;
if (ext.Namespace != null) root.Namespace = ext.Namespace;
XmlReflectionImporter ri = new XmlReflectionImporter ();
XmlTypeMapping map = ri.ImportTypeMapping (type, root);
if (ext.ElementName == null) throw new InvalidOperationException ("XmlFormatExtensionAttribute must be applied to type " + type);
extensionsByName.Add (ext.Namespace + " " + ext.ElementName, ext);
extensionsByType.Add (type, ext);
maps.Add (map);
extensions.Add (ext);
}
示例2: Initialize
protected void Initialize(Type controllerType)
{
ControllerType = controllerType;
// If controller type has a RouteAttribute, then standard routes can't reach it.
_hasRouteAttributeOnController = controllerType.GetCustomAttributes(typeof(IDirectRouteFactory), inherit: false).Any()
|| controllerType.GetCustomAttributes(typeof(IRouteInfoProvider), inherit: false).Any();
PopulateLookupTables();
}
示例3: AddModuleDocumentation
/// <summary>
/// Adds the documentation for the current
/// module type to the referenced stringbuild.
/// </summary>
/// <returns></returns>
public static bool AddModuleDocumentation(ref StringBuilder working, Type moduleType)
{
if(moduleType == null)
return false;
object[] attrs = moduleType
.GetCustomAttributes(typeof(KPartModuleConfigurationDocumentationAttribute), true);
if(attrs.Length == 0)
return false;
KPartModuleConfigurationDocumentationAttribute attribute =
attrs[0] as KPartModuleConfigurationDocumentationAttribute;
if(attribute == null)
return false;
attrs = moduleType.GetCustomAttributes(typeof(KRequiresModuleAttribute), true);
string moduleStringName = string.Concat(moduleType.UnderlyingSystemType.Name, ".cs");
working.Append("//");
working.Append('=', moduleStringName.Length);
working.AppendLine();
working.Append("//");
working.AppendLine(moduleStringName);
working.Append("//");
working.Append('=', moduleStringName.Length);
working.AppendLine(attribute.ModuleDocumentation);
working.AppendLine("//");
working.AppendLine("//Requires Modules:");
if(attrs.Length > 0)
{
foreach(KRequiresModuleAttribute current in attrs)
{
working.Append("// > ");
working.AppendLine(
FormatAssemblyString(current.RequiredType));
}
}
else
{
working.Append("//=> None");
}
working.Append("//");
working.AppendLine();
return true;
}
示例4: GetAttributeValue
private static bool GetAttributeValue(Type objType, Type attrType, string property, bool inherit, ref object outVal)
{
object[] attrs = objType.GetCustomAttributes(attrType, inherit);
if (attrs.Length > 0)
return GetPropertyValue(attrs[0], property, ref outVal);
return false;
}
示例5: EnumTypeConfiguration
/// <summary>
/// Initializes a new instance of the <see cref="EnumTypeConfiguration"/> class.
/// </summary>
public EnumTypeConfiguration(ODataModelBuilder builder, Type clrType)
{
if (builder == null)
{
throw Error.ArgumentNull("builder");
}
if (clrType == null)
{
throw Error.ArgumentNull("clrType");
}
if (!clrType.IsEnum)
{
throw Error.Argument("clrType", SRResources.TypeCannotBeEnum, clrType.FullName);
}
ClrType = clrType;
IsFlags = clrType.GetCustomAttributes(typeof(FlagsAttribute), false).Any();
UnderlyingType = Enum.GetUnderlyingType(clrType);
ModelBuilder = builder;
_name = clrType.EdmName();
_namespace = clrType.Namespace ?? DefaultNamespace;
ExplicitMembers = new Dictionary<Enum, EnumMemberConfiguration>();
RemovedMembers = new List<Enum>();
}
示例6: TryFindConfigurationType
public virtual Type TryFindConfigurationType(Type contextType, IEnumerable<Type> typesToSearch = null)
{
DebugCheck.NotNull(contextType);
var typeFromAttribute = contextType.GetCustomAttributes(inherit: true)
.OfType<DbConfigurationTypeAttribute>()
.Select(a => a.ConfigurationType)
.FirstOrDefault();
if (typeFromAttribute != null)
{
if (!typeof(DbConfiguration).IsAssignableFrom(typeFromAttribute))
{
throw new InvalidOperationException(
Strings.CreateInstance_BadDbConfigurationType(typeFromAttribute.ToString(), typeof(DbConfiguration).ToString()));
}
return typeFromAttribute;
}
var configurations = (typesToSearch ?? contextType.Assembly.GetAccessibleTypes())
.Where(
t => typeof(DbConfiguration).IsAssignableFrom(t)
&& t != typeof(DbConfiguration)
&& !t.IsAbstract
&& !t.IsGenericType)
.ToList();
if (configurations.Count > 1)
{
throw new InvalidOperationException(
Strings.MultipleConfigsInAssembly(configurations.First().Assembly, typeof(DbConfiguration).Name));
}
return configurations.FirstOrDefault();
}
示例7: GetInitializer
public override object GetInitializer(Type webServiceType)
{
if (webServiceType.GetCustomAttributes (typeof (EncryptAttribute), false).Length > 0)
return CreateAlgorithm ();
else
return null;
}
示例8: GetInitializer
public override object GetInitializer(Type webServiceType)
{
if (webServiceType.GetCustomAttributes (typeof (DumpAttribute), false).Length > 0)
return true;
else
return false;
}
示例9: GetFor
public static UTActionInfoAttribute GetFor(Type type)
{
var info = type.GetCustomAttributes(typeof(UTActionInfoAttribute), false);
if (info.Length == 0) {
return new UTActionInfoAttribute();
}
return info[0] as UTActionInfoAttribute;
}
示例10: GetFor
/// <summary>
/// Gets the UTDefaultAction attached to the given type.
/// </summary>
/// <returns>
/// The UTDefaultAction or null, if there is no UTDefaultAction on the type.
/// </returns>
public static UTDefaultAction GetFor(Type type)
{
var annotations = type.GetCustomAttributes(typeof(UTDefaultAction), false);
if (annotations.Length == 1) {
return (UTDefaultAction) annotations[0];
}
return null;
}
示例11: GetFor
public static UTPropertyRendererAttribute GetFor(Type type)
{
var attrs = type.GetCustomAttributes (typeof(UTPropertyRendererAttribute), false);
if (attrs.Length == 1) {
return (UTPropertyRendererAttribute)attrs [0];
}
return null;
}
示例12: GetDebugViewType
private static Type GetDebugViewType(Type type)
{
var att =
(DebuggerTypeProxyAttribute)
type.GetCustomAttributes().Single(at => at.TypeId.Equals(typeof(DebuggerTypeProxyAttribute)));
var proxyName = att.ProxyTypeName;
proxyName = proxyName.Substring(0, proxyName.IndexOf(','));
return type.GetTypeInfo().Assembly.GetType(proxyName);
}
示例13: GetFor
/// <summary>
/// Gets the UTInspectorGroups attribute attached to the given type. If no such attribute is attached to the given
/// type, a default UTInspectorGroups object will be returned.
/// </summary>
/// <returns>
/// The UTInspectorGroups attribute.
/// </returns>
/// <param name='type'>
/// The type to read the attribute from.
/// </param>
public static UTInspectorGroups GetFor(Type type)
{
var groups = type.GetCustomAttributes(typeof(UTInspectorGroups), true);
if (groups.Length > 0) {
var hint = (UTInspectorGroups) groups[0];
return hint;
}
return Default;
}
示例14: IsTypeThemeable
public static bool IsTypeThemeable (Type type)
{
Object [] attributes = type.GetCustomAttributes (typeof (ThemeableAttribute), false);
if (attributes.Length != 0) {
foreach (Attribute attrib in attributes)
if (attrib is ThemeableAttribute)
return true;
}
return false;
}
示例15: DataContractImplementor
internal DataContractImplementor(EntityType ospaceEntityType)
{
_baseClrType = ospaceEntityType.ClrType;
var attributes = (DataContractAttribute[])_baseClrType.GetCustomAttributes(typeof(DataContractAttribute), false);
if (attributes.Length > 0)
{
_dataContract = attributes[0];
}
}