예제 #1
0
        public bool HasAttribute(MetadataReader reader, CustomAttributeHandleCollection attrHandles, string attributeFullName)
        {
            if (!_attributeConstructors.TryGetValue(attributeFullName, out var constructorSet))
            {
                constructorSet = new HashSet <EntityHandle>();
                _attributeConstructors[attributeFullName] = constructorSet;
            }

            var attrs = attrHandles.Select(reader.GetCustomAttribute).ToList();

            if (attrs.Any(attr => constructorSet.Contains(attr.Constructor)))
            {
                return(true);
            }

            var compilerGeneratedAttr = attrs
                                        .Where(attr => reader.GetFullname(reader.GetCustomAttrClass(attr)) == attributeFullName)
                                        .Select(attr => (CustomAttribute?)attr)
                                        .FirstOrDefault();

            if (compilerGeneratedAttr == null)
            {
                return(false);
            }

            constructorSet.Add(compilerGeneratedAttr.Value.Constructor);
            return(true);
        }
예제 #2
0
 public static string ToString(this MetadataReader reader, CustomAttribute x) => $"{{CustomAttr[{RowId(x):X}]: {reader.ToString( reader.GetCustomAttrClass(x))} {reader.ToString( x.Parent)}}}";
예제 #3
0
파일: MetaUtil.cs 프로젝트: saul/Refasmer
 public static EntityHandle GetCustomAttrClass(this MetadataReader reader, CustomAttributeHandle attrHandle) =>
 reader.GetCustomAttrClass(reader.GetCustomAttribute(attrHandle));