Пример #1
0
        /// <summary>
        ///     Registers all types marked with a MoonSharpUserDataAttribute that ar contained in an assembly.
        /// </summary>
        /// <param name="asm">The assembly.</param>
        /// <param name="includeExtensionTypes">if set to <c>true</c> extension types are registered to the appropriate registry.</param>
        internal static void RegisterAssembly(Assembly asm = null, bool includeExtensionTypes = false)
        {
            asm = asm ?? Assembly.GetCallingAssembly();

            if (includeExtensionTypes)
            {
                var extensionTypes = from t in asm.SafeGetTypes()
                    let attributes = t.GetCustomAttributes(typeof (ExtensionAttribute), true)
                    where attributes != null && attributes.Length > 0
                    select new {Attributes = attributes, DataType = t};

                foreach (var extType in extensionTypes)
                {
                    UserData.RegisterExtensionType(extType.DataType);
                }
            }


            var userDataTypes = from t in asm.SafeGetTypes()
                let attributes = t.GetCustomAttributes(typeof (MoonSharpUserDataAttribute), true)
                where attributes != null && attributes.Length > 0
                select new {Attributes = attributes, DataType = t};

            foreach (var userDataType in userDataTypes)
            {
                UserData.RegisterType(userDataType.DataType, userDataType.Attributes
                    .OfType<MoonSharpUserDataAttribute>()
                    .First()
                    .AccessMode);
            }
        }
		/// <summary>
		/// Registers all types marked with a MoonSharpUserDataAttribute that ar contained in an assembly.
		/// </summary>
		/// <param name="asm">The assembly.</param>
		/// <param name="includeExtensionTypes">if set to <c>true</c> extension types are registered to the appropriate registry.</param>
		internal static void RegisterAssembly(Assembly asm = null, bool includeExtensionTypes = false)
		{
			if (asm == null)
			{
				#if NETFX_CORE || DOTNET_CORE
					throw new NotSupportedException("Assembly.GetCallingAssembly is not supported on target framework.");
				#else
					asm = Assembly.GetCallingAssembly();
				#endif
			}

			if (includeExtensionTypes)
			{
				var extensionTypes = from t in asm.SafeGetTypes()
									 let attributes = Framework.Do.GetCustomAttributes(t, typeof(ExtensionAttribute), true)
									 where attributes != null && attributes.Length > 0
									 select new { Attributes = attributes, DataType = t };

				foreach (var extType in extensionTypes)
				{
					UserData.RegisterExtensionType(extType.DataType);
				}
			}


			var userDataTypes = from t in asm.SafeGetTypes()
								let attributes = Framework.Do.GetCustomAttributes(t, typeof(MoonSharpUserDataAttribute), true)
								where attributes != null && attributes.Length > 0
								select new { Attributes = attributes, DataType = t };

			foreach (var userDataType in userDataTypes)
			{
				UserData.RegisterType(userDataType.DataType, userDataType.Attributes
					.OfType<MoonSharpUserDataAttribute>()
					.First()
					.AccessMode);
			}
		}
 private static void TryAddManagers(List<ConstructorInfo> managers, Assembly assembly)
 {
     foreach (Type type in assembly.SafeGetTypes(false))
     {
         if (!typeof(IDesignTimeManager).IsAssignableFrom(type) || !type.IsPublicNonAbstractClass())
             continue;
         ConstructorInfo constructor = type.GetConstructor(Empty.Array<Type>());
         if (constructor != null)
             managers.Add(constructor);
     }
 }
Пример #4
0
 /// <summary>
 /// Registers named items from the assembly.
 /// </summary>
 /// <param name="assembly">The assembly.</param>
 /// <param name="itemNamePrefix">Item name prefix.</param>
 public void RegisterItemsFromAssembly(Assembly assembly, string itemNamePrefix)
 {
     InternalLogger.Debug("ScanAssembly('{0}')", assembly.FullName);
     var typesToScan = assembly.SafeGetTypes();
     foreach (IFactory f in this.allFactories)
     {
         f.ScanTypes(typesToScan, itemNamePrefix);
     }
 }