Пример #1
0
        static void AddMethodToTypeDeclaration(CodeTypeDeclaration typeDeclaration, MethodDefinition member, AttributeFilter attributeFilter)
        {
            var attributes = member.GetMethodAttributes();

            if (!ShouldIncludeMember(attributes))
            {
                return;
            }

            if (member.IsSpecialName && !member.Name.StartsWith("op_"))
            {
                return;
            }

            var returnType = member.ReturnType.CreateCodeTypeReference(member.MethodReturnType);

            if (member.ReturnType.IsUnsafeSignatureType() || member.Parameters.Any(p => p.ParameterType.IsUnsafeSignatureType()))
            {
                returnType = returnType.MakeUnsafe();
            }

            var method = new CodeMemberMethod
            {
                Name             = CSharpOperatorKeyword.Get(member.Name),
                Attributes       = attributes,
                CustomAttributes = CreateCustomAttributes(member, attributeFilter),
                ReturnType       = returnType,
            };

            PopulateCustomAttributes(member.MethodReturnType, method.ReturnTypeCustomAttributes, attributeFilter);
            PopulateGenericParameters(member, method.TypeParameters, attributeFilter, _ => true);
            PopulateMethodParameters(member, method.Parameters, attributeFilter, member.IsExtensionMethod());

            typeDeclaration.Members.Add(method);
        }
Пример #2
0
        public static string AugmentMethodNameWithMethodModifierMarkerTemplate(MethodDefinition methodDefinition,
                                                                               MemberAttributes attributes)
        {
            var name = CSharpOperatorKeyword.Get(methodDefinition.Name);

            if (methodDefinition.DeclaringType.IsInterface)
            {
                return(name);
            }

            var isNew = methodDefinition.IsNew(typeDef => typeDef?.Methods, e =>
                                               e.Name.Equals(methodDefinition.Name, StringComparison.Ordinal) &&
                                               e.Parameters.Count == methodDefinition.Parameters.Count &&
                                               e.Parameters.SequenceEqual(methodDefinition.Parameters, new ParameterTypeComparer()));

            return(ModifierMarkerNameBuilder.Build(methodDefinition, attributes, isNew, name,
                                                   CodeNormalizer.MethodModifierMarkerTemplate));
        }