Ejemplo n.º 1
0
        void PopulateProperty(ModuleInfo moduleInfo, object module, ref ModulePropertyDefinition propertyDefinition)
        {
            var propertyName = propertyDefinition.Name;

            if (string.IsNullOrEmpty(propertyName))
            {
                return;
            }

            var property      = moduleInfo.GetProperty(propertyName);
            var propertyValue = propertyDefinition.Value;

            for (int i = 0; i < PropertyHandlers.Count; i++)
            {
                var handler = PropertyHandlers[i];
                if (handler.SetPropertyValue(module, property, propertyValue))
                {
                    return;
                }
            }

            throw new InvalidOperationException("Property not handled: " + propertyName);
        }
Ejemplo n.º 2
0
        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);
        }