Ejemplo n.º 1
0
        /// <summary>
        /// Feeds the target its required services.
        /// </summary>
        /// <returns>false if update failed</returns>
        public static bool UpdateServices(IEmulatorServiceProvider source, object target)
        {
            Type targetType = target.GetType();

            object?[] tmp = new object?[1];

            foreach (var propInfo in targetType.GetPropertiesWithAttrib(typeof(RequiredServiceAttribute)))
            {
                tmp[0] = source.GetService(propInfo.PropertyType);
                if (tmp[0] == null)
                {
                    return(false);
                }

                propInfo.GetSetMethod(true).Invoke(target, tmp);
            }

            foreach (var propInfo in targetType.GetPropertiesWithAttrib(typeof(OptionalServiceAttribute)))
            {
                tmp[0] = source.GetService(propInfo.PropertyType);
                propInfo.GetSetMethod(true).Invoke(target, tmp);
            }

            return(true);
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Feeds the target its required services.
		/// </summary>
		/// <returns>false if update failed</returns>
		public static bool UpdateServices(IEmulatorServiceProvider source, object target)
		{
			Type targetType = target.GetType();
			object[] tmp = new object[1];

			foreach (var propinfo in targetType.GetPropertiesWithAttrib(typeof(RequiredService)))
			{
				tmp[0] = source.GetService(propinfo.PropertyType);
				if (tmp[0] == null)
					return false;
				propinfo.GetSetMethod(true).Invoke(target, tmp);
			}

			foreach (var propinfo in targetType.GetPropertiesWithAttrib(typeof(OptionalService)))
			{
				tmp[0] = source.GetService(propinfo.PropertyType);
				propinfo.GetSetMethod(true).Invoke(target, tmp);
			}
			return true;
		}