Esempio n. 1
0
        public static string GetSubjectString(this IMetadataEntity type)
        {
            var attributes = type.GetCustomAttributes(typeof(SubjectAttribute).FullName);

            if (attributes.Count != 1)
            {
                return(null);
            }

            var attribute = attributes.First();

            var parameters = attribute.ConstructorArguments.Select(x =>
            {
                var typeArgument = x as IMetadataClassType;
                if (typeArgument != null)
                {
                    return(new CLRTypeName(typeArgument.Type.FullyQualifiedName).ShortName);
                }

                return((string)x);
            })
                             .ToArray();

            return(String.Join(" ", parameters));
        }
Esempio n. 2
0
        public static MetadataToken ResolveToken(IMetadataEntity entity, MetadataBuilder builder)
        {
            var resolver = new MetadataTokenResolver(builder);

            entity.Accept(resolver);
            return(resolver._token);
        }
Esempio n. 3
0
        private static string GetExplicitString(IMetadataEntity entity)
        {
            IList <IMetadataCustomAttribute> attributes = entity.GetCustomAttributes(IgnoreAttribute.ClrName);
            string reason = null;

            for (int i = 0; i < attributes.Count; i++)
            {
                object[] arguments = attributes[i].ConstructorArguments;
                if (arguments.Length == 1)
                {
                    var r = arguments[0] as string;
                    if (r == null)
                    {
                        if (reason == null)
                        {
                            reason = "";
                        }
                    }
                    else
                    {
                        reason = r;
                    }
                }
                else
                {
                    if (reason == null)
                    {
                        reason = "";
                    }
                }
            }
            return(reason);
        }
Esempio n. 4
0
 private static IList <IMetadataCustomAttribute> GetSubjectAttributes(IMetadataEntity type)
 {
     return(type.CustomAttributes
            .Where(attribute => attribute.AndAllBaseTypes()
                   .Any(i => i.FullyQualifiedName == typeof(SubjectAttribute).FullName))
            .ToList());
 }
Esempio n. 5
0
 internal CliMetadataCollection(IControlledCollection <ICliMetadataCustomAttributeTableRow> sourceData, IMetadataEntity declarationPoint, _ICliManager identityManager)
 {
     this.declarationPoint = declarationPoint;
     this.sourceData       = sourceData;
     this.metadataSet      = new IMetadatum[this.Count];
     this.identityManager  = identityManager;
 }
Esempio n. 6
0
        static IEnumerable <IMetadataTypeInfo> AndAllBaseTypes(this IMetadataEntity type)
        {
            Func <IMetadataEntity, IMetadataTypeInfo> getTypeFromAttributeConstructor = entity =>
            {
                var attr = type as IMetadataCustomAttribute;
                if (attr == null)
                {
                    return(null);
                }

                return(attr.UsedConstructor.DeclaringType);
            };

            var typeInfo = type as IMetadataTypeInfo;

            if (typeInfo == null)
            {
                // type might be an attribute - which cannot be cast as IMetadataTypeInfo.
                typeInfo = getTypeFromAttributeConstructor(type);
                if (typeInfo == null)
                {
                    // No idea how the get the type of the IMetadataEntity.
                    yield break;
                }
            }

            yield return(typeInfo);

            while (typeInfo.Base != null && typeInfo.Base.Type != null)
            {
                yield return(typeInfo.Base.Type);

                typeInfo = typeInfo.Base.Type;
            }
        }
Esempio n. 7
0
        public static string GetSubjectString(this IMetadataEntity type)
        {
            var attributes = GetSubjectAttributes(type);

            if (attributes.Count != 1)
            {
                var asMember = type as IMetadataTypeMember;
                if (asMember != null && asMember.DeclaringType != null)
                {
                    return(asMember.DeclaringType.GetSubjectString());
                }
                return(null);
            }

            var attribute = attributes.First();

            var parameters = attribute.ConstructorArguments.Select(x =>
            {
                var typeArgument = x.Value as IMetadataClassType;
                if (typeArgument != null)
                {
                    return(new ClrTypeName(typeArgument.Type.FullyQualifiedName).ShortName);
                }

                return((string)x.Value);
            }).ToArray();

            return(String.Join(" ", parameters));
        }
Esempio n. 8
0
 public CliMetadatum(ICliMetadataCustomAttributeTableRow metadataEntry, _ICliAssembly owner)
 {
     this.declarationPoint = owner;
     this.metadataEntry    = metadataEntry;
     this.identityManager  = owner.IdentityManager;
     this.parameters       = new Lazy <IEnumerable <MetadatumTypedParameter> >(() => this.GetParameters().SinglePass(), true);
     this.namedParameters  = new Lazy <IEnumerable <MetadatumNamedParameter> >(() => this.GetNamedParameters().SinglePass(), true);;
 }
Esempio n. 9
0
 public static ICollection <string> GetTags(this IMetadataEntity type)
 {
     return(type.AndAllBaseTypes()
            .SelectMany(x => x.GetCustomAttributes(typeof(TagsAttribute).FullName))
            .Select(x => x.ConstructorArguments)
            .Flatten(tag => tag.FirstOrDefault().Value as string,
                     tag => tag.Skip(1).FirstOrDefault().ValuesArray.Select(v => v.Value as string))
            .Distinct()
            .ToList());
 }
		new public int Add(IMetadataEntity val) {
			if (this._owningMetadataFile != null) {
				val.OwningMetadataFile = this._owningMetadataFile;
			}
			if ( !this.Contains(val) ) {
				return base.Add(val);
			}
			else {
				return -1;
			}
		}
Esempio n. 11
0
 public static bool StandardIsDefined(this IMetadataEntity target, IType metadatumType)
 {
     foreach (IMetadatum inst in target.Metadata)
     {
         if (metadatumType.IsAssignableFrom(inst.Type))
         {
             return(true);
         }
     }
     return(false);
 }
        private static IList <IMetadataCustomAttribute> GetSubjectAttributes(IMetadataEntity metadataEntity, SubjectAttributeFullName subjectAttributeFullName)
        {
            var derivedAndBaseTypes = metadataEntity.AndAllBaseTypes();

            foreach (var type in derivedAndBaseTypes)
            {
                var attributes = type.CustomAttributes.ToList().Where(x => x.GetCustomAttributes(subjectAttributeFullName) != null);
                if (attributes.Any())
                {
                    return(attributes.ToList());
                }
            }

            return(new List <IMetadataCustomAttribute>());
        }
        static IEnumerable <IMetadataTypeInfo> AndAllBaseTypes(this IMetadataEntity type)
        {
            var typeInfo = type as IMetadataTypeInfo;

            if (typeInfo == null)
            {
                yield break;
            }

            yield return(typeInfo);

            while (typeInfo.Base != null && typeInfo.Base.Type != null)
            {
                yield return(typeInfo.Base.Type);

                typeInfo = typeInfo.Base.Type;
            }
        }
        public static string GetSubjectString(this IMetadataEntity type)
        {
            var attributes = GetSubjectAttributes(type);

            if (attributes.Count != 1)
            {
                var asMember = type as IMetadataTypeMember;
                if (asMember != null && asMember.DeclaringType != null)
                {
                    return(asMember.DeclaringType.GetSubjectString());
                }

                return(null);
            }

            IMetadataCustomAttribute attribute = attributes.First();

            string[] parameterNames = attribute.ConstructorArguments.Select(GetParameterName).ToArray();

            return(string.Join(" ", parameterNames));
        }
		/// <summary>
		/// <para>Copies the <see cref='MetadataEntityCollection'/> values to a one-dimensional <see cref='System.Array'/> instance at the 
		///    specified index.</para>
		/// </summary>
		/// <param name='array'><para>The one-dimensional <see cref='System.Array'/> that is the destination of the values copied from <see cref='MetadataEntityCollection'/> .</para></param>
		/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
		/// <returns>
		///   <para>None.</para>
		/// </returns>
		/// <exception cref='System.ArgumentException'><para><paramref name='array'/> is multidimensional.</para> <para>-or-</para> <para>The number of elements in the <see cref='MetadataEntityCollection'/> is greater than the available space between <paramref name='arrayIndex'/> and the end of <paramref name='array'/>.</para></exception>
		/// <exception cref='System.ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
		/// <exception cref='System.ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
		/// <seealso cref='System.Array'/>
		public void CopyTo(IMetadataEntity[] array, int index)
		{
			List.CopyTo(array, index);
		}
Esempio n. 16
0
 public bool Equals(IMetadataEntity other)
 {
     return((other is MethodReference) && Equals((MethodReference)other));
 }
Esempio n. 17
0
 private static string GetExplicitString(IMetadataEntity entity)
 {
     return(string.Empty);
 }
Esempio n. 18
0
 public bool Equals(IMetadataEntity other)
 {
     return((other is AssemblyReference) && Equals((AssemblyReference)other));
 }
		/// <summary>
		///    <para> Removes a specific <see cref='IMetadataEntity'/> from the 
		///    <see cref='MetadataEntityCollection'/> .</para>
		/// </summary>
		/// <param name='value'>The <see cref='IMetadataEntity'/> to remove from the <see cref='MetadataEntityCollection'/> .</param>
		/// <returns><para>None.</para></returns>
		/// <exception cref='System.ArgumentException'><paramref name='value'/> is not found in the Collection. </exception>
		public void Remove(IMetadataEntity val)
		{
			List.Remove(val);
		}
Esempio n. 20
0
 public IMetadataCustomAttribute GetAttributeData <T> (IMetadataEntity entity) where T : Attribute
 {
     return(GetAttributeDatas <T>(entity).SingleOrDefault());
 }
		new public void Remove(IMetadataEntity val) {
			base.Remove(val);
		}
Esempio n. 22
0
 public static bool IsIgnored(this IMetadataEntity type)
 {
     return(type.HasCustomAttribute(typeof(IgnoreAttribute).FullName));
 }
Esempio n. 23
0
 public bool Equals(IMetadataEntity other)
 {
     return((other is MethodDefinition) && Equals((MethodDefinition)other));
 }
Esempio n. 24
0
 public void Dispose()
 {
     this.parent = null;
 }
		/// <summary>
		///    <para>Returns the index of a <see cref='IMetadataEntity'/> in 
		///       the <see cref='MetadataEntityCollection'/> .</para>
		/// </summary>
		/// <param name='value'>The <see cref='IMetadataEntity'/> to locate.</param>
		/// <returns>
		/// <para>The index of the <see cref='IMetadataEntity'/> of <paramref name='value'/> in the 
		/// <see cref='MetadataEntityCollection'/>, if found; otherwise, -1.</para>
		/// </returns>
		/// <seealso cref='MetadataEntityCollection.Contains'/>
		public int IndexOf(IMetadataEntity val)
		{
			return List.IndexOf(val);
		}
Esempio n. 26
0
 public bool Equals(IMetadataEntity other)
 {
     return((other is ITypeInfo) && Equals((ITypeInfo)other));
 }
 public static IMetadataCustomAttribute GetAttributeData(this IMetadataEntity entity, string attributeType)
 {
     return(AttributeDataUtility.Instance.GetAttributeData(entity, attributeType));
 }
		/// <summary>
		/// <para>Inserts a <see cref='IMetadataEntity'/> into the <see cref='MetadataEntityCollection'/> at the specified index.</para>
		/// </summary>
		/// <param name='index'>The zero-based index where <paramref name='value'/> should be inserted.</param>
		/// <param name=' value'>The <see cref='IMetadataEntity'/> to insert.</param>
		/// <returns><para>None.</para></returns>
		/// <seealso cref='MetadataEntityCollection.Add'/>
		public void Insert(int index, IMetadataEntity val)
		{
			List.Insert(index, val);
		}
		new public void Insert(int index, IMetadataEntity val) {
			if (this._owningMetadataFile != null) {
				val.OwningMetadataFile = this._owningMetadataFile;
			}
			if ( this.Contains(val) ) {
				base.Remove(val);
			}
			base.Insert(index, val);
		}
Esempio n. 30
0
 public CustomAttributeCollection(IMetadataEntity parent)
     : base()
 {
     this.parent = parent;
 }
		/// <summary>
		/// <para>Copies the elements of an array to the end of the <see cref='MetadataEntityCollection'/>.</para>
		/// </summary>
		/// <param name='value'>
		///    An array of type <see cref='IMetadataEntity'/> containing the objects to add to the collection.
		/// </param>
		/// <returns>
		///   <para>None.</para>
		/// </returns>
		/// <seealso cref='MetadataEntityCollection.Add'/>
		public void AddRange(IMetadataEntity[] val)
		{
			for (int i = 0; i < val.Length; i++) {
				this.Add(val[i]);
			}
		}
Esempio n. 32
0
 public bool Equals(IMetadataEntity other)
 {
     return((other is StandAloneSignature) && base.Equals((StandAloneSignature)other));
 }
 private static IList <IMetadataCustomAttribute> GetSubjectAttributes(IMetadataEntity metadataEntity)
 {
     return(metadataEntity.AndAllBaseTypes()
            .SelectMany(x => x.GetCustomAttributes(FullNames.SubjectAttribute))
            .ToList());
 }
		/// <summary>
		/// <para>Gets a value indicating whether the 
		///    <see cref='MetadataEntityCollection'/> contains the specified <see cref='IMetadataEntity'/>.</para>
		/// </summary>
		/// <param name='value'>The <see cref='IMetadataEntity'/> to locate.</param>
		/// <returns>
		/// <para><see langword='true'/> if the <see cref='IMetadataEntity'/> is contained in the collection; 
		///   otherwise, <see langword='false'/>.</para>
		/// </returns>
		/// <seealso cref='MetadataEntityCollection.IndexOf'/>
		public bool Contains(IMetadataEntity val)
		{
			return List.Contains(val);
		}
Esempio n. 35
0
 public IEnumerable <IMetadataCustomAttribute> GetAttributeDatas <T> (IMetadataEntity entity) where T : Attribute
 {
     return(entity.CustomAttributes.Where(x => x.UsedConstructor.DeclaringType.Implements(typeof(T))));
 }
Esempio n. 36
0
 public bool Equals(IMetadataEntity other)
 {
     return((other is CustomAttribute) && Equals((CustomAttribute)other));
 }
		/// <summary>
		///     <para>
		///       Initializes a new instance of <see cref='MetadataEntityCollection'/> containing any array of <see cref='IMetadataEntity'/> objects.
		///    </para>
		/// </summary>
		/// <param name='value'>
		///       A array of <see cref='IMetadataEntity'/> objects with which to intialize the collection
		/// </param>
		public MetadataEntityCollection(IMetadataEntity[] val)
		{
			this.AddRange(val);
		}
Esempio n. 38
0
 protected MetadataEntityBase(IMetadataEntity metadataEntity)
 {
     _metadataEntity = metadataEntity;
 }
Esempio n. 39
0
 public bool Equals(IMetadataEntity other)
 {
     return(_metadataEntity.Equals(other));
 }
Esempio n. 40
0
 public bool Equals(IMetadataEntity other)
 {
     return((other is TypeReference) && Equals((TypeReference)other));
 }
		/// <summary>
		///    <para>Adds a <see cref='IMetadataEntity'/> with the specified value to the 
		///    <see cref='MetadataEntityCollection'/> .</para>
		/// </summary>
		/// <param name='value'>The <see cref='IMetadataEntity'/> to add.</param>
		/// <returns>
		///    <para>The index at which the new element was inserted.</para>
		/// </returns>
		/// <seealso cref='MetadataEntityCollection.AddRange'/>
		public int Add(IMetadataEntity val)
		{
			return List.Add(val);
		}