コード例 #1
0
        //readonly CecilLoader loader = new CecilLoader();

        public string GetTypeNameForAttribute(NRefactory.CSharp.Attribute attribute)
        {
            return(attribute.Type.Annotations
                   .OfType <Mono.Cecil.MemberReference>()
                   .First()
                   .FullName);
        }
コード例 #2
0
        public override object VisitAttribute(NRefactory.CSharp.Attribute attribute, object data)
        {
            var        section = (AttributeSection)attribute.Parent;
            SimpleType type    = attribute.Type as SimpleType;

            if (section.AttributeTarget == AttributeTarget.Assembly &&
                (type.Identifier == "CompilationRelaxations" || type.Identifier == "RuntimeCompatibility"))
            {
                attribute.Remove();
                if (section.Attributes.Count == 0)
                {
                    section.Remove();
                }
            }
            return(null);
        }
コード例 #3
0
        public static void AddNamedArgument(this NRefactory.CSharp.Attribute attribute, ModuleDef module, Type attrType, Type fieldType, string fieldName, Expression argument)
        {
            var ide = new IdentifierExpression(fieldName);

            if (module != null)
            {
                TypeSig sig = module.CorLibTypes.GetCorLibTypeSig(module.Import(fieldType));
                if (sig == null)
                {
                    var typeRef = module.CorLibTypes.GetTypeRef(fieldType.Namespace, fieldType.Name);
                    sig = fieldType.IsValueType ? (TypeSig) new ValueTypeSig(typeRef) : new ClassSig(typeRef);
                }
                var fr = new MemberRefUser(module, fieldName, new FieldSig(sig), module.CorLibTypes.GetTypeRef(attrType.Namespace, attrType.Name));
                ide.AddAnnotation(fr);
                ide.IdentifierToken.AddAnnotation(fr);
            }

            attribute.Arguments.Add(new AssignmentExpression(ide, argument));
        }
コード例 #4
0
        public override object VisitAttribute(NRefactory.CSharp.Attribute attribute, object data)
        {
            var        section = (AttributeSection)attribute.Parent;
            SimpleType type    = attribute.Type as SimpleType;

            if (section.AttributeTarget == "assembly" &&
                (type.Identifier == "CompilationRelaxations" || type.Identifier == "RuntimeCompatibility" || type.Identifier == "SecurityPermission" || type.Identifier == "AssemblyVersion"))
            {
                attribute.Remove();
                if (section.Attributes.Count == 0)
                {
                    section.Remove();
                }
            }
            if (section.AttributeTarget == "module" && type.Identifier == "UnverifiableCode")
            {
                attribute.Remove();
                if (section.Attributes.Count == 0)
                {
                    section.Remove();
                }
            }
            return(null);
        }
コード例 #5
0
 public static void AddNamedArgument(this NRefactory.CSharp.Attribute attribute, string name, Expression argument)
 {
     attribute.Arguments.Add(new AssignmentExpression(new IdentifierExpression(name), argument));
 }