public static List<Type> GetListOfKnownTypes(ICustomAttributeProvider provider)
        {
            List<Type> knownTypes = new List<Type>();

            Type interLinqQuery = typeof(InterLinqQuery<>);
            Type genericList = typeof(List<>);

            List<Type> coreTypes = new List<Type>
            {
                typeof(Customer),
                typeof(Order),
                typeof(Product),
                typeof(Supplier),
            };

            coreTypes.ForEach(type =>
                {
                    knownTypes.Add(type);

                    knownTypes.Add(interLinqQuery.MakeGenericType(type));

                    knownTypes.Add(type.MakeArrayType());
                }
            );

            return knownTypes;
        }
        public static JsonRpcHelpAttribute Get(ICustomAttributeProvider attributeProvider)
        {
            if (attributeProvider == null)
                return null;

            return (JsonRpcHelpAttribute) CustomAttribute.Get(attributeProvider, typeof(JsonRpcHelpAttribute));
        }
Example #3
0
 /// <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));
         }
     }
 }
Example #4
0
 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;
 }
        public static bool IsValidParameter(Type type, ICustomAttributeProvider attributeProvider, bool allowReferences)        
        {

            object[] attributes = System.ServiceModel.Description.ServiceReflector.GetCustomAttributes(attributeProvider, typeof(MarshalAsAttribute), true);

            foreach (MarshalAsAttribute attr in attributes)
            {
                UnmanagedType marshalAs = attr.Value;

                if (marshalAs == UnmanagedType.IDispatch ||
                    marshalAs == UnmanagedType.Interface ||
                    marshalAs == UnmanagedType.IUnknown)
                {
                    return allowReferences;
                }
            }

            XsdDataContractExporter exporter = new XsdDataContractExporter();
            if (!exporter.CanExport(type))
            {
                return false;
            }

            return true;
        }
Example #6
0
 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;
 }
Example #7
0
 /// <summary>
 /// Get attribute of a given type on a member. If multiple attributes
 /// of a type are present, the first one found is returned.
 /// </summary>
 /// <param name="member">The member to examine</param>
 /// <param name="attrName">The FullName of the attribute type to look for</param>
 /// <param name="inherit">True to include inherited attributes</param>
 /// <returns>The attribute or null</returns>
 public static System.Attribute GetAttribute(ICustomAttributeProvider member, string attrName, bool inherit)
 {
     foreach (Attribute attribute in GetAttributes( member, inherit ) )
         if ( IsInstanceOfType( attrName, attribute ) )
             return attribute;
     return null;
 }
 /// <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;
     }
 }
 void AssertDescriptorMatches(ILookup<string, SecurityAttributeDescriptor> descriptors, string signature, ICustomAttributeProvider element)
 {
     if (descriptors.Contains(signature))
         AssertContainsAttribute(element, descriptors[signature].Single().AttributeTypeName);
     else
         AssertContainsNoAttribute(element);
 }
Example #10
0
 public AttributeSet(ICustomAttributeProvider attributeProvider)
 {
     this.attributes = attributeProvider
         .GetCustomAttributes(true)
         .Cast<Attribute>()
         .ToArray();
 }
		internal TemplateBuilder (ICustomAttributeProvider prov)
		{
			object[] ats = prov.GetCustomAttributes (typeof(TemplateContainerAttribute), true);
			if (ats.Length > 0) {
				containerAttribute = (TemplateContainerAttribute) ats [0];
			}
		}
Example #12
0
 public IEnumerable<ValidationAttribute> GetAttributes(ICustomAttributeProvider attributeProvider)
 {
     return attributeProvider
         .GetAttributes<ValidationAttribute>()
         .Select(attr => container.BuildUp(attr.GetType(), attr))
         .Cast<ValidationAttribute>();
 }
        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));
        }
Example #14
0
        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);
            }
        }
        public static bool IsDefined(ICustomAttributeProvider attributeProvider)
        {
            if (attributeProvider == null)
                return false;

            return CustomAttribute.IsDefined(attributeProvider, typeof(JsonRpcParamsAttribute));
        }
        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;
            }
        }
        public static string GetDescription(ICustomAttributeProvider thing)
        {
            string description = string.Empty;
            thing.ForAttribute<DescriptionAttribute>(att => description = att.Text);

            return description;
        }
        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;
            }
        }
Example #19
0
		/// <summary>
		/// Check presence of attribute of a given type on a member.
		/// </summary>
		/// <param name="member">The member to examine</param>
		/// <param name="attrName">The FullName of the attribute type to look for</param>
		/// <param name="inherit">True to include inherited attributes</param>
		/// <returns>True if the attribute is present</returns>
		public static bool HasAttribute( ICustomAttributeProvider member, string attrName, bool inherit )
		{
			foreach( Attribute attribute in GetAttributes( member, inherit ) )
				if ( IsInstanceOfType( attrName, attribute ) )
					return true;
			return false;
		}
        public void SetUp()
        {
            _attributeProvider = NewTypeDefinition();
            CustomAttributes.ForEach(x => _attributeProvider.CustomAttributes.Add(x));

            _findInCustomAttributes = new FindTypeReferencesInCustomAttributes();
        }
Example #21
0
		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;
			}
		}
Example #22
0
 public virtual void ProcessAttributes(IMetaData metaData, ICustomAttributeProvider attributeProvider)
 {
     foreach(AttributeProcessor processor in AttributeProcessors)
     {
         processor.Process(metaData, attributeProvider, this.Config);
     }
 }
        /// <summary>
        /// Attempts to create a property editor for the given edited data type
        /// from the given editor type.
        /// </summary>
        /// <param name="editedType">The type that is being edited.</param>
        /// <param name="editorType">The editor type.</param>
        /// <param name="attributes">
        /// The attributes that were specified for the type.
        /// </param>
        /// <param name="forceInherit">
        /// Should inheritance behavior be forced? The expected value is false.
        /// </param>
        /// <returns>
        /// A property editor that can edit the given edited type.
        /// </returns>
        public static IPropertyEditor TryCreateEditor(Type editedType, Type editorType, ICustomAttributeProvider attributes, bool forceInherit)
        {
            // If our editor isn't inherited, then we only want to create a
            // specific editor
            var customPropertyEditorAttribute = fsPortableReflection.GetAttribute<CustomPropertyEditorAttribute>(editorType);
            if (!forceInherit && (customPropertyEditorAttribute == null || customPropertyEditorAttribute.Inherit == false)) {
                return TryCreateSpecificEditor(editedType, editedType, editorType, attributes);
            }

            // Otherwise we want to try to create a property editor from any of
            // the edited type's associated types.
            Type baseType = editedType;

            while (baseType != null) {
                IPropertyEditor editor = TryCreateSpecificEditor(baseType, editedType, editorType, attributes);
                if (editor != null) {
                    return editor;
                }

                foreach (Type iface in baseType.GetInterfaces()) {
                    editor = TryCreateSpecificEditor(iface, editedType, editorType, attributes);
                    if (editor != null) {
                        return editor;
                    }
                }

                baseType = baseType.BaseType;
            }

            return null;
        }
Example #24
0
File: Common.cs Project: JuRogn/OA
        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;
        }
Example #25
0
 /// <summary>
 /// Check customer attributes
 /// </summary>
 private void Check(ICustomAttributeProvider provider, string context)
 {
     foreach (var ca in provider.CustomAttributes)
     {
         Check(ca.AttributeType, context);
     }
 }
        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;
        }
		internal static object[] GetPseudoCustomAttributes (ICustomAttributeProvider obj, Type attributeType) {
			object[] pseudoAttrs = null;

			/* FIXME: Add other types */
			if (obj is MonoMethod)
				pseudoAttrs = ((MonoMethod)obj).GetPseudoCustomAttributes ();
			else if (obj is FieldInfo)
				pseudoAttrs = ((FieldInfo)obj).GetPseudoCustomAttributes ();
			else if (obj is ParameterInfo)
				pseudoAttrs = ((ParameterInfo)obj).GetPseudoCustomAttributes ();
			else if (obj is Type)
				pseudoAttrs = ((Type)obj).GetPseudoCustomAttributes ();

			if ((attributeType != null) && (pseudoAttrs != null)) {
				for (int i = 0; i < pseudoAttrs.Length; ++i)
					if (attributeType.IsAssignableFrom (pseudoAttrs [i].GetType ()))
						if (pseudoAttrs.Length == 1)
							return pseudoAttrs;
						else
							return new object [] { pseudoAttrs [i] };
				return new object [0];
			}
			else
				return pseudoAttrs;
		}
 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);
         }
     }
 }
        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);
            }
        }
        public IEnumerable<TypeReference> OfProvider(ICustomAttributeProvider provider)
        {
            if (provider == null)
                throw new ArgumentNullException("provider");

            return provider.CustomAttributes.Select(x => x.AttributeType);
        }