protected override void ProcessRecord() { Type objectType = Type; if (objectType == null) { if (Object is PSObject pSObject) { objectType = pSObject.BaseObject?.GetType(); } else { objectType = Object?.GetType(); } } if (objectType == null) { throw new ArgumentException("Cannot determine object type", nameof(Type)); } if (string.IsNullOrWhiteSpace(MethodName)) { throw new ArgumentException("Method name is not provided", nameof(MethodName)); } if ((GenericTypes?.Length ?? 0) <= 0) { throw new ArgumentException("Generic types are not provided", nameof(GenericTypes)); } object[] args = null; if (Arguments?.Length > 0) { args = new object[Arguments.Length]; for (int i = 0; i < args.Length; i++) { var arg = Arguments[i]; if (arg is PSObject psArg) { arg = psArg.BaseObject; } args[i] = arg; } } var result = SCHost.DoInvokeGenericMethod(objectType, Object, MethodName, GenericTypes, args, MethodIndex); WriteObject(result); }
static void Main(string[] args) { Console.WindowWidth = 80; Console.Title = "SmallChat - by Valentino Giudice"; string chatId; while ((chatId = ConsoleInput("Chat ID")) == "") { ; } string nick; while ((nick = ConsoleInput("Nickname")) == "") { ; } string key = ConsoleInput("Key", hidden: true); IPAddress broadcast; while (!IPAddress.TryParse(ConsoleInput("Broadcast address", "255.255.255.255"), out broadcast) || broadcast.Equals(IPAddress.Any)) { ; } SCHost myself = new SCHost(nick, chatId, SCEDA.Digest(Encoding.ASCII.GetBytes(key)), broadcast); myself.OnReceive += myself_OnReceive; myself.OnWelcome += myself_OnWelcome; myself.OnHello += myself_OnHello; myself.OnLeave += myself_OnLeave; myself.OnConflictNotification += myself_OnConflictNotification; myself.OnMalformedReceived += myself_OnMalformed; myself.OnMalformedNotification += myself_OnMalformed; Console.CancelKeyPress += delegate { myself.Dispose(); }; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Begin to chat!\n"); Console.ResetColor(); char input; for (; ;) { string msg = ""; Console.ForegroundColor = ConsoleColor.Magenta; Console.Write(nick + ": "); Console.ResetColor(); while (((input = Console.ReadKey().KeyChar) != '\r') && msg.Length + nick.Length + 2 < Console.WindowWidth - 1) { if (input == '\0') { Console.Write('\b'); } else { if (input == '\b') { if (Console.CursorLeft < nick.Length + 2) { Console.SetCursorPosition(0, Console.CursorTop); Console.ForegroundColor = ConsoleColor.Magenta; Console.Write(nick + ": "); Console.ResetColor(); } else { Console.Write(" \b"); msg = msg.Remove(msg.Length - 1); } } else { msg += input; } } } if (msg.Length + nick.Length + 2 < Console.WindowWidth - 1) { Console.WriteLine(); } myself.Send(msg); } }
internal ExternalHost(SpreadCommanderHost host) { _Host = host ?? throw new ArgumentNullException(nameof(host), "Host must be assigned"); SCHost = new SCHost(this); }