Exemple #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));
        }
Exemple #2
0
        public static MetadataToken ResolveToken(IMetadataEntity entity, MetadataBuilder builder)
        {
            var resolver = new MetadataTokenResolver(builder);

            entity.Accept(resolver);
            return(resolver._token);
        }
Exemple #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);
        }
Exemple #4
0
 private static IList <IMetadataCustomAttribute> GetSubjectAttributes(IMetadataEntity type)
 {
     return(type.CustomAttributes
            .Where(attribute => attribute.AndAllBaseTypes()
                   .Any(i => i.FullyQualifiedName == typeof(SubjectAttribute).FullName))
            .ToList());
 }
Exemple #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;
 }
Exemple #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;
            }
        }
Exemple #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));
        }
Exemple #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);;
 }
Exemple #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;
			}
		}
Exemple #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);
		}
 public bool Equals(IMetadataEntity other)
 {
     return((other is MethodReference) && Equals((MethodReference)other));
 }
Exemple #17
0
 private static string GetExplicitString(IMetadataEntity entity)
 {
     return(string.Empty);
 }
Exemple #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);
		}
Exemple #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);
		}
Exemple #22
0
 public static bool IsIgnored(this IMetadataEntity type)
 {
     return(type.HasCustomAttribute(typeof(IgnoreAttribute).FullName));
 }
Exemple #23
0
 public bool Equals(IMetadataEntity other)
 {
     return((other is MethodDefinition) && Equals((MethodDefinition)other));
 }
Exemple #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);
		}
 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);
		}
Exemple #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]);
			}
		}
Exemple #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);
		}
Exemple #35
0
 public IEnumerable <IMetadataCustomAttribute> GetAttributeDatas <T> (IMetadataEntity entity) where T : Attribute
 {
     return(entity.CustomAttributes.Where(x => x.UsedConstructor.DeclaringType.Implements(typeof(T))));
 }
Exemple #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);
		}
Exemple #38
0
 protected MetadataEntityBase(IMetadataEntity metadataEntity)
 {
     _metadataEntity = metadataEntity;
 }
Exemple #39
0
 public bool Equals(IMetadataEntity other)
 {
     return(_metadataEntity.Equals(other));
 }
 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);
		}