本文整理汇总了C#中ICustomAttributeProvider.GetCustomAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# ICustomAttributeProvider.GetCustomAttributes方法的具体用法?C# ICustomAttributeProvider.GetCustomAttributes怎么用?C# ICustomAttributeProvider.GetCustomAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICustomAttributeProvider
的用法示例。
在下文中一共展示了ICustomAttributeProvider.GetCustomAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeNode
private static DashbardIconWithDisplay MakeNode(DashboardIconAttribute sitemapNodeAttr, ICustomAttributeProvider info)
{
var sitemapNode = new DashbardIconWithDisplay
{
DashboardIcon = sitemapNodeAttr,
Display = info.GetCustomAttributes(false).OfType<DisplayAttribute>().FirstOrDefault(),
Url = info.GetCustomAttributes(false).OfType<IUrl>().FirstOrDefault() ?? new ConstUrl("#")
};
return sitemapNode;
}
示例2: TemplateBuilder
internal TemplateBuilder (ICustomAttributeProvider prov)
{
object[] ats = prov.GetCustomAttributes (typeof (TemplateContainerAttribute), true);
if (ats.Length > 0)
containerAttribute = (TemplateContainerAttribute) ats [0];
ats = prov.GetCustomAttributes (typeof (TemplateInstanceAttribute), true);
if (ats.Length > 0)
instanceAttribute = (TemplateInstanceAttribute) ats [0];
}
示例3: BuildInitializedMember
private static void BuildInitializedMember(List<InitializedMember> members, ICustomAttributeProvider attributeProvider, InitializedMemberFactory factory)
{
var finders = (ComponentFinderAttribute[]) attributeProvider.GetCustomAttributes(typeof(ComponentFinderAttribute), true);
if (finders.Length == 0)
return;
if (finders.Length > 1)
throw new InvalidOperationException(string.Format("Member '{0}' has more than one ComponentFinderAttribute.", attributeProvider));
var finder = finders[0];
var decorators = (ComponentDecoratorAttribute[])attributeProvider.GetCustomAttributes(typeof(ComponentDecoratorAttribute), true);
InitializedMember member = factory(finder, decorators);
members.Add(member);
}
示例4: Draw3
public static ReferenceType<Boolean3> Draw3(Rect position, object eventsObj, GUIContent content, ICustomAttributeProvider info = null)
{
Boolean3 boolPair = (Boolean3)eventsObj;
var boolArray = new bool[] { boolPair.x, boolPair.y, boolPair.z };
Builder = new StringBuilder();
char flags = (char)EditorNameFlags.Default;
if (info != null && info.HasAttribute(typeof(CustomNamesAttribute)))
{
CustomNamesAttribute attribute = info.GetCustomAttributes<CustomNamesAttribute>()[0];
flags = (char)attribute.CustomFlags;
Builder.Append(flags);
if (attribute.UseVariableNameAsTitle)
{
Builder.Append(Seperator);
Builder.Append(content.text);
}
Builder.Append(attribute.CombinedName);
}
else
{
Builder.Append(flags);
Builder.Append(Seperator);
Builder.Append(content.text);
}
content.text = Builder.ToString();
DrawMultiBoolean(ref boolArray, position, content);
boolPair.x = boolArray[0];
boolPair.y = boolArray[1];
boolPair.z = boolArray[2];
return boolPair;
}
示例5: GetBinderFromAttributes
internal static IModelBinder GetBinderFromAttributes(ICustomAttributeProvider element, Func<string> errorMessageAccessor)
{
// this method is used to get a custom binder based on the attributes of the element passed to it.
// it will return null if a binder cannot be detected based on the attributes alone.
var attrs = (CustomModelBinderAttribute[]) element.GetCustomAttributes(typeof (CustomModelBinderAttribute), true /* inherit */);
if (attrs == null)
{
return null;
}
switch (attrs.Length)
{
case 0:
return null;
case 1:
var binder = attrs[0].GetBinder();
return binder;
default:
var errorMessage = errorMessageAccessor();
throw new InvalidOperationException(errorMessage);
}
}
示例6: SoapAttributes
/// <include file='doc\SoapAttributes.uex' path='docs/doc[@for="SoapAttributes.SoapAttributes1"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public SoapAttributes(ICustomAttributeProvider provider) {
object[] attrs = provider.GetCustomAttributes(false);
for (int i = 0; i < attrs.Length; i++) {
if (attrs[i] is SoapIgnoreAttribute || attrs[i] is ObsoleteAttribute) {
this.soapIgnore = true;
break;
}
else if (attrs[i] is SoapElementAttribute) {
this.soapElement = (SoapElementAttribute)attrs[i];
}
else if (attrs[i] is SoapAttributeAttribute) {
this.soapAttribute = (SoapAttributeAttribute)attrs[i];
}
else if (attrs[i] is SoapTypeAttribute) {
this.soapType = (SoapTypeAttribute)attrs[i];
}
else if (attrs[i] is SoapEnumAttribute) {
this.soapEnum = (SoapEnumAttribute)attrs[i];
}
else if (attrs[i] is DefaultValueAttribute) {
this.soapDefaultValue = ((DefaultValueAttribute)attrs[i]).Value;
}
}
if (soapIgnore) {
this.soapElement = null;
this.soapAttribute = null;
this.soapType = null;
this.soapEnum = null;
this.soapDefaultValue = null;
}
}
示例7: IncludeTypes
private void IncludeTypes(ICustomAttributeProvider provider, RecursionLimiter limiter)
{
object[] attrs = provider.GetCustomAttributes(typeof(SoapIncludeAttribute), false);
for (int i = 0; i < attrs.Length; i++) {
IncludeType(((SoapIncludeAttribute)attrs[i]).Type, limiter);
}
}
示例8: XmlAttributes
public XmlAttributes (ICustomAttributeProvider provider)
{
object[] attributes = provider.GetCustomAttributes(false);
foreach(object obj in attributes)
{
if(obj is XmlAnyAttributeAttribute)
xmlAnyAttribute = (XmlAnyAttributeAttribute) obj;
else if(obj is XmlAnyElementAttribute)
xmlAnyElements.Add((XmlAnyElementAttribute) obj);
else if(obj is XmlArrayAttribute)
xmlArray = (XmlArrayAttribute) obj;
else if(obj is XmlArrayItemAttribute)
xmlArrayItems.Add((XmlArrayItemAttribute) obj);
else if(obj is XmlAttributeAttribute)
xmlAttribute = (XmlAttributeAttribute) obj;
else if(obj is XmlChoiceIdentifierAttribute)
xmlChoiceIdentifier = (XmlChoiceIdentifierAttribute) obj;
else if(obj is DefaultValueAttribute)
xmlDefaultValue = ((DefaultValueAttribute)obj).Value;
else if(obj is XmlElementAttribute )
xmlElements.Add((XmlElementAttribute ) obj);
else if(obj is XmlEnumAttribute)
xmlEnum = (XmlEnumAttribute) obj;
else if(obj is XmlIgnoreAttribute)
xmlIgnore = true;
else if(obj is XmlNamespaceDeclarationsAttribute)
xmlns = true;
else if(obj is XmlRootAttribute)
xmlRoot = (XmlRootAttribute) obj;
else if(obj is XmlTextAttribute)
xmlText = (XmlTextAttribute) obj;
else if(obj is XmlTypeAttribute)
xmlType = (XmlTypeAttribute) obj;
}
}
示例9: GetInvalidSuppressMessageAttributeErrorsCore
private static IEnumerable<string> GetInvalidSuppressMessageAttributeErrorsCore(ICustomAttributeProvider target, string name, string targetType, IEnumerable<Exemption> exemptions) {
foreach (SuppressMessageAttribute attr in target.GetCustomAttributes(typeof(SuppressMessageAttribute), false).OfType<SuppressMessageAttribute>()) {
if (String.IsNullOrWhiteSpace(attr.Justification) && !IsExempt(exemptions, attr.CheckId, name, targetType)) {
yield return FormatErrorMessage(attr, name, targetType);
}
}
}
示例10: FromCustomAttributeProvider
public static IEnumerable<UsesFeatureAttribute> FromCustomAttributeProvider(ICustomAttributeProvider provider)
{
var attrs = provider.GetCustomAttributes ("Android.App.UsesFeatureAttribute");
foreach (var attr in attrs) {
UsesFeatureAttribute self = new UsesFeatureAttribute ();
if (attr.HasProperties) {
// handle the case where the user sets additional properties
self.specified = mapping.Load (self, attr);
if (self.specified.Contains("GLESVersion") && self.GLESVersion==0) {
throw new InvalidOperationException("Invalid value '0' for UsesFeatureAttribute.GLESVersion.");
}
}
if (attr.HasConstructorArguments) {
// in this case the user used one of the Consructors to pass arguments and possibly properties
// so we only create the specified list if its not been created already
if (self.specified == null)
self.specified = new List<string>();
foreach(var arg in attr.ConstructorArguments) {
if (arg.Value.GetType() == typeof(string)) {
self.specified.Add("Name");
self.Name = (string)arg.Value;
}
}
}
yield return self;
}
}
示例11: FromCustomAttributeProvider
public static IEnumerable<UsesLibraryAttribute> FromCustomAttributeProvider(ICustomAttributeProvider provider)
{
var attrs = provider.GetCustomAttributes ("Android.App.UsesLibraryAttribute");
foreach (var attr in attrs) {
UsesLibraryAttribute self;
string[] extra = null;
if (attr.ConstructorArguments.Count == 1) {
self = new UsesLibraryAttribute (
(string) attr.ConstructorArguments [0].Value);
extra = new[]{"Name"};
} else if (attr.ConstructorArguments.Count == 2) {
self = new UsesLibraryAttribute (
(string) attr.ConstructorArguments [0].Value,
(bool) attr.ConstructorArguments [1].Value);
extra = new[]{"Name", "Required"};
} else {
self = new UsesLibraryAttribute ();
extra = new string[0];
}
self.specified = mapping.Load (self, attr);
foreach (var e in extra)
self.specified.Add (e);
yield return self;
}
}
示例12: GetDescrition
internal static string GetDescrition(MemberInfo member, ICustomAttributeProvider provider, string defaultValue, string memberSuffix)
{
Type t = member as Type;
if (t == null)
{
t = member.DeclaringType;
}
object[] attributes = t.GetCustomAttributes(typeof(MBeanResourceAttribute), true);
if (attributes.Length > 0)
{
ResourceManager manager = new ResourceManager(((MBeanResourceAttribute)attributes[0]).ResourceName, t.Assembly);
string name = memberSuffix == null ? member.Name : member.Name + "__" + memberSuffix;
string descr = manager.GetString(member.Name);
if (descr != null)
{
return descr;
}
}
attributes = provider.GetCustomAttributes(typeof(DescriptionAttribute), true);
if (attributes.Length > 0)
{
return ((DescriptionAttribute)attributes[0]).Description;
}
return defaultValue;
}
示例13: AttributeSet
public AttributeSet(ICustomAttributeProvider attributeProvider)
{
this.attributes = attributeProvider
.GetCustomAttributes(true)
.Cast<Attribute>()
.ToArray();
}
示例14: GetTypeConverters
public static ITypeConverter[] GetTypeConverters(ICustomAttributeProvider attributeProvider)
{
var attributes = attributeProvider.GetCustomAttributes(typeof(TypeConverterAttribute), true).Cast<TypeConverterAttribute>();
return attributes
.Select(x => new { x.Context, Converter = (ITypeConverter)Activator.CreateInstance(x.ConverterType) })
.Select(x => x.Context == TypeConversionContext.None ? x.Converter : new ContextBasedTypeConverter(x.Context, x.Converter))
.ToArray();
}
示例15: GetHeaders
public static HttpHeader[] GetHeaders(ICustomAttributeProvider provider)
{
return provider
.GetCustomAttributes(typeof(HeaderAttribute), true)
.Cast<HeaderAttribute>()
.Select(x => new HttpHeader(x.Name, x.Values))
.ToArray();
}