示例#1
0
        internal static void TryAddCompilerGeneratedAttribute(Member member, System.AttributeTargets targets)
        {
            Contract.Requires(member != null);

            if (HelperMethods.compilerGeneratedAttributeNode == null)
            {
                return;
            }
            Member        compilerGenerated          = HelperMethods.compilerGeneratedAttributeNode.GetConstructor();
            AttributeNode compilerGeneratedAttribute = new AttributeNode(new MemberBinding(null, compilerGenerated), null, targets);

            member.Attributes.Add(compilerGeneratedAttribute);
        }
示例#2
0
        IEnumerable <KeyValuePair <T, TX> > GetAllAttributes <T, TX>(System.AttributeTargets pTarget, System.Type pBaseType = null) where T : System.Attribute where TX : class
        {
            bool searchClass    = (pTarget & System.AttributeTargets.Class) == System.AttributeTargets.Class;
            bool searchStruct   = (pTarget & System.AttributeTargets.Struct) == System.AttributeTargets.Struct;
            bool searchProperty = (pTarget & System.AttributeTargets.Property) == System.AttributeTargets.Property;
            bool searchField    = (pTarget & System.AttributeTargets.Field) == System.AttributeTargets.Field;

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var t in assembly.GetTypes())
                {
                    if (t.IsClass && searchClass || searchStruct)
                    {
                        foreach (var attribute in t.GetCustomAttributes(typeof(T), true))
                        {
                            yield return(new KeyValuePair <T, TX>(attribute as T, t as TX));
                        }
                    }

                    if (t.IsClass && t == pBaseType)
                    {
                        if (searchField)
                        {
                            foreach (var field in t.GetFields())
                            {
                                foreach (var attribute in field.GetCustomAttributes(typeof(T), true))
                                {
                                    yield return(new KeyValuePair <T, TX>(attribute as T, field as TX));
                                }
                            }
                        }
                        if (searchProperty)
                        {
                            foreach (var property in t.GetProperties())
                            {
                                foreach (var attribute in property.GetCustomAttributes(typeof(T), true))
                                {
                                    yield return(new KeyValuePair <T, TX>(attribute as T, property as TX));
                                }
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        internal static void TryAddDebuggerBrowsableNeverAttribute(Member member, System.AttributeTargets targets)
        {
            Contract.Requires(member != null);

            try
            {
                if (HelperMethods.debuggerBrowsableAttributeNode == null)
                {
                    return;
                }
                if (HelperMethods.debuggerBrowsableStateType == null)
                {
                    return;
                }
                var ctor      = HelperMethods.debuggerBrowsableAttributeNode.GetConstructor(HelperMethods.debuggerBrowsableStateType);
                var args      = new ExpressionList(Literal.Int32Zero);
                var attribute = new AttributeNode(new MemberBinding(null, ctor), args, targets);
                member.Attributes.Add(attribute);
            }
            catch
            { }
        }
示例#4
0
 public KeywordPair(CS.SyntaxKind cs, VB.SyntaxKind vb, System.AttributeTargets target = AttributeTargets.All)
 {
     CS = cs;
     VB = vb;
     Targets = target;
 }
示例#5
0
 public void TestWithEnumAsArgument(System.AttributeTargets targets)
 {
 }
示例#6
0
 public BreakPair(CS.SyntaxKind cs, VB.SyntaxKind vb, VB.SyntaxKind exitTargetKeyword, System.AttributeTargets target = AttributeTargets.All)
     : base(cs, vb, target)
 {
     this.ExitTargetKeyword = exitTargetKeyword;
 }