Пример #1
0
        internal static ICodeWriter DoAppendSignature(
            this ICodeWriter @this,
            AccessProtectionOption protection,
            string frontModifier,
            MethodInfo method)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }
            string name = method.Name;

            if (method.ContainsGenericParameters)
            {
                name += '<';
                name += String.Join(",", method.GetGenericArguments().Select(a => a.Name));
                name += '>';
            }
            if (protection != AccessProtectionOption.None)
            {
                @this.AppendAccessProtection(method, protection);
            }
            @this.Append(frontModifier)
            .AppendCSharpName(method.ReturnType, true, true, useValueTupleParentheses: true)
            .Space()
            .Append(name)
            .AppendParameters(method.GetParameters());
            return(@this);
        }
Пример #2
0
 internal static ICodeWriter AppendAccessProtection(this ICodeWriter w, MethodInfo method, AccessProtectionOption p)
 {
     Debug.Assert(p != AccessProtectionOption.None);
     if (p == AccessProtectionOption.ThrowOnPureInternal &&
         (method.IsAssembly || method.IsFamilyAndAssembly))
     {
         throw new ArgumentException($"Method {method} must not be internal.", nameof(method));
     }
     if (method.IsPublic)
     {
         w.Append("public ");
     }
     else if (method.IsFamily)
     {
         w.Append("protected ");
     }
     else if (method.IsAssembly)
     {
         if (p == AccessProtectionOption.All)
         {
             w.Append("internal ");
         }
     }
     else if (method.IsFamilyAndAssembly)
     {
         if (p == AccessProtectionOption.All)
         {
             w.Append("private protected ");
         }
         else
         {
             w.Append("protected ");
         }
     }
     else if (method.IsFamilyOrAssembly)
     {
         if (p == AccessProtectionOption.All)
         {
             w.Append("internal protected ");
         }
         else
         {
             w.Append("protected ");
         }
     }
     return(w);
 }