/// <summary> /// Builds up a sample call for the command. /// </summary> /// <param name="commandName"></param> /// <returns></returns> public string GetSampleRun(string commandName) { // - HelloWorld({name:"kishore", age:35, ..... }); ExtensionMetaData info = null; List <CommandParameterAttribute> args = null; GetInfo(commandName, (ext, paramList) => { info = ext; args = paramList; }); string sample = info.Attribute.Name; if (args == null || args.Count == 0) { return(sample + "();"); } sample += "( {"; // Build up individual parameters. foreach (var arg in args) { if (arg.DataType == typeof(string)) { sample += " " + arg.Name + " : \"" + arg.Example + "\","; } else if (arg.DataType == typeof(DateTime)) { sample += " " + arg.Name + " : \"" + arg.Example + "\","; } else { sample += " " + arg.Name + " : " + arg.Example + ","; } } sample = sample.Remove(sample.Length - 1, 1); return(sample += "} );"); }
/// <summary> /// Register the macro programmatically with lamda func. /// </summary> /// <param name="attrib">The macro attribute to register.</param> /// <param name="args">The list of macro parameters.</param> /// <param name="callback">The callback to use for the macro.</param> public virtual void Register(MacroAttribute attrib, MacroParameterAttribute[] args, Func <Tag, string> callback) { List <object> macroArgs = null; if (args != null && args.Length > 0) { macroArgs = new List <object>(args); } var metadata = new ExtensionMetaData { Id = attrib.Name, Attribute = attrib, Instance = null, DataType = attrib.DeclaringDataType, Lamda = callback, AdditionalAttributes = macroArgs }; Register(attrib.Name, metadata); }