Exemplo n.º 1
0
 public static IEnumerable <Attribute> Attrs(this ICustomAttributeProvider cap, Type t)
 {
     if (cap == null)
     {
         return(null);
     }
     return(cap.Attrs(t, true));
 }
Exemplo n.º 2
0
 public static IEnumerable <Attribute> Attrs(this ICustomAttributeProvider cap)
 {
     if (cap == null)
     {
         return(null);
     }
     return(cap.Attrs(typeof(Attribute)));
 }
Exemplo n.º 3
0
 public static Attribute AttrOrNull(this ICustomAttributeProvider cap, Type t, bool inherit)
 {
     if (cap == null)
     {
         return(null);
     }
     return(cap.Attrs(t, inherit).SingleOrDefault());
 }
Exemplo n.º 4
0
 public static IEnumerable <T> Attrs <T>(this ICustomAttributeProvider cap, bool inherit)
     where T : Attribute
 {
     if (cap == null)
     {
         return(null);
     }
     return(cap.Attrs(typeof(T), inherit).Cast <T>());
 }
        public static String GetCSharpAttributesClause(this ICustomAttributeProvider cap, ToCSharpOptions opt)
        {
            if (cap.Attrs().Count() == 0)
            {
                return(String.Empty);
            }
            else
            {
                var buffer = new StringBuilder();
                buffer.Append("[");

                var prefix = String.Empty;
                if (cap is ParameterInfo)
                {
                    /*IsRetVal ain't work */
                    var mb = ((ParameterInfo)cap).Member;
                    if (mb is MethodInfo && ((MethodInfo)(mb)).ReturnParameter == cap)
                    {
                        prefix = "return: ";
                    }
                }

                // todo. implement this using CustomAttributeData
                // that will preserve info about ctor and setters
                var attrs = cap.GetCustomAttributes(false);
                attrs.ForEach((attr, i) =>
                {
                    buffer.Append(prefix);
                    buffer.Append(attr.GetType().GetCSharpRef(opt));
                    if (i != attrs.Count() - 1)
                    {
                        buffer.Append(", ");
                    }
                });

                buffer.Append("]");
                return(buffer.ToString());
            }
        }
Exemplo n.º 6
0
 public static T AttrOrNull <T>(this ICustomAttributeProvider cap, bool inherit)
     where T : Attribute
 {
     return(cap.Attrs <T>().SingleOrDefault());
 }
Exemplo n.º 7
0
 public static IEnumerable <T> Attrs <T>(this ICustomAttributeProvider cap)
     where T : Attribute
 {
     return(cap.Attrs <T>(true));
 }
Exemplo n.º 8
0
 public static Attribute Attr(this ICustomAttributeProvider cap, Type t, bool inherit)
 {
     (cap != null).AssertTrue();
     return(cap.Attrs(t, inherit).Single());
 }