_Samples/Example_Extensions_Macros.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;
using System.Data.Common;
using System.Security.Cryptography;
using System.Security.Principal;

using ComLib;
using ComLib.Macros;
using ComLib.Application;
using ComLib.Extensions;


namespace ComLib.Samples
{
    /// <summary>
    /// Example of Macro component to interpret macros or command in text, much like wordpress shortcodes.
    /// </summary>
    public class Example_Extensions_Macros : App
    {
        private string _macroSampleText1 = @"Local news for $[today format=""MM//dd//yyyy""/] with NY Times.";
        private string _macroSampleText2 = @"Saying $[helloworld language=""en""]Some more greeting here.[/helloworld]";

        /// <summary>
        /// Run the application.
        /// </summary>
        public override BoolMessageItem Execute()
        {
            // 1. Macro service loads classes with attribute "MacroAttribute" and of type IMacro.
            var macros = new MacroService();

            // 2. Register Option 1: Load macro extensions from dll "CommonLibrary"            
            macros.Load("CommonLibrary");

            // 3. Register Option 2: Programmactically with macro attributes.       
            macros.Register(new MacroAttribute(){ Name = "helloworld" },
                            new MacroParameterAttribute[] { new MacroParameterAttribute() { Name = "language" } },
                           (tag) => "hello world using tag: " + tag.Name + ", " + tag.InnerContent );

            // 3. Register Option 3: Programmactically with simple api.
            macros.Register("helloworld2", "", "Simple hello world macro", (tag) => "hello world 2 : "); 
            
            
            // 4. Now build the content by processing the macros
            var content = macros.BuildContent(_macroSampleText1);

            // 5. Render content that has a lamda based macro in it.
            // NOTE: Render content that has multiple macros involves the same method call.
            var content2 = macros.BuildContent(_macroSampleText2);
            
            
            return BoolMessageItem.True;
        }
    }



后面还有 15 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。