public static object Copy(object @object, ICommandAssembly commandAssembly) { if (@object == null) { return(null); } if (IsPrimitiveOrArrayOfPrimitives(@object.GetType())) { return(@object); } Type copiedType = commandAssembly.GetType(@object.GetType()); if (copiedType == null) { return(null); } if (copiedType.IsArray) { Array copiedArray = Array.CreateInstance(copiedType.GetElementType(), ((Array)@object).Length); var array = ((Array)@object); for (int i = 0; i < array.Length; i++) { copiedArray.SetValue(Copy(array.GetValue(i), commandAssembly), i); } return(copiedArray); } return(CopyNonArray(@object, copiedType)); }
public virtual bool TryDeserializeCommand(string requestString, out ICommand command) { object[] request; if (!TryDeserializeString(requestString, out request)) { command = null; return(false); } var customCommandRequest = new CustomCommandRequest(request); if (customCommandRequest.IsLoadAssemblyCommand) { command = new LoadAssemblyCommand(customCommandRequest.AssemblyName, customCommandRequest.AssemblyContents, commandAssemblies, this); } else if (customCommandRequest.IsEndSessionCommand) { command = new EndSessionCommand(); } else { ICommandAssembly commandAssembly = commandAssemblies.Get(customCommandRequest.AssemblyName); command = commandAssembly == null ? null : new CustomCommand(customCommandRequest.AssemblyName, DeserializeString(customCommandRequest.Payload), new CommandAssemblies()); } return(true); }
public void SetUp() { var mocks = new MockRepository(); commandAssembly = mocks.CreateMock <ICommandAssembly>(); SetupResult.For(commandAssembly.GetType(typeof(ObjectForObjectCopierTest))).Return(typeof(ObjectForObjectCopierTest)); SetupResult.For(commandAssembly.GetType(typeof(ObjectWithoutNoArgConstructor))).Return(typeof(ObjectWithoutNoArgConstructor)); SetupResult.For(commandAssembly.GetType(typeof(CustomEnum))).Return(typeof(CustomEnum)); SetupResult.For(commandAssembly.GetType(typeof(CustomEnum[]))).Return(typeof(CustomEnum[])); SetupResult.For(commandAssembly.GetType(typeof(CustomEnum[][]))).Return(typeof(CustomEnum[][])); mocks.ReplayAll(); }
public static object Copy(object @object, ICommandAssembly commandAssembly) { if (@object == null) return null; if (IsPrimitiveOrArrayOfPrimitives(@object.GetType())) return @object; Type copiedType = commandAssembly.GetType(@object.GetType()); if (copiedType == null) return null; if (copiedType.IsArray) { Array copiedArray = Array.CreateInstance(copiedType.GetElementType(), ((Array) @object).Length); var array = ((Array) @object); for (int i = 0; i < array.Length; i++) copiedArray.SetValue(Copy(array.GetValue(i), commandAssembly), i); return copiedArray; } return CopyNonArray(@object, copiedType); }
public void SetUp() { var mocks = new MockRepository(); commandAssembly = mocks.CreateMock<ICommandAssembly>(); SetupResult.For(commandAssembly.GetType(typeof (ObjectForObjectCopierTest))).Return(typeof (ObjectForObjectCopierTest)); SetupResult.For(commandAssembly.GetType(typeof(ObjectWithoutNoArgConstructor))).Return(typeof(ObjectWithoutNoArgConstructor)); SetupResult.For(commandAssembly.GetType(typeof(CustomEnum))).Return(typeof(CustomEnum)); SetupResult.For(commandAssembly.GetType(typeof(CustomEnum[]))).Return(typeof(CustomEnum[])); SetupResult.For(commandAssembly.GetType(typeof(CustomEnum[][]))).Return(typeof(CustomEnum[][])); mocks.ReplayAll(); }
public CustomCommand(string assemblyName, object[] payload, CommandAssemblies commandAssemblies) { commandList = payload; commandAssembly = commandAssemblies.Get(assemblyName); }