示例#1
0
        private void CheckAttributeInheritanceAllowMultiple(IMutableMember mutableInfo)
        {
            mutableInfo.AddCustomAttribute(CreateAttribute <InheritableAllowMultipleAttribute> (new object[] { "derived1" }));
            mutableInfo.AddCustomAttribute(CreateAttribute <NonInheritableAllowMultipleAttribute> (new object[] { "derived2" }));

            var filterType       = typeof(AllowMultipleBaseAttribute);
            var actualAttributes = (AllowMultipleBaseAttribute[])mutableInfo.GetCustomAttributes(filterType, true);

            Assert.That(actualAttributes.Select(a => a.CtorArg), Is.EquivalentTo(new[] { "derived1", "derived2", "base1" }));
        }
        public void AddDebuggerBrowsableAttribute(IMutableMember member, DebuggerBrowsableState debuggerBrowsableState)
        {
            ArgumentUtility.CheckNotNull("member", member);

            var attribute = new CustomAttributeDeclaration(s_debuggerBrowsableAttributeConstructor, new object[] { debuggerBrowsableState });

            member.AddCustomAttribute(attribute);
        }
        public void AddConcreteMixinTypeAttribute(IMutableMember member, ConcreteMixinTypeIdentifier concreteMixinTypeIdentifier)
        {
            ArgumentUtility.CheckNotNull("member", member);
            ArgumentUtility.CheckNotNull("concreteMixinTypeIdentifier", concreteMixinTypeIdentifier);

            var attributeData = ConcreteMixinTypeAttribute.Create(concreteMixinTypeIdentifier).ConcreteMixinTypeIdentifierData;
            var attribute     = new CustomAttributeDeclaration(s_concreteMixinTypeAttributeConstructor, new object[] { attributeData });

            member.AddCustomAttribute(attribute);
        }
        public void AddGeneratedMethodWrapperAttribute(IMutableMember member, MethodInfo methodToBeWrapped)
        {
            ArgumentUtility.CheckNotNull("member", member);
            ArgumentUtility.CheckNotNull("methodToBeWrapped", methodToBeWrapped);

            var attribute = new CustomAttributeDeclaration(
                s_generatedMethodWrapperAttributeConstructor,
                new object[] { methodToBeWrapped.DeclaringType, methodToBeWrapped.Name, methodToBeWrapped.ToString() });

            member.AddCustomAttribute(attribute);
        }
        public void AddOverrideInterfaceMappingAttribute(IMutableMember member, MethodInfo overriddenMethod)
        {
            ArgumentUtility.CheckNotNull("member", member);
            ArgumentUtility.CheckNotNull("overriddenMethod", overriddenMethod);

            var attribute = new CustomAttributeDeclaration(
                s_overrideInterfaceMappingAttributeConstructor,
                new object[] { overriddenMethod.DeclaringType, overriddenMethod.Name, overriddenMethod.ToString() });

            member.AddCustomAttribute(attribute);
        }
        public void AddConcreteMixedTypeAttribute(IMutableMember member, ClassContext classContext, IEnumerable <Type> orderedMixinTypes)
        {
            ArgumentUtility.CheckNotNull("member", member);
            ArgumentUtility.CheckNotNull("classContext", classContext);
            ArgumentUtility.CheckNotNull("orderedMixinTypes", orderedMixinTypes);

            var attributeData = ConcreteMixedTypeAttribute.FromClassContext(classContext, orderedMixinTypes.ToArray());
            var attribute     = new CustomAttributeDeclaration(
                s_concreteMixedTypeAttributeConstructor, new object[] { attributeData.ClassContextData, attributeData.OrderedMixinTypes });

            member.AddCustomAttribute(attribute);
        }
        public void AddIntroducedMemberAttribute(IMutableMember member, MemberInfo interfaceMember, MemberDefinitionBase implementingMember)
        {
            ArgumentUtility.CheckNotNull("member", member);
            ArgumentUtility.CheckNotNull("interfaceMember", interfaceMember);
            ArgumentUtility.CheckNotNull("implementingMember", implementingMember);

            var attribute = new CustomAttributeDeclaration(
                s_introducedMemberAttributeConstructor,
                new object[] { implementingMember.DeclaringClass.Type, implementingMember.Name, interfaceMember.DeclaringType, interfaceMember.Name });

            member.AddCustomAttribute(attribute);
        }
        public void AddAttribute(IMutableMember member, ICustomAttributeData attributeData)
        {
            ArgumentUtility.CheckNotNull("member", member);
            ArgumentUtility.CheckNotNull("attributeData", attributeData);

            var attribute = new CustomAttributeDeclaration(
                attributeData.Constructor,
                attributeData.ConstructorArguments.ToArray(),
                attributeData.NamedArguments.Select(CreateNamedArgumentDeclaration).ToArray());

            member.AddCustomAttribute(attribute);
        }
        public void AddDebuggerDisplayAttribute(IMutableMember member, string debuggerDisplayString, string debuggerDisplayNameStringOrNull)
        {
            ArgumentUtility.CheckNotNull("member", member);
            ArgumentUtility.CheckNotNullOrEmpty("debuggerDisplayString", debuggerDisplayString);
            // Debugger display name may be null.

            var attribute = new CustomAttributeDeclaration(
                s_debuggerDisplayAttributeConstructor,
                new object[] { debuggerDisplayString },
                new NamedArgumentDeclaration(s_debuggerDisplayAttributeNameProperty, debuggerDisplayNameStringOrNull));

            member.AddCustomAttribute(attribute);
        }