Ejemplo n.º 1
0
        protected static List <InjectionTarget> GetInjectionTargets(Type type)
        {
            // see if we have it in the injection target cache
            if (InjectionTargetCache.ContainsKey(type))
            {
                return(InjectionTargetCache[type]);
            }

            // initialize injection targets
            var targets = new List <InjectionTarget>();

            // otherwise we will create injection targets
            var fieldInfos = type.GetFields();

            foreach (var fieldInfo in fieldInfos)
            {
                var attributes = fieldInfo.GetCustomAttributes(typeof(InjectAttribute), false);
                // if we have an inject attribute, this is considered a target
                if (attributes.Length > 0)
                {
                    var target = new InjectionTarget();
                    target.Type     = fieldInfo.FieldType;
                    target.Property = fieldInfo.Name;
                    targets.Add(target);
                }
            }

            // fill the cache
            InjectionTargetCache[type] = targets;

            return(targets);
        }
Ejemplo n.º 2
0
 //_____________________________________________________________________
 //	Protected Methods
 //_____________________________________________________________________
 protected void ApplyToTarget(InjectionTarget target, Object value)
 {
     if (MappedValues.ContainsKey(target.Type))
     {
         var injectedValue = MappedValues[target.Type];
         var field         = GetFieldInfo(value.GetType(), target.Property);
         if (field != null && injectedValue != null)
         {
             field.SetValue(value, injectedValue);
         }
     }
     else
     {
         throw new Exception("No rule for injecting " + target.Type.ToString() + " into " + value.GetType().ToString());
     }
 }
Ejemplo n.º 3
0
        protected static List<InjectionTarget> GetInjectionTargets(Type type)
        {
            // see if we have it in the injection target cache
            if (InjectionTargetCache.ContainsKey(type))
            {
                return InjectionTargetCache[type];
            }

            // initialize injection targets
            var targets = new List<InjectionTarget>();

            // otherwise we will create injection targets
            var fieldInfos = type.GetFields();
            foreach (var fieldInfo in fieldInfos)
            {
                var attributes = fieldInfo.GetCustomAttributes(typeof(InjectAttribute), false);
                // if we have an inject attribute, this is considered a target
                if (attributes.Length > 0)
                {
                    var target = new InjectionTarget();
                    target.Type = fieldInfo.FieldType;
                    target.Property = fieldInfo.Name;
                    targets.Add(target);
                }
            }

            // fill the cache
            InjectionTargetCache[type] = targets;

            return targets;
        }
Ejemplo n.º 4
0
 //_____________________________________________________________________
 //    Protected Methods
 //_____________________________________________________________________
 protected void ApplyToTarget(InjectionTarget target, Object value)
 {
     if (MappedValues.ContainsKey(target.Type))
     {
         var injectedValue = MappedValues[target.Type];
         var field = GetFieldInfo(value.GetType(), target.Property);
         if (field != null && injectedValue != null)
         {
             field.SetValue(value, injectedValue);
         }
     }
     else
     {
         throw new Exception("No rule for injecting " + target.Type.ToString() + " into " + value.GetType().ToString());
     }
 }
Ejemplo n.º 5
0
 public MappingLoad()
 {
     level     = MappingLevel.None;
     injection = InjectionTarget.All;
 }
Ejemplo n.º 6
0
 public MappingLoad(IMappingProvider _provider, MappingLevel _mapping_level = MappingLevel.None, InjectionTarget _injection = InjectionTarget.All)
 {
     provider  = _provider;
     level     = _mapping_level;
     injection = _injection;
 }