private void graphSaveNET35(object o, Code originalCode, int level) { bool first; Type t = o.GetType(); string indent = new string('\t', level); string indent1 = new string('\t', level + 1); if (o is IEnumerable && (CustomAttributeHelper.All <XsTypeAttribute>(o.GetType()).Length == 0)) { first = true; MainCode.Write("new " + _re.GetTypeName(t)); foreach (var obj in (o as IEnumerable)) { MainCode.WriteLine(first ? " {" : ","); MainCode.Write(indent1); first = false; GenerateObjectCode(obj, null, level + 1); } if (!first) { MainCode.WriteLine(); MainCode.Write(indent); MainCode.Write("}"); } else { MainCode.Write("()"); } MainCode.Write(" "); } else { newClass(o); first = true; foreach (var pi in getPropertiesToSave(o)) { object propValue = pi.GetValue(o, null); MainCode.WriteLine(first ? "{" : ","); MainCode.Write(indent1); first = false; MainCode.Write(pi.Name + " = "); if (pi.PropertyType == typeof(ExecutableScriptBase)) { MainCode.Write("new " + originalCode.GetClassName() + "()"); } else { GenerateObjectCode(propValue, null, level + 1); } } if (!first) { MainCode.WriteLine(); MainCode.Write(indent); MainCode.Write("}"); } } }
public static int Help(ScriptContext context, UsageGenerator usage, CommandLineParameters xsParams) { context.WriteLine(OutputType.Bold, GetLogo(context)); context.WriteLine(); var command = context.GetStr(xs.help, null); if (!string.IsNullOrEmpty(command)) { var tt = new Dictionary <string, Type>(StringComparer.OrdinalIgnoreCase); tt["param"] = typeof(CommandLineParameter); tt["versionInfo"] = typeof(VersionInfo); tt["usage"] = typeof(UsageGenerator); foreach (var s in context.GetKnownTypes()) { foreach (var at in CustomAttributeHelper.All <XsTypeAttribute>(s)) { if (!string.IsNullOrEmpty(at.Name)) { tt[at.Name] = s; } } } Type type; if (tt.TryGetValue(command, out type)) { writeCommandHelp(context, type, usage.CorrectWidth(-1)); return(-2); } if (command == "*") { List <Var> v = new List <Var>(); v.Add(new Var("param", getDescr(typeof(CommandLineParameter)))); v.Add(new Var("versioninfo", getDescr(typeof(VersionInfo)))); v.Add(new Var("usage", getDescr(typeof(UsageGenerator)))); foreach (var s in context.GetKnownTypes()) { var xst = CustomAttributeHelper.First <XsTypeAttribute>(s); if (xst == null || string.IsNullOrEmpty(xst.Name)) { continue; } v.Add(new Var(xst.Name, getDescr(s))); } v.Sort((a, b) => string.Compare(a.Name, b.Name)); v.Insert(0, new Var("Actions:", null)); v.Insert(1, new Var("", null)); Utils.WrapTwoColumns(context.Out, v, 30, usage.CorrectWidth(-1)); return(-2); } if (command.StartsWith(".", StringComparison.Ordinal)) { bool success = false; foreach (var nn in ((IEvaluationContext)context).GetNonameObjects()) { success = writeTypeHelp(context, nn.Type, new StringFilter(command.Substring(1)), usage.CorrectWidth(-1)) || success; } if (!success) { context.Error.WriteLine("Cannot find method '" + command + "'. "); } return(-2); } Type t = context.FindType(command); if (t == null) { t = context.FindType("XS." + command); } if (t != null) { writeTypeHelp(context, t, null, usage.CorrectWidth(-1)); } else if (command.Contains("?") || command.Contains("*")) { var r = Utils.WildcardToRegex(command, RegexOptions.IgnoreCase); foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) { foreach (var ttt in a.GetTypes()) { if (ttt != null && ttt.IsPublic && (r.IsMatch(ttt.Name) || r.IsMatch(Dump.GetFriendlyTypeName(ttt)))) { context.WriteLine(Dump.GetFriendlyTypeName(ttt, true)); } } } } else { context.Error.WriteLine("Cannot find command or type '" + command + "'. Use //help * to display the list of commands"); } } else { context.WriteLine(usage.GetUsage(context, null, null, -1, xsParams)); } return(-2); }
private void graphSaveNET20(object o, string prevVarName, Code originalCode, int level) { Type t = o.GetType(); string indent = new string('\t', level); if (o is IEnumerable && (CustomAttributeHelper.All <XsTypeAttribute>(o.GetType()).Length == 0)) { if (t.GetGenericArguments().Length == 0) { MainCode.Write("new " + _re.GetTypeName(t) + "()"); } else { string bestType = _re.GetTypeName(t.GetGenericArguments()[0]); MainCode.Write("new List<" + bestType + ">()"); } foreach (var obj in (o as IEnumerable)) { MainCode.WriteLine(";"); MainCode.Write(indent); string v = getNextVar(obj); if (obj is Code && ((Code)obj).Dynamic == false) { MainCode.Write(_re.GetTypeName(typeof(CompiledCode))); } else { MainCode.Write(_re.GetTypeName(obj.GetType())); } MainCode.Write(" " + v + " = "); GenerateObjectCode(obj, v, level + 1); MainCode.WriteLine(";"); MainCode.Write(indent + prevVarName + ".Add(" + v + ")"); } } else { newClass(o); foreach (var pi in getPropertiesToSave(o)) { MainCode.WriteLine(";"); MainCode.Write(indent); if (!pi.PropertyType.IsClass || pi.PropertyType == typeof(string) || pi.PropertyType == typeof(ExecutableScriptBase)) { MainCode.Write(prevVarName + "." + pi.Name + " = "); if (pi.PropertyType == typeof(ExecutableScriptBase)) { MainCode.Write("new " + originalCode.GetClassName() + "()"); } else { object propValue = pi.GetValue(o, null); writeSimple(propValue); } } else { object propValue = pi.GetValue(o, null); if (propValue != null) { string v = getNextVar(propValue); MainCode.Write(_re.GetTypeName(propValue.GetType()) + " " + v + " = "); GenerateObjectCode(propValue, v, level + 1); MainCode.WriteLine(";"); MainCode.Write(indent + prevVarName + "." + pi.Name + " = " + v); } } } } }