コード例 #1
0
        // TODO: TBD: whether Attribute arguments are necessary...
        // TODO: TBD: could provide as a set of string-factory methods?
        // TODO: TBD: or as a dictionary of string name/value pairs where property completion is desired...
        // TODO: TBD: for now we will assume simple parameter-/property-less attributes...
        /// <summary>
        /// Renders the <paramref name="type"/> given the <paramref name="options"/>.
        /// Defaults to <see cref="DefaultOptions"/> when Null.
        /// </summary>
        /// <param name="obj">Not used except as an extension method anchor.</param>
        /// <param name="options">Allowable Options are <see cref="shorthand"/>
        /// (<see cref="bool"/>) and <see cref="full_name"/> (<see cref="bool"/>).</param>
        /// <returns></returns>
        /// <see cref="AttributeName"/>
        /// <see cref="OpenSquareBracket"/>
        /// <see cref="CloseSquareBracket"/>
        /// <see cref="shorthand"/>
        /// <see cref="full_name"/>
        /// <see cref="bool"/>
        public static string RenderAttributeNotation(this object obj, Type type, IAttributeRenderingOptionDictionary options = null)
        {
            options = options ?? DefaultOptions;

            // TODO: TBD: if we are doing this, it might make sense to formalize an interface/concrete implementation with the same properties...
            // Form an anonymous type Options out of the Ad-Hoc Dictionary for local use.
            var o = new
            {
                UseShorthand = options.TryGetValue(shorthand, out var x) && (bool)x,  // default: false
                UseFullName  = !options.TryGetValue(full_name, out var y) || (bool)y, // default: true
                AsAssembly   = options.TryGetValue(assembly, out var z) && (bool)z    // default: false
            };

            // ReSharper disable once ImplicitlyCapturedClosure
            string RenderAsAssembly() => o.AsAssembly ? $"{nameof(assembly)}{Colon} " : Empty;

            string RenderFullName() => o.UseFullName ? type.FullName : type.Name;

            string Render(string name)
            => name == AttributeName
                    ? AttributeName
                    : o.UseShorthand && type.Name.EndsWith(AttributeName)
                        ? name.Substring(0, name.Length - AttributeName.Length)
                        : name;

            // TODO: TBD: for instance, might capture "square brackets" as an Option...
            // TODO: TBD: for example, [Attribute1, Attribute2, ..., AttributeN] is perfectly fine...
            return(Join($"{RenderAsAssembly()}{Render(RenderFullName())}", $"{OpenSquareBracket}", $"{CloseSquareBracket}"));
        }
コード例 #2
0
        public virtual void AddInterfaceAnnotation<TAttribute>(ModuleKind module, IAttributeRenderingOptionDictionary options = null)
            where TAttribute : Attribute
        {
            var fileName = GetFileName(module);

            if (IsNullOrEmpty(fileName))
            {
                return;
            }

            // TODO: TBD: I dare say we might even be able to leverage regular expressions here...
            TryInfluenceAttributeAnnotation(fileName, s => s.Replace(PublicPartialInterface
                , $"{this.RenderAttributeNotation<TAttribute>(options)}{CarriageReturnLineFeed}    {PublicPartialInterface}"));
        }
コード例 #3
0
        public virtual void AddAssemblyAnnotation<TAttribute>(ModuleKind module, IAttributeRenderingOptionDictionary options = null)
            where TAttribute : Attribute
        {
            var fileName = GetFileName(module);

            if (IsNullOrEmpty(fileName))
            {
                return;
            }

            // ReSharper disable once RedundantEmptyObjectOrCollectionInitializer
            options = options ?? new AttributeRenderingOptionDictionary { };

            // Ensures that Rendering occurs WithAssemblyAttribute or rather AsAssemblyAttribute.
            options[assembly] = true;

            TryInfluenceAttributeAnnotation(fileName
                , s => $"{s}{this.RenderAttributeNotation<TAttribute>(options)}{CarriageReturnLineFeed}");
        }
コード例 #4
0
        };                                                                                                        // the defaults

        // TODO: TBD: might consider specifying Rendering Options...
        /// <summary>
        /// Renders the <typeparamref name="TAttribute"/> given the <paramref name="options"/>.
        /// Defaults to <see cref="DefaultOptions"/> when Null.
        /// </summary>
        /// <typeparam name="TAttribute"></typeparam>
        /// <param name="obj">Not used except as an extension method anchor.</param>
        /// <param name="options">Allowable Options are <see cref="shorthand"/>
        /// (<see cref="bool"/>) and <see cref="full_name"/> (<see cref="bool"/>).</param>
        /// <returns></returns>
        /// <see cref="AttributeName"/>
        /// <see cref="OpenSquareBracket"/>
        /// <see cref="CloseSquareBracket"/>
        /// <see cref="RenderAttributeNotation(object,Type,IAttributeRenderingOptionDictionary)"/>
        /// <see cref="shorthand"/>
        /// <see cref="full_name"/>
        /// <see cref="bool"/>
        public static string RenderAttributeNotation <TAttribute>(this object obj, IAttributeRenderingOptionDictionary options = null)
            where TAttribute : Attribute
        => RenderAttributeNotation(obj, typeof(TAttribute), options);
コード例 #5
0
 public virtual bool TryAddClassAnnotation <TAttribute>(string s, out string text, IAttributeRenderingOptionDictionary options = null)
     where TAttribute : Attribute
 => TryInfluenceAttributeAnnotation(s, out text
                                    , x => x.Replace(PublicPartialClass
                                                     , $"{this.RenderAttributeNotation<TAttribute>(options)}{CarriageReturnLineFeed}    {PublicPartialClass}"));