本文整理汇总了C#中System.Type.GetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetAttribute方法的具体用法?C# Type.GetAttribute怎么用?C# Type.GetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.GetAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OutlinerPluginData
/// <summary>
/// Initializes a new instance of the OutlinerPluginData class.
/// </summary>
/// <param name="type">The type to create the metadata for.</param>
public OutlinerPluginData(Type type)
{
Throw.IfNull(type, "type");
this.Type = type;
OutlinerPluginAttribute pluginAttr = type.GetAttribute<OutlinerPluginAttribute>();
Throw.IfNull(pluginAttr, "OutlinerPlugin attribute not found on type.");
this.PluginType = pluginAttr.PluginType;
DisplayNameAttribute dispAtrr = type.GetAttribute<DisplayNameAttribute>();
if (dispAtrr != null)
this.DisplayName = dispAtrr.DisplayName;
else
this.DisplayName = type.Name;
LocalizedDisplayImageAttribute imgAttr = type.GetAttribute<LocalizedDisplayImageAttribute>();
if (imgAttr != null)
{
this.DisplayImageSmall = imgAttr.DisplayImageSmall;
this.DisplayImageLarge = imgAttr.DisplayImageLarge;
}
else
{
this.DisplayImageSmall = null;
this.DisplayImageLarge = null;
}
}
示例2: Match
private bool Match(Type bhvType, string searchString)
{
var bhvAttr = bhvType.GetAttribute<Behaviors.BehaviorModelAttribute>();
return CultureInfo.CurrentCulture.CompareInfo.IndexOf(bhvAttr.DefaultName, searchString, CompareOptions.IgnoreCase) >= 0
|| CultureInfo.CurrentCulture.CompareInfo.IndexOf(bhvType.FullName, searchString, CompareOptions.IgnoreCase) >= 0;
}
示例3: GetSheet
public static Sheet GetSheet(Type t)
{
var sheetAttr = (SheetAttribute)t.GetAttribute(typeof(SheetAttribute));
var sheetName = sheetAttr != null ? sheetAttr.Name : t.Name;
var definedColumn = sheetAttr != null ? sheetAttr.DefinedColumn : "";
var startingComments = sheetAttr != null && sheetAttr.StartingComments != null ? sheetAttr.StartingComments.ToList() : new List<string>();
var properties = from property in t.GetRuntimeProperties()
where (property.GetMethod != null && property.GetMethod.IsPublic)
|| (property.SetMethod != null && property.SetMethod.IsPublic)
|| (property.GetMethod != null && property.GetMethod.IsStatic)
|| (property.SetMethod != null && property.SetMethod.IsStatic)
select property;
var columns = new List<Column>();
foreach(var property in properties)
{
var ignore = property.GetCustomAttribute(typeof(IgnoredColumnAttribute), true);
if (property.CanWrite && ignore == null)
{
columns.Add(new Column(property));
}
}
return new Sheet(sheetName, columns, definedColumn, startingComments);
}
示例4: GenerateCommonCode
/// <summary>
/// 生成控制器及视图
/// </summary>
/// <param name="type">要生成代码的模型类</param>
/// <param name="gen">生成内容选项</param>
public static void GenerateCommonCode(Type type, string gen)
{
if (type.FullName == null) return;
var packageName = type.FullName.Split('.')[3];
// var packageName = type.FullName.Substring(15, 2);
var modelName = type.Name;
var tableAttribute = type.GetAttribute<TableAttribute>();
var moduleName = tableAttribute != null ? tableAttribute.DisplayName : "未命名";
if (gen.Contains("Controller"))
GenContollerCode(packageName, modelName, moduleName);
if (gen.Contains("Index"))
GenIndexCode(packageName, modelName);
var inputForList = GetInputForList(type);
if (gen.Contains("Create"))
{
GenCreateCode(packageName, modelName, inputForList);
}
if (gen.Contains("Edit"))
{
GenEditCode(packageName, modelName, inputForList);
}
var addlist = GetAddList(type);
if (gen.Contains("QuickSearch"))
{
GenQuickSearchCode(packageName, modelName, addlist);
}
if (gen.Contains("Delete"))
GenDeleteCode(packageName, modelName, addlist);
if (gen.Contains("Details"))
GenDetailsCode(packageName, modelName, addlist);
}
示例5: GetLifecycle
/// <summary>
/// 获取生命周期
/// </summary>
public static Lifecycle GetLifecycle(Type type)
{
if (!type.IsDefined(typeof(LifeCycleAttribute), false))
return Lifecycle.Singleton;
return type.GetAttribute<LifeCycleAttribute>(false).Lifetime;
}
示例6: Get
internal static string Get(Type type)
{
var result = type.GetAttribute<SchemaAttribute>(false);
if(result == null)
return null;
return result._name;
}
示例7: Descriptor
/// <summary>Creates a new <see cref="Descriptor"/> instance from a given type.</summary>
/// <param name="type">The type from which the descriptor will be created.</param>
public Descriptor(Type type) {
var attr = type.GetAttribute<DescriptorAttribute>();
if (attr != null) {
ParseXml(attr.Markup);
}
Subject = type;
}
示例8: ConnectorInfo
/// <summary>
/// Initializes a new instance of the <see cref="ConnectorInfo"/>.
/// </summary>
/// <param name="adapterType">The type of transaction or market data adapter.</param>
public ConnectorInfo(Type adapterType)
{
if (adapterType == null)
throw new ArgumentNullException("adapterType");
if (!typeof(IMessageAdapter).IsAssignableFrom(adapterType))
throw new ArgumentException("adapterType");
AdapterType = adapterType;
Name = adapterType.GetDisplayName();
Description = adapterType.GetDescription();
Category = adapterType.GetCategory(LocalizedStrings.Str1559);
var targetPlatform = adapterType.GetAttribute<TargetPlatformAttribute>();
if (targetPlatform != null)
{
PreferLanguage = targetPlatform.PreferLanguage;
Platform = targetPlatform.Platform;
}
else
{
PreferLanguage = Languages.English;
Platform = Platforms.AnyCPU;
}
}
示例9: TryCreateEditor
public static IPropertyEditor TryCreateEditor(Type editedType, Type editorType)
{
CustomPropertyEditorAttribute attribute = editorType.GetAttribute<CustomPropertyEditorAttribute>();
if (attribute == null || !attribute.Inherit)
{
return PropertyEditorTools.TryCreateSpecificEditor(editedType, editedType, editorType);
}
for (Type type = editedType; type != null; type = type.BaseType)
{
IPropertyEditor propertyEditor = PropertyEditorTools.TryCreateSpecificEditor(type, editedType, editorType);
if (propertyEditor != null)
{
return propertyEditor;
}
Type[] interfaces = type.GetInterfaces();
for (int i = 0; i < interfaces.Length; i++)
{
Type usedEditedType = interfaces[i];
propertyEditor = PropertyEditorTools.TryCreateSpecificEditor(usedEditedType, editedType, editorType);
if (propertyEditor != null)
{
return propertyEditor;
}
}
}
return null;
}
示例10: CreateObjectInfo
public IObjectInfo CreateObjectInfo(Type forType)
{
if (forType == null)
{
throw new ArgumentNullException("forType");
}
var tableAttribute = forType.GetAttribute<TableAttribute>(inherit: false);
if (tableAttribute == null)
{
throw new MappingException(ExceptionMessages.AttributeMappingConvention_NoTableAttribute.FormatWith(forType.FullName));
}
var identifierStrategy = IdentifierStrategy.DbGenerated;
var columns = this.CreateColumnInfos(forType, ref identifierStrategy);
var tableInfo = new TableInfo(columns, identifierStrategy, tableAttribute.Name, tableAttribute.Schema);
if (this.log.IsDebug)
{
this.log.Debug(LogMessages.MappingConvention_MappingTypeToTable, forType.FullName, tableInfo.Schema, tableInfo.Name);
}
return new PocoObjectInfo(forType, tableInfo);
}
示例11: BindingInfo
/// <summary>
/// 构造模型绑定器
/// </summary>
/// <param name="name">成员名称</param>
/// <param name="type">成员类型</param>
/// <param name="defaultValue">缺省值</param>
public BindingInfo(string name, Type type, object defaultValue)
{
Name = name;
Type = type;
DefaultValue = new Lazy<object>(() => defaultValue);
BindAttribute attr = type.GetAttribute<BindAttribute>(false);
if (attr == null)
Exclude = Include = new string[0];
else
{
if (string.IsNullOrEmpty(attr.Prefix))
IsNullPrefix = false;
else
Prefix = attr.Prefix.ToLower() + ".";
Exclude = new ReadOnlyCollection<string>(SplitString(attr.Exclude));
Include = new ReadOnlyCollection<string>(SplitString(attr.Include));
}
var binderAttr = type.GetAttribute<CustomModelBinderAttribute>(false);
if (binderAttr != null)
ModelBinder = binderAttr.GetBinder();
if (ModelBinder == null)
ModelBinder = ModelBinders.GetBinder(type);
if (ModelBinder == null)
ModelBinder = _DefaultModelBinder;
}
示例12: AttributeDrivenPatternSchema
public AttributeDrivenPatternSchema(Type patternProviderInterface, Type patternClientInterface)
{
if (!patternProviderInterface.IsInterface)
throw new ArgumentException("Provided pattern provider type should be an interface", "patternProviderInterface");
if (!patternClientInterface.IsInterface)
throw new ArgumentException("Provided pattern client type should be an interface", "patternClientInterface");
_patternProviderInterface = patternProviderInterface;
_patternClientInterface = patternClientInterface;
var patternClientName = _patternClientInterface.Name;
if (!patternClientName.EndsWith("Pattern") || !patternClientName.StartsWith("I"))
throw new ArgumentException("Pattern client interface named incorrectly, should be IXxxPattern", "patternClientInterface");
var baseName = patternClientName.Substring(1, patternClientName.Length - "I".Length - "Pattern".Length);
if (_patternProviderInterface.Name != string.Format("I{0}Provider", baseName))
throw new ArgumentException(string.Format("Pattern provider interface named incorrectly, should be I{0}Provider", baseName));
_patternName = string.Format("{0}Pattern", baseName);
var patternGuidAttr = _patternProviderInterface.GetAttribute<PatternGuidAttribute>();
if (patternGuidAttr == null) throw new ArgumentException("Provided type should be marked with PatternGuid attribute");
_patternGuid = patternGuidAttr.Value;
_methods = patternProviderInterface.GetMethodsMarkedWith<PatternMethodAttribute>().Select(GetMethodHelper).ToArray();
_properties = patternProviderInterface.GetPropertiesMarkedWith<PatternPropertyAttribute>().Select(GetPropertyHelper).ToArray();
ValidateClientInterface();
_handler = new AttributeDrivenPatternHandler(this);
}
示例13: GetInspectorType
/// <summary>
/// Gets inspector data such as name and description for the
/// specified type.
/// </summary>
/// <param name="type">Type to get inspector data for.</param>
/// <param name="conditionalInspectors">Dictionary to be filled with conditions for inspectors to be shown.</param>
/// <returns>Inspector data for the specified type.</returns>
public static InspectorType GetInspectorType(
Type type,
ref Dictionary<InspectorPropertyAttribute, InspectorConditionalPropertyAttribute> conditionalInspectors)
{
List<InspectorPropertyAttribute> inspectorProperties = InspectorUtils.CollectInspectorProperties(
type, ref conditionalInspectors);
var inspectorTypeAttribute = type.GetAttribute<InspectorTypeAttribute>();
if (inspectorTypeAttribute == null)
{
return null;
}
var inspectorTypeData = new InspectorType
{
Attribute = inspectorTypeAttribute,
Name = type.Name,
Description = inspectorTypeAttribute.Description,
Properties = inspectorProperties,
Type = type,
};
return inspectorTypeData;
}
示例14: GetDeliveryMode
public byte GetDeliveryMode(Type messageType)
{
Preconditions.CheckNotNull(messageType, "messageType");
var deliveryModeAttribute = messageType.GetAttribute<DeliveryModeAttribute>();
if (deliveryModeAttribute == null)
return GetDeliveryModeInternal(connectionConfiguration.PersistentMessages);
return GetDeliveryModeInternal(deliveryModeAttribute.IsPersistent);
}
示例15: LabelForTypeConvention
public string LabelForTypeConvention(Type type)
{
if (type.AttributeExists<LabelAttribute>())
{
return type.GetAttribute<LabelAttribute>().Label;
}
return type.Name.ToSeparatedWords();
}