/// <summary>
        /// Returns a list of types that bear a given attribute.
        /// </summary>
        /// <typeparam name="TAttribute">Type of the attribute.</typeparam>
        /// <param name="assembly">The assembly to reflect on.</param>
        /// <param name="inherit">Return inherited types or not.</param>
        /// <returns>List of Type.</returns>
        public static IEnumerable <Type> GetTypesWithAttribute <TAttribute>(Assembly assembly, bool inherit) where TAttribute : System.Attribute
        {
            ArgumentValidator.AssertNotNull(assembly, nameof(assembly));
            var types = from t in assembly.GetTypes() where t.GetTypeInfo().IsDefined(typeof(TAttribute), inherit) select t;

            return(types.ToList());
        }
        private void NullStringRaisesArgumentNullException()
        {
            string nullString = null;
            var    ex         = Assert.Throws <ArgumentNullException>(() => ArgumentValidator.AssertNotNull(nullString, nameof(nullString)));

            Assert.Equal(nameof(nullString), ex.ParamName);
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RegionViewMappingPayload" /> class.
        /// </summary>
        /// <param name="regionName">Name of the region.</param>
        /// <param name="viewMappingType">Type of the view mapping.</param>
        /// <param name="view">The view.</param>
        /// <param name="index">The index.</param>
        /// <param name="assignViewName">Name of the assign view.</param>
        /// <param name="dataContext">The data context.</param>
        /// <exception cref="System.ArgumentNullException">If "regionName" is null\empty</exception>
        /// <exception cref="System.ArgumentNullException">If "view" is null</exception>
        /// <exception cref="System.InvalidOperationException">If "viewMappingType" is not MapView</exception>
        public RegionViewMappingPayload(string regionName, RegionViewMappingType viewMappingType,
                                        GameObject view, int?index = null, string assignViewName = null, object dataContext = null) : this()
            //: this(regionName, viewMappingType)
        {
            ArgumentValidator.AssertNotNullOrEmpty(regionName, "regionName");
            ArgumentValidator.AssertNotNull(view, "view");

            RegionName      = regionName;
            ViewMappingType = viewMappingType;

            if (viewMappingType != RegionViewMappingType.MapView)
            {
                var allowedMappingTypes = string.Format(
                    "This constructor can be used for this operation: {0}", RegionViewMappingType.MapView);
                ThrowInvalidMappingTypeException(allowedMappingTypes, viewMappingType);
            }

            View           = view;
            AssignViewName = assignViewName;
            DataContext    = dataContext;
            if (index.HasValue)
            {
                Index = index.Value;
            }
        }
Пример #4
0
        public static UnityTimer CreateTimer(Action timerCallback, TimeSpan timeSpan, bool isRepeating = true, bool autorun = true)
        {
            ArgumentValidator.AssertNotNull(timerCallback, "timerCallback");
            ArgumentValidator.AssertNotEquals(timeSpan, TimeSpan.Zero, "timeSpan", "timeSpan cannot be {0}", TimeSpan.Zero);

            const string timersHostName = "[TIMERS]";

            var go = GameObject.Find(timersHostName);

            if (go == null)
            {
                go = new GameObject(timersHostName)
                {
                    hideFlags = HideFlags.DontSave
                };
                Debug.LogFormat("Created {0}", go.name);
                if (Application.isPlaying)
                {
                    DontDestroyOnLoad(go);
                }
            }

            var timer = go.AddComponent <UnityTimer>();

            timer.name = string.Format("Timer_{0}_{1}", timerCallback, timerCallback.GetHashCode());

            timer.TimeInterval  = timeSpan;
            timer.IsRepeating   = isRepeating;
            timer.TimerCallBack = timerCallback;
            timer.Autorun       = autorun;
            Debug.LogFormat("Created new timer (name: {0}, autorun: {1}, repeating: {2}, interval: {3})", timer.name, autorun, isRepeating, timeSpan);

            return(timer);
        }
Пример #5
0
        /// <summary>
        /// Unregisters all implementation instance(s).
        /// </summary>
        /// <param name="implementationInstance">The implementation instance.</param>
        /// <returns>
        /// false in case did not find registered mapping(s) for this instance
        /// </returns>
        public bool Unregister(object implementationInstance)
        {
            ArgumentValidator.AssertNotNull(implementationInstance, "implementationInstance");

            var typeKey = implementationInstance.GetType();
            var res     = Mappings.Where(map => map.Value.ContainsKey(typeKey));

            if (res.IsNullOrEmpty())
            {
                return(false);
            }

            var ary = res.ToArray();

            foreach (var map in ary)
            {
                var typeMap = map.Value[typeKey];
                map.Value.Remove(typeKey);
                typeMap.Dispose();

                // TODO TEMP
#if UNITY_EDITOR && UNITY3D
                RemoveFromSingletonsList(typeKey.Name);
#endif

                if (map.Value.Count > 0)
                {
                    continue;
                }
                Mappings.Remove(map.Key);
            }

            return(true);
        }
Пример #6
0
        /// <summary>
        /// Unregisters the specified implementation instance.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="implementationInstance">The implementation instance.</param>
        /// <returns>
        /// false in case did not find registered mapping for this instance
        /// </returns>
        public bool Unregister <T>(object implementationInstance)
        {
            ArgumentValidator.AssertNotNull(implementationInstance, "implementationInstance");

            var key = typeof(T);

            if (!Mappings.ContainsKey(key))
            {
                return(false);
            }

            var map     = Mappings[key];
            var typeKey = implementationInstance.GetType();

            if (map.ContainsKey(typeKey))
            {
                var typeMapping = map[typeKey];
                map.Remove(typeKey);
                typeMapping.Dispose();

                // TODO TEMP
#if UNITY_EDITOR && UNITY3D
                RemoveFromSingletonsList(key.Name);
#endif
            }
            if (map.Count > 0)
            {
                return(true);
            }

            Mappings.Remove(key);
            map.Dispose();
            return(true);
        }
        /// <summary>
        /// Returns the Attribute defined on the give type.
        /// </summary>
        /// <typeparam name="TAttribute">Type of the attribute.</typeparam>
        /// <param name="type">The Type of the object to get the attribute from.</param>
        /// <returns>The attribute if defined on the type, else null.</returns>
        public static TAttribute GetAttributeFrom <TAttribute>(Type type) where TAttribute : Attribute
        {
            ArgumentValidator.AssertNotNull(type, nameof(type));
            var attrib = type.GetTypeInfo().GetCustomAttribute <TAttribute>();

            return(attrib);
        }
        public void InvokeWithoutBlocking(SendOrPostCallback callback, object state)
        {
            ArgumentValidator.AssertNotNull(callback, "callback");
            EnsureInitialized();

            context.Post(callback, state);
        }
        private void NullObjectRaisesArgumentNullException()
        {
            object nullObject = null;
            var    ex         = Assert.Throws <ArgumentNullException>(() => ArgumentValidator.AssertNotNull(nullObject, nameof(nullObject)));

            Assert.Equal(nameof(nullObject), ex.ParamName);
        }
Пример #10
0
        /// <summary>
        ///     Writes the msg.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <param name="src">The source.</param>
        protected override void WriteInternal(string msg, LogSourceType src)
        {
            if (Settings.Severity == LogSeverityType.None)
            {
                return;
            }

            ArgumentValidator.AssertNotNull(msg, "msg");
            Action act;

            switch (src)
            {
            case LogSourceType.Warning:
                act = () => Debug.LogWarning(msg);
                break;

            case LogSourceType.Error:
                act = () => Debug.LogError(msg);
                break;

            default:
                if (Settings.Severity == LogSeverityType.Critical)
                {
                    return;
                }
                act = () => Debug.Log(msg);
                break;
            }
            ThreadHelper.Default.CurrentDispatcher.Dispatch(act);
        }
Пример #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RegionViewMappingPayload" /> class.
        /// </summary>
        /// <param name="regionName">Name of the region.</param>
        /// <param name="viewMappingType">Type of the view mapping.</param>
        /// <param name="view">The view.</param>
        /// <param name="dataContext">The data context.</param>
        /// <exception cref="InvalidOperationException">If "viewMappingType" is not
        /// MapView, UnmapView, ShowView, HideView, LockView, UnlockView, UpdateDataContext</exception>
        /// <exception cref="ArgumentNullException">If "reagionName" is null or empty</exception>
        /// <exception cref="ArgumentNullException">If "view" is null</exception>
        public RegionViewMappingPayload(string regionName, RegionViewMappingType viewMappingType,
                                        GameObject view, object dataContext = null) : this()
        {
            ArgumentValidator.AssertNotNullOrEmpty(regionName, "regionName");
            ArgumentValidator.AssertNotNull(view, "view");

            if (viewMappingType != RegionViewMappingType.MapView &&
                viewMappingType != RegionViewMappingType.UnmapView &&
                viewMappingType != RegionViewMappingType.ShowView &&
                viewMappingType != RegionViewMappingType.HideView &&
                viewMappingType != RegionViewMappingType.LockView &&
                viewMappingType != RegionViewMappingType.UnlockView &&
                viewMappingType != RegionViewMappingType.UpdateDataContext)
            {
                var allowedMappingTypes = string.Format(
                    "This constructor can be used for these operations only: {0}, {1}, {2}, {3}, {4}, {5}, {6}.",
                    RegionViewMappingType.MapView,
                    RegionViewMappingType.UnmapView,
                    RegionViewMappingType.ShowView,
                    RegionViewMappingType.HideView,
                    RegionViewMappingType.LockView,
                    RegionViewMappingType.UnlockView,
                    RegionViewMappingType.UpdateDataContext);
                ThrowInvalidMappingTypeException(allowedMappingTypes, viewMappingType);
            }

            View            = view;
            DataContext     = dataContext;
            RegionName      = regionName;
            ViewMappingType = viewMappingType;
        }
        public void InvokeWithoutBlocking(Action action)
        {
            ArgumentValidator.AssertNotNull(action, "action");
            EnsureInitialized();

            context.Post(state => action(), null);
        }
        public void InvokeAndBlockUntilCompletion(SendOrPostCallback callback, object state)
        {
            ArgumentValidator.AssertNotNull(callback, "callback");
            EnsureInitialized();

            context.Send(callback, state);
        }
Пример #14
0
        public void RegisterRegion(IRegion region)
        {
            ArgumentValidator.AssertNotNull(region, "region");
            ArgumentValidator.AssertNotNullOrEmpty(region.Name, "region.Name");
            if (RegisteredRegions.Contains(region.Name))
            {
                return;
            }

            RegisteredRegions.Add(region.Name);
            if (!DelayedRegions.ContainsKey(region.Name))
            {
                return;
            }

            var payloads = DelayedRegions[region.Name];

            if (payloads.IsNullOrEmpty())
            {
                return;
            }

            var ary = payloads.ToArray();

            payloads.Clear();

            foreach (var payload in ary)
            {
                region.ProcessPayload(payload);
            }
        }
Пример #15
0
 public Task(Action <TaskEventArgs <T> > execute, string descriptionForUser)
 {
     ArgumentValidator.AssertNotNull <Action <TaskEventArgs <T> > >(execute, "execute");
     ArgumentValidator.AssertNotNullOrEmpty(descriptionForUser, "descriptionForUser");
     this.descriptionForUser = descriptionForUser;
     this.Execute           += (EventHandler <TaskEventArgs <T> >)((o, args) => execute(args));
 }
Пример #16
0
        public TaskResult PerformTask <T>(TaskBase <T> task, T argument, object ownerKey = null)
        {
            if (!this.Enable || this.IsUndoing)
            {
                return(TaskResult.NoEnable);
            }
            ArgumentValidator.AssertNotNull <TaskBase <T> >(task, "task");
            if (ownerKey == null)
            {
                return(this.PerformTask <T>(task, argument));
            }
            CancellableTaskServiceEventArgs e = new CancellableTaskServiceEventArgs((ITask)task);

            this.OnExecuting(e);
            if (e.Cancel)
            {
                return(TaskResult.Cancelled);
            }
            this.undoableDictionary.Remove(ownerKey);
            this.redoableDictionary.Remove(ownerKey);
            TaskService.TaskCollection <IInternalTask> taskCollection;
            if (!this.repeatableDictionary.TryGetValue(ownerKey, out taskCollection))
            {
                taskCollection = new TaskService.TaskCollection <IInternalTask>();
                this.repeatableDictionary[ownerKey] = taskCollection;
            }
            taskCollection.AddLast((IInternalTask)task);
            TaskResult taskResult = task.PerformTask((object)argument, TaskMode.FirstTime);

            this.TrimIfRequired(ownerKey);
            this.OnExecuted(new TaskServiceEventArgs((ITask)task));
            return(taskResult);
        }
Пример #17
0
 public SequentiallyCompositeUndoableTask(List <UndoableTaskBase <T> > taskList, string descriptionForUser)
 {
     ArgumentValidator.AssertNotNull <List <UndoableTaskBase <T> > >(taskList, "tasks");
     this.descriptionForUser = descriptionForUser;
     this.taskList           = taskList.ToList <UndoableTaskBase <T> >();
     this.Execute           += new EventHandler <TaskEventArgs <T> >(this.OnExecute);
     this.Undo += new EventHandler <TaskEventArgs <T> >(this.OnUndo);
 }
        /// <summary>
        /// Returns a list of TypeInfo about classes in the assembly that inherit from the given base class.
        /// </summary>
        /// <param name="assembly">The assembly to reflect on.</param>
        /// <param name="baseClass">The base class to get the descendants from.</param>
        /// <returns>List of TypeInfo.</returns>
        /// <exception cref="ArgumentNullException">When an input argument is null.</exception>
        public static IEnumerable <TypeInfo> GetClassesInheritingFrom(Assembly assembly, Type baseClass)
        {
            ArgumentValidator.AssertNotNull(assembly, nameof(assembly));
            ArgumentValidator.AssertNotNull(baseClass, nameof(baseClass));
            var classes = (from t in assembly.DefinedTypes where t.IsClass && t.IsSubclassOf(baseClass) select t).ToArray();

            return(classes.ToList());
        }
Пример #19
0
        public TimeoutDelegateCancelPayload(TimeoutDelegatePayload timeoutPayload,
                                            Delegate onCancelTimeoutMethod = null, params object[] onCancelTimeoutMethodArgs)
            : base(onCancelTimeoutMethod, onCancelTimeoutMethodArgs)
        {
            ArgumentValidator.AssertNotNull(timeoutPayload, "timeoutPayload");

            TimeoutPayload = timeoutPayload;
        }
 public EnhancedAccelerometer(ISettingsService settingsService)
 {
     this.settingsService = ArgumentValidator.AssertNotNull(
         settingsService, "settingsService");
     SetMaximumCalibrationOffset();
     SetMaximumStabilityDeltaOffset();
     DeviceSupportsAccelerometer = Accelerometer.IsSupported;
     CalibrationOffset           = GetCalibrationSetting();
 }
 public void Initialize(Dispatcher dispatcher)
 {
     ArgumentValidator.AssertNotNull(dispatcher, "dispatcher");
     lock (initializationLock)
     {
         this.dispatcher = dispatcher;
         context         = new DispatcherSynchronizationContext(dispatcher);
     }
 }
Пример #22
0
        /// <summary>
        ///     Registers the region.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="regionName">Name of the region.</param>
        public void RegisterRegion(GameObject target, string regionName)
        {
            ArgumentValidator.AssertNotNull(target, "target");
            ArgumentValidator.AssertNotNullOrEmpty(regionName, "regionName");

            target.name = regionName;
            var mapping = target.AddComponent <RegionMapping>();

            mapping.name = regionName;
        }
Пример #23
0
        /// <summary>
        ///     Writes the record.
        /// </summary>
        /// <param name="record">The record.</param>
        /// <param name="src">The source.</param>
        protected override void WriteInternal(LogRecord record, LogSourceType src)
        {
            if (Settings.Severity == LogSeverityType.None)
            {
                return;
            }

            ArgumentValidator.AssertNotNull(record, "record");
            WriteInternal(record.ToString(), src);
        }
Пример #24
0
        public void UnregisterRegion(IRegion region)
        {
            ArgumentValidator.AssertNotNull(region, "region");
            ArgumentValidator.AssertNotNullOrEmpty(region.Name, "region.Name");
            if (!RegisteredRegions.Contains(region.Name))
            {
                return;
            }

            RegisteredRegions.Remove(region.Name);
        }
Пример #25
0
        /// <summary>
        /// Awakes this instance.
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            var col = GetComponent <Collider>();

            ArgumentValidator.AssertNotNull(col, "col");

            _thisCollider         = col;
            _thisCollider.enabled = false;
        }
        /// <summary>
        /// Clones the specified vector.
        /// </summary>
        /// <param name="threeDimensionalVector">The vector to clone.</param>
        public ThreeDimensionalVector(ThreeDimensionalVector threeDimensionalVector)
        {
            ArgumentValidator.AssertNotNull(threeDimensionalVector, "simple3DVector");

            if (threeDimensionalVector != null)
            {
                X = threeDimensionalVector.X;
                Y = threeDimensionalVector.Y;
                Z = threeDimensionalVector.Z;
            }
        }
Пример #27
0
        /// <summary>
        ///     Writes the exc.
        /// </summary>
        /// <param name="exc">The exception.</param>
        protected override void WriteInternal(Exception exc)
        {
            if (Settings.Severity == LogSeverityType.None)
            {
                return;
            }

            ArgumentValidator.AssertNotNull(exc, "exc");
            Action act = () => Debug.LogException(exc);

            ThreadHelper.Default.CurrentDispatcher.Dispatch(act);
        }
Пример #28
0
        protected internal BaseServiceResponsePayload(BaseServiceRequestPayload parentRequestPayload,
                                                      ServiceResponseState state, Exception error = null)
            : base(parentRequestPayload.ServiceName)
        {
            ArgumentValidator.AssertNotNull(parentRequestPayload, "parentRequestPayload");

            ParentRequestPayload = parentRequestPayload;
            Tag             = parentRequestPayload.Tag;
            IsCustomService = parentRequestPayload.IsCustomService;

            ResponseState = state;
            ResponseError = error;
        }
 public EnhancedAccelerometerReading(
     DateTimeOffset timestamp,
     ThreeDimensionalVector rawAcceleration,
     ThreeDimensionalVector optimallyFilteredAcceleration,
     ThreeDimensionalVector lowPassFilteredAcceleration,
     ThreeDimensionalVector averageAcceleration)
 {
     Timestamp       = timestamp;
     RawAcceleration = ArgumentValidator.AssertNotNull(rawAcceleration, "rawAcceleration");
     OptimallyFilteredAcceleration = ArgumentValidator.AssertNotNull(optimallyFilteredAcceleration, "optimallyFilteredAcceleration");
     LowPassFilteredAcceleration   = ArgumentValidator.AssertNotNull(lowPassFilteredAcceleration, "lowPassFilteredAcceleration");
     AverageAcceleration           = ArgumentValidator.AssertNotNull(averageAcceleration, "averageAcceleration");
 }
        public void InvokeAndBlockUntilCompletion(Action action)
        {
            ArgumentValidator.AssertNotNull(action, "action");
            EnsureInitialized();

            if (dispatcher.CheckAccess())
            {
                action();
            }
            else
            {
                context.Send(delegate { action(); }, null);
            }
        }