本文整理汇总了C#中ICustomAttributeProvider类的典型用法代码示例。如果您正苦于以下问题:C# ICustomAttributeProvider类的具体用法?C# ICustomAttributeProvider怎么用?C# ICustomAttributeProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ICustomAttributeProvider类属于命名空间,在下文中一共展示了ICustomAttributeProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetKnownTypes
public static IEnumerable<Type> GetKnownTypes(ICustomAttributeProvider provider)
{
System.Collections.Generic.List<System.Type> knownTypes =
new System.Collections.Generic.List<System.Type>();
//// Add any types to include here.
//return knownTypes;
Type[] types = Assembly.Load("SMT_FB_EFModel").GetTypes();
for (int i = 0; i < types.Length; i++)
{
if ((types[i].BaseType == typeof(EntityObject)) || typeof(VisitUserBase).IsAssignableFrom(types[i]))
{
knownTypes.Add(types[i]);
}
}
//List<Type> typesO = knownTypes.ToList();
//typesO.ForEach(item =>
//{
// knownTypes.Add(typeof(List<>).MakeGenericType(new Type[] { item }));
//});
knownTypes.Add(typeof(AuditResult));
knownTypes.Add(typeof(SaveResult));
knownTypes.Add(typeof(VirtualAudit));
knownTypes.Add(typeof(SMT.SaaS.BLLCommonServices.FlowWFService.SubmitData));
return knownTypes;
}
示例2: ProcessAttributes
public virtual void ProcessAttributes(IMetaData metaData, ICustomAttributeProvider attributeProvider)
{
foreach(AttributeProcessor processor in AttributeProcessors)
{
processor.Process(metaData, attributeProvider, this.Config);
}
}
示例3: 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;
}
}
示例4: 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;
}
}
示例5: 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;
}
}
示例6: AssertDescriptorMatches
void AssertDescriptorMatches(ILookup<string, SecurityAttributeDescriptor> descriptors, string signature, ICustomAttributeProvider element)
{
if (descriptors.Contains(signature))
AssertContainsAttribute(element, descriptors[signature].Single().AttributeTypeName);
else
AssertContainsNoAttribute(element);
}
示例7: AttributeSet
public AttributeSet(ICustomAttributeProvider attributeProvider)
{
this.attributes = attributeProvider
.GetCustomAttributes(true)
.Cast<Attribute>()
.ToArray();
}
示例8: TemplateBuilder
internal TemplateBuilder (ICustomAttributeProvider prov)
{
object[] ats = prov.GetCustomAttributes (typeof(TemplateContainerAttribute), true);
if (ats.Length > 0) {
containerAttribute = (TemplateContainerAttribute) ats [0];
}
}
示例9: GetAttributes
public IEnumerable<ValidationAttribute> GetAttributes(ICustomAttributeProvider attributeProvider)
{
return attributeProvider
.GetAttributes<ValidationAttribute>()
.Select(attr => container.BuildUp(attr.GetType(), attr))
.Cast<ValidationAttribute>();
}
示例10: CreateSubstituteRequest
private static object CreateSubstituteRequest(ICustomAttributeProvider request, SubstituteAttribute attribute)
{
var parameter = request as ParameterInfo;
if (parameter != null)
{
return new SubstituteRequest(parameter.ParameterType);
}
var property = request as PropertyInfo;
if (property != null)
{
return new SubstituteRequest(property.PropertyType);
}
var field = request as FieldInfo;
if (field != null)
{
return new SubstituteRequest(field.FieldType);
}
throw new NotSupportedException(
string.Format(
CultureInfo.CurrentCulture,
"{0} is applied to an unsupported code element {1}",
attribute, request));
}
示例11: 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);
}
}
示例12: ResolveType
public static TypeDefinition ResolveType(string type, ICustomAttributeProvider provider, IAssemblyResolver resolver)
{
if (provider == null)
throw new ArgumentException ("Type resolution support requires an AssemblyDefinition or TypeDefinition.", "provider");
if (resolver == null)
throw new ArgumentException ("Type resolution support requires a IAssemblyResolver.", "resolver");
// `type` is either a "bare" type "Foo.Bar", or an
// assembly-qualified type "Foo.Bar, AssemblyName [Version=...]?".
//
// Bare types are looked up via `provider`; assembly-qualified types are
// looked up via `resolver`
int c = type.IndexOf (',');
string typeName = c < 0 ? type : type.Substring (0, c);
string assmName = c < 0 ? null : type.Substring (c+1);
AssemblyDefinition assembly = assmName == null ? null : resolver.Resolve (assmName);
if (assembly == null) {
assembly = provider as AssemblyDefinition;
if (assembly == null) {
TypeDefinition decl = (TypeDefinition) provider;
assembly = decl.Module.Assembly;
}
}
var ret = assembly.Modules.Cast<ModuleDefinition> ()
.Select (md => md.Types.FirstOrDefault (t => t.FullName == typeName))
.FirstOrDefault (td => td != null);
if (ret == null)
throw new ArgumentException ("Type not found: " + type, "type");
return ret;
}
示例13: 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);
}
}
}
示例14: ProcessExports
void ProcessExports(ICustomAttributeProvider provider)
{
if (provider == null)
return;
if (!provider.HasCustomAttributes)
return;
var attributes = provider.CustomAttributes;
for (int i = 0; i < attributes.Count; i++) {
var attribute = attributes [i];
switch (attribute.Constructor.DeclaringType.FullName) {
case "Java.Interop.ExportAttribute":
Annotations.Mark (provider);
if (!attribute.HasProperties)
break;
var throwsAtt = attribute.Properties.FirstOrDefault (p => p.Name == "Throws");
var thrownTypesArgs = throwsAtt.Argument.Value != null ? (CustomAttributeArgument []) throwsAtt.Argument.Value : null;
if (thrownTypesArgs != null)
foreach (var attArg in thrownTypesArgs)
Annotations.Mark (((TypeReference) attArg.Value).Resolve ());
break;
case "Java.Interop.ExportFieldAttribute":
Annotations.Mark (provider);
break;
default:
continue;
}
if (provider is MemberReference)
Annotations.Mark (((MemberReference) provider).DeclaringType.Resolve ());
if (provider is MethodDefinition)
Annotations.SetAction (((MethodDefinition) provider), MethodAction.ForceParse);
}
}
示例15: Create
/// <summary>
/// Create annotations for all included attributes
/// </summary>
public static void Create(AssemblyCompiler compiler, ICustomAttributeProvider attributeProvider,
IAnnotationProvider annotationProvider, DexTargetPackage targetPackage, bool customAttributesOnly = false)
{
if (!attributeProvider.HasCustomAttributes)
return;
var annotations = new List<Annotation>();
foreach (var attr in attributeProvider.CustomAttributes)
{
var attributeType = attr.AttributeType.Resolve();
if (!attributeType.HasIgnoreAttribute())
{
Create(compiler, attr, attributeType, annotations, targetPackage);
}
}
if (annotations.Count > 0)
{
// Create 1 IAttributes annotation
var attrsAnnotation = new Annotation { Visibility = AnnotationVisibility.Runtime };
attrsAnnotation.Type = compiler.GetDot42InternalType("IAttributes").GetClassReference(targetPackage);
attrsAnnotation.Arguments.Add(new AnnotationArgument("Attributes", annotations.ToArray()));
annotationProvider.Annotations.Add(attrsAnnotation);
}
if (!customAttributesOnly)
{
// Add annotations specified using AnnotationAttribute
foreach (var attr in attributeProvider.CustomAttributes.Where(IsAnnotationAttribute))
{
var annotationType = (TypeReference) attr.ConstructorArguments[0].Value;
var annotationClass = annotationType.GetClassReference(targetPackage, compiler.Module);
annotationProvider.Annotations.Add(new Annotation(annotationClass, AnnotationVisibility.Runtime));
}
}
}