public void Build(ModuleBundleDefinition definition) { if (definition.Modules == null || definition.Modules.Length == 0) { return; } moduleMap = new Dictionary <string, object>(definition.Modules.Length); for (int i = 0; i < definition.Modules.Length; i++) { var moduleInfo = moduleInfoManager.GetModuleInfo(definition.Modules[i].Type); var moduleName = definition.Modules[i].Name; var module = moduleInfo.CreateInstance(); moduleMap[moduleName] = module; } for (int i = 0; i < definition.Modules.Length; i++) { var moduleInfo = moduleInfoManager.GetModuleInfo(definition.Modules[i].Type); var moduleName = definition.Modules[i].Name; var module = moduleMap[moduleName]; var propertyDefinitions = definition.Modules[i].Properties; if (propertyDefinitions == null || propertyDefinitions.Length == 0) { continue; } for (int j = 0; j < propertyDefinitions.Length; j++) { PopulateProperty(moduleInfo, module, ref propertyDefinitions[j]); } } for (int i = 0; i < definition.Modules.Length; i++) { var moduleName = definition.Modules[i].Name; var module = moduleMap[moduleName]; var initializeMethodName = definition.Modules[i].InitializeMethodName; if (initializeMethodName != null) { var initializeMethod = module.GetType().GetMethod(initializeMethodName); initializeMethod.Invoke(module, null); } } }
public ModuleBundleDefinition Build() { AddNamelessModules(); var definition = new ModuleBundleDefinition(); if (modules.Count == 0) { return(definition); } definition.Modules = new ModuleDefinition[modules.Count]; for (int i = 0; i < modules.Count; i++) { var module = modules[i]; var moduleInfo = moduleInfoManager.GetModuleInfo(module.GetType()); var moduleName = GetModuleName(module); definition.Modules[i] = new ModuleDefinition { Name = moduleName, Type = moduleInfoManager.GetTypeDefinitionName(moduleInfo), InitializeMethodName = GetInitializeMethodName(moduleName) }; if (moduleInfo.PropertyCount == 0) { continue; } for (int j = 0; j < moduleInfo.PropertyCount; j++) { var property = moduleInfo.GetProperty(j); var propertyType = property.PropertyType; var propertyName = property.Name; var propertyValue = property.GetValue(module, null); var defaultValue = moduleInfo.GetDefaultValue(j); if (propertyValue == defaultValue) { continue; } if (defaultValue != null && defaultValue.Equals(propertyValue)) { continue; } string stringValue = null; for (int k = 0; k < PropertyStringfiers.Count; k++) { var stringfier = PropertyStringfiers[k]; if (stringfier.ConvertToString(module, property, propertyValue, out stringValue)) { break; } } var propertyDefinition = new ModulePropertyDefinition { Name = propertyName, Value = stringValue }; propertyDefinitions.Add(propertyDefinition); } if (0 < propertyDefinitions.Count) { definition.Modules[i].Properties = propertyDefinitions.ToArray(); propertyDefinitions.Clear(); } } return(definition); }