public void AsTestNullValue() { var res = ObjectEx.As <String>(null); res.Should() .BeNull(); }
private UnityEngine.Object GetSharedResource(string res, bool notdestoryed) { UnityEngine.Object obj = null; if (string.IsNullOrEmpty(res)) { return(obj); } ObjectEx objEx = null; if (!m_LoadedPrefabs.TryGetValue(res, out objEx)) { obj = UnityEngine.Resources.Load(res); if (null != obj) { objEx = new ObjectEx(); objEx.obj = obj; objEx.notdesotryed = notdestoryed; m_LoadedPrefabs.Add(res, objEx); } else { LogUtil.Error("Load asset failed : {0}", res); } } else { obj = objEx.obj; } return(obj); }
public void CoalesceTest1() { var expected = RandomValueEx.GetRandomString(); var actual = ObjectEx.Coalesce(null, null, null, null, expected, "Test2"); Assert.Equal(expected, actual); }
private void UpdateDefinitions(Dictionary <string, SessionDefinition> currentDefinitions) { var previousDefinitions = ObjectEx.GetAndReplace(ref _definitions, currentDefinitions); if (previousDefinitions != null && previousDefinitions.Any()) { var addedDefinitions = currentDefinitions.Where(kvp => previousDefinitions.ContainsKey(kvp.Key) == false || previousDefinitions[kvp.Key].CreatedAt != kvp.Value.CreatedAt) .Select(kvp => kvp.Value) .OrderBy(definition => definition.CreatedAt) .ToList(); var removedDefinitions = previousDefinitions.Where(kvp => currentDefinitions.ContainsKey(kvp.Key) == false || currentDefinitions[kvp.Key].CreatedAt != kvp.Value.CreatedAt) .Select(kvp => kvp.Value) .ToList(); if (addedDefinitions.Any() || removedDefinitions.Any()) { DefinitionsChanged?.Invoke(this, CollectionChangedEventArgs <SessionDefinition> .Create(addedDefinitions, removedDefinitions)); } } else if (currentDefinitions.Any()) { DefinitionsChanged?.Invoke(this, CollectionChangedEventArgs <SessionDefinition> .CreateForAddedCollection(currentDefinitions.Values.OrderBy(d => d.CreatedAt))); } }
public void RPC_SelectedLootItem(RPCMessage msg) { BasePlayer player = msg.player; uint itemUID = msg.read.UInt32(); if (player == null || !player.inventory.loot.IsLooting() || player.inventory.loot.entitySource != this) { return; } Item vehicleItem = carOccupant.GetVehicleItem(itemUID); if (vehicleItem == null || Interface.CallHook("OnVehicleModuleSelect", vehicleItem, this, player) != null) { return; } bool flag = player.inventory.loot.RemoveContainerAt(3); BaseVehicleModule result; VehicleModuleStorage vehicleModuleStorage; if (TryGetModuleForItem(vehicleItem, out result) && (object)(vehicleModuleStorage = result as VehicleModuleStorage) != null) { IItemContainerEntity container = vehicleModuleStorage.GetContainer(); if (!ObjectEx.IsUnityNull(container)) { player.inventory.loot.AddContainer(container.inventory); flag = true; } } if (flag) { player.inventory.loot.SendImmediate(); } Interface.CallHook("OnVehicleModuleSelected", vehicleItem, this, player); }
/// <summary> /// 添加事件; /// </summary> /// <param name="receiver">接收者</param> /// <param name="type">事件类型</param> /// <param name="callBack">事件回调</param> public void AddEvent(ObjectEx receiver, EventType type, EventHandler callBack) { if (null == receiver) { LogHelper.PrintError("[EventMgr]AddEvent error,the receiver is null."); return; } if (!_eventDict.TryGetValue(receiver, out var dict)) { _eventDict[receiver] = new Dictionary <EventType, List <EventHandler> >(); } dict = _eventDict[receiver]; if (!dict.TryGetValue(type, out var list)) { list = new List <EventHandler>(); dict[type] = list; } list = dict[type]; if (list.Contains(callBack)) { LogHelper.PrintWarning($"[EventMgr]AddEvent repeat,receiver:{receiver.ID},eventType:{type.ToString()}."); } else { list.Add(callBack); } }
private void ConfigureWebApi(IAppBuilder appBuilder) { HttpConfiguration config = new HttpConfiguration(); bool bound = ObjectEx.GetAndReplace(ref _boundTypes, true); if (bound == false) { _kernel.Bind <DefaultModelValidatorProviders>().ToConstant(new DefaultModelValidatorProviders(config.Services.GetServices(typeof(ModelValidatorProvider)).Cast <ModelValidatorProvider>())); _kernel.Bind <DefaultFilterProviders>().ToConstant(new DefaultFilterProviders(new[] { new NinjectFilterProvider(_kernel) }.AsEnumerable())); } config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); var cors = new EnableCorsAttribute(origins: "*", headers: "*", methods: "*"); config.EnableCors(cors); config.DependencyResolver = new Ninject.Web.WebApi.NinjectDependencyResolver(_kernel); Formatters.ForEach(config.Formatters.Add); config.Formatters.OfType <JsonMediaTypeFormatter>().ForEach(formatter => { formatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); Converters.ForEach(formatter.SerializerSettings.Converters.Add); }); appBuilder.UseWebApi(config); }
/// <summary> /// Update the local copy of the Ucdb object with returned values keeping compounds & models if returned as null /// </summary> /// <param name="resultObject"></param> /// <param name="ucdb"></param> void UpdateUcdb( Services.Native.NativeMethodTransportObject resultObject, UcdbDatabase ucdb) { if (resultObject == null || resultObject.Value == null || ucdb == null) { return; } ServiceTypes.UcdbDatabase serviceUcdbDatabase = (ServiceTypes.UcdbDatabase)resultObject.Value; UcdbDatabase ucdbDatabase = ServiceFacade.TypeConversionHelper.Convert <ServiceTypes.UcdbDatabase, UcdbDatabase>(serviceUcdbDatabase); UcdbCompound[] compounds = ucdb.Compounds; UcdbModel[] models = ucdb.Models; ObjectEx.MemberwiseCopy(ucdbDatabase, ucdb); // copy values back if (ucdb.Compounds == null) { ucdb.Compounds = compounds; } if (ucdb.Models == null) { ucdb.Models = models; } return; }
/// <summary> /// 从组合体中获取指定名称的嵌入的资源 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="assembly"></param> /// <param name="resourceName"></param> /// <returns></returns> public static T GetEmbeddedResource <T>(Assembly assembly, string resourceName) where T : class { string manifestName = GetResourceManifestName(resourceName, assembly); if (string.IsNullOrEmpty(manifestName)) { return(default(T)); } if (typeof(T) == typeof(Stream)) { return(assembly.GetManifestResourceStream(manifestName) as T); } using (Stream st = assembly.GetManifestResourceStream(manifestName)) { st.Position = 0; if (typeof(T) == typeof(string)) { using (StreamReader reader = new StreamReader(st)) { object text = reader.ReadToEnd(); return((T)text); } } else { XmlObjectSerializer serializer = ObjectEx.GetXmlObjectSerializer(typeof(T)); return(serializer.ReadObject(st) as T); } } }
/// <summary> /// 移除Component; /// </summary> /// <typeparam name="T"></typeparam> /// <param name="owner"></param> public void ReleaseComponent <T>(ObjectEx owner) where T : AbsComponent, new() { if (null == owner) { return; } owner.ReleaseComponent <T>(); }
public void Stop() { var subscription = ObjectEx.GetAndReplace(ref _subscription, null); subscription?.Dispose(); State = ControlServiceState.Stopped; }
public void ReferenceEqualsTestNullCheck() { // ReSharper disable once AssignNullToNotNullAttribute // ReSharper disable once ReturnValueOfPureMethodIsNotUsed Action test = () => ObjectEx.RefEquals(null, ""); Assert.Throws <ArgumentNullException>(test); }
public void ToBooleanValueNullTest() { var actual = ObjectEx.ToBoolean(null, CultureInfo.InvariantCulture); actual .Should() .Be(false); }
private void Close() { ObjectEx.GetAndReplace(ref _deviceObserver, null); if (_deviceObserver != null) { _observers.Disconnect(_deviceObserver); } }
public void CoalesceTestInvalidOperationCheck() { Object[] array = null; // ReSharper disable once ReturnValueOfPureMethodIsNotUsed // ReSharper disable once ExpressionIsAlwaysNull Action test = () => ObjectEx.Coalesce(null, array, null); test.ShouldThrow <InvalidOperationException>(); }
public void ToInt16InvalidFormatTest() { const String value = "invalidFormat"; // ReSharper disable once ReturnValueOfPureMethodIsNotUsed Action test = () => ObjectEx.ToInt16(value); test.ShouldThrow <FormatException>(); }
public void ToDecimalInvalidFormatFormatProviderTest() { const String value = "invalidFormat"; // ReSharper disable once ReturnValueOfPureMethodIsNotUsed Action test = () => ObjectEx.ToDecimal(value, CultureInfo.InvariantCulture); test.ShouldThrow <FormatException>(); }
public void ToBooleanInvalidFormatTest() { const String value = "invalidFormat"; // ReSharper disable once ReturnValueOfPureMethodIsNotUsed Action test = () => ObjectEx.ToBoolean(value); Assert.Throws <FormatException>(test); }
public void ToByteInvalidFormatFormatProviderTest() { const String value = "invalidFormat"; // ReSharper disable once ReturnValueOfPureMethodIsNotUsed Action test = () => ObjectEx.ToByte(value, CultureInfo.CurrentCulture); Assert.Throws <FormatException>(test); }
static void ClientState(ISmartMemory memUtils) { scan = memUtils["engine.dll"].Find(new byte[] { 0xC2, 0x00, 0x00, 0xCC, 0xCC, 0x8B, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x33, 0xC0, 0x83, 0xB9 }, "x??xxxx????xxxx"); if (scan.Success) { int tmp = memUtils.Read <int>((IntPtr)(scan.Address.ToInt32() + 7)); Offsets.EngineClientState = (IntPtr)tmp - engineDllBase; Logger.Info(ObjectEx.GetName(() => Offsets.EngineClientState) + "\n" + Offsets.EngineClientState.ToString("X8")); } }
static void WeaponTable(ISmartMemory memUtils) { scan = memUtils["client.dll"].Find(new byte[] { 0xA1, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xB7, 0xC9, 0x03, 0xC9, 0x8B, 0x44, 0x00, 0x0C, 0xC3 }, "x????xxxxxxx?xx"); if (scan.Success) { int tmp = memUtils.Read <int>((IntPtr)(scan.Address.ToInt32() + 1)); Offsets.MiscWeaponInfo = (IntPtr)tmp - clientDllBase; Logger.Info(ObjectEx.GetName(() => Offsets.MiscWeaponInfo) + "\n" + Offsets.MiscWeaponInfo.ToString("X8")); } }
public void ToByteFormatProviderTest() { const Byte expected = 1; var value = expected.ToString(); var actual = ObjectEx.ToByte(value, CultureInfo.InvariantCulture); actual .Should() .Be(expected); }
public void ToByteFormatProviderNullTest() { const Byte expected = 1; var value = expected.ToString(); var actual = ObjectEx.ToByte(value, null); actual .Should() .Be(expected); }
public void ToByteTest() { const Byte expected = 1; var value = expected.ToString(); var actual = ObjectEx.ToByte(value); actual .Should() .Be(expected); }
public bool DisconnectDevice() { var hook = ObjectEx.GetAndReplace(ref _hook, null) as IDisposable; if (hook != null) { hook.Dispose(); } return(true); }
private void HideTray() { var tb = ObjectEx.GetAndReplace(ref icon, null); if (tb != null && tb.IsDisposed == false) { //tb.HideBalloonTip(); tb.Dispose(); } }
public void CoalesceOrDefaultTest() { var expected = RandomValueEx.GetRandomString(); String s = null; // ReSharper disable once ReturnValueOfPureMethodIsNotUsed // ReSharper disable once AssignNullToNotNullAttribute Action test = () => ObjectEx.CoalesceOrDefault(null, s, null, null, expected, "Test2"); Assert.Throws <ArgumentNullException>(test); }
//static void ClientState2(MemUtils memUtils) //{ // scan = memUtils.PerformSignatureScan(new byte[] { 0x68, 0, 0, 0, 0, 0xFF, 0x15, 0x98, 0x75, 0x1C, 0x0D, 0xA1, 0, 0, 0, 0, 0x83, 0xc4, 0x1c }, "x????xx????x????xxx", engineDll); // if (scan.Success) // { // int tmp = memUtils.Read<int>((IntPtr)(scan.Address.ToInt32() + 12)); // Options.Engine = tmp - engineDllBase; // } //} static void SetViewAngles(ISmartMemory memUtils) { scan = memUtils["engine.dll"].Find(new byte[] { 0x8B, 0x15, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x4D, 0x08, 0x8B, 0x82, 0x00, 0x00, 0x00, 0x00, 0x89, 0x01, 0x8B, 0x82, 0x00, 0x00, 0x00, 0x00, 0x89, 0x41, 0x04 }, "xx????xxxxx????xxxx????xxx"); if (scan.Success) { int tmp = memUtils.Read <int>((IntPtr)(scan.Address.ToInt32() + 11)); Offsets.SetViewAngles = (IntPtr)tmp; Logger.Info(ObjectEx.GetName(() => Offsets.SetViewAngles) + "\n" + Offsets.SetViewAngles.ToString("X8")); } }
static void Jump(ISmartMemory memUtils) { scan = memUtils["client.dll"].Find(new byte[] { 0x89, 0x15, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x15, 0x00, 0x00, 0x00, 0x00, 0xF6, 0xC2, 0x03, 0x74, 0x03, 0x83, 0xCE, 0x08, 0xA8, 0x08, 0xBF }, "xx????xx????xxxxxxxxxxx"); if (scan.Success) { int tmp = memUtils.Read <int>((IntPtr)(scan.Address.ToInt32() + 2)); Offsets.Jump = (IntPtr)tmp - clientDllBase; Logger.Info(ObjectEx.GetName(() => Offsets.Jump) + "\n" + Offsets.Jump.ToString("X8")); } }
private void CloseHostWindow() { var hostWindow = ObjectEx.GetAndReplace(ref _sessionHostWindow, null); if (hostWindow != null) { hostWindow.Closed -= SessionHostWindow_Closed; hostWindow.Close(); } }