Esempio n. 1
0
        public void LinkProperties(FAopComponentBuilder builder)
        {
            XAopComponent xcomponent = builder.Component;

            if (xcomponent.HasProperty)
            {
                FAopDescriptor descriptor = xcomponent.Descriptor;
                foreach (XAopProperty xproperty in xcomponent.Properties)
                {
                    FAopProperty property = descriptor.Properties[xproperty.Name];
                    if (property == null)
                    {
                        throw new FFatalException("Config has property. but instance has'nt this property({0}).", xproperty.Name);
                    }
                    if (_logger.DebugAble)
                    {
                        _logger.Debug(this, "LinkProperties", "Set property {0} = {1}", xproperty.Name, xproperty.Value);
                    }
                    object fieldValue = Convert.ChangeType(xproperty.Value, property.FieldType);
                    property.Field.SetValue(builder.Instance, fieldValue);
                }
            }
        }
Esempio n. 2
0
        public void Parse(FType type)
        {
            _type = type;
            // Parse fields
            BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

            FField[] fields = type.GetAllFields(flags);
            foreach (FField field in fields)
            {
                // Build property
                object[] aproperties = field.Field.GetCustomAttributes(typeof(APropertyAttribute), true);
                if (aproperties.Length > 0)
                {
                    FAopProperty property = new FAopProperty();
                    property.Link(field.Field);
                    if (_properties.Contains(property.Name))
                    {
                        throw new FFatalException("Duplicate property. (name={0})", property.Name);
                    }
                    _properties[property.Name] = property;
                    continue;
                }
                // Build linker
                object[] alinkers = field.Field.GetCustomAttributes(typeof(ALinkerAttribute), true);
                if (alinkers.Length > 0)
                {
                    FAopLinker linker = new FAopLinker();
                    linker.Link(field.Field);
                    if (_linkers.Contains(linker.Name))
                    {
                        throw new FFatalException("Duplicate linker. (name={0})", linker.Name);
                    }
                    _linkers[field.Name] = linker;
                    continue;
                }
            }
        }