Пример #1
0
        public void BuildDefinition(out ComponentBundleDefinition definition)
        {
            AddNamelessComponents();

            definition = new ComponentBundleDefinition();

            if (components.Count == 0)
            {
                return;
            }

            definition.Components = new ComponentDefinition[components.Count];
            for (int i = 0; i < components.Count; i++)
            {
                var component     = components[i];
                var componentInfo = componentInfoManager.GetComponentInfo(component.GetType());

                definition.Components[i] = new ComponentDefinition
                {
                    Name = GetName(component),
                    Type = componentInfoManager.GetTypeDefinitionName(componentInfo)
                };

                if (componentInfo.PropertyCount == 0)
                {
                    continue;
                }

                definition.Components[i].Properties = new PropertyDefinition[componentInfo.PropertyCount];
                for (int j = 0; j < componentInfo.PropertyCount; j++)
                {
                    var property     = componentInfo.GetProperty(j);
                    var propertyType = property.PropertyType;

                    var propertyName  = property.Name;
                    var propertyValue = property.GetValue(component, null);

                    string stringValue = null;

                    for (int k = 0; k < PropertyStringfiers.Count; k++)
                    {
                        var stringfier = PropertyStringfiers[k];

                        if (stringfier.ConvertToString(component, property, propertyValue, out stringValue))
                        {
                            break;
                        }
                    }

                    definition.Components[i].Properties[j] = new PropertyDefinition
                    {
                        Name  = propertyName,
                        Value = stringValue
                    };
                }
            }
        }
Пример #2
0
        public void Build(ref ComponentBundleDefinition definition)
        {
            if (ArrayHelper.IsNullOrEmpty(definition.Components))
            {
                return;
            }

            nameComponentMap = new Dictionary <string, object>(definition.Components.Length);

            for (int i = 0; i < definition.Components.Length; i++)
            {
                var componentInfo = componentInfoManager.GetComponentInfo(definition.Components[i].Type);
                var name          = definition.Components[i].Name;
                var component     = componentInfo.CreateInstance();
                nameComponentMap[name] = component;
            }

            for (int i = 0; i < definition.Components.Length; i++)
            {
                var componentInfo = componentInfoManager.GetComponentInfo(definition.Components[i].Type);
                var name          = definition.Components[i].Name;
                var component     = nameComponentMap[name];

                var propertyDefinitions = definition.Components[i].Properties;
                if (ArrayHelper.IsNullOrEmpty(propertyDefinitions))
                {
                    continue;
                }

                for (int j = 0; j < propertyDefinitions.Length; j++)
                {
                    PopulateProperty(componentInfo, component, ref propertyDefinitions[j]);
                }
            }

            for (int i = 0; i < definition.Components.Length; i++)
            {
                var name      = definition.Components[i].Name;
                var component = nameComponentMap[name];

                var initializable = component as IInitializingObject;
                if (initializable != null)
                {
                    initializable.Initialize();
                }
            }
        }