Source/NFX/Environment/Behavior.cs
/// <summary>
/// Applies behaviors to instance as configured from config section node
/// </summary>
Applies behaviors to instance as configured from config section node
Applies behaviors to instance as configured from config section node
public static void ApplyConfiguredBehaviors(object target, IConfigSectionNode node)
          {
              if (target==null) return;
              if (typeof(Behavior).IsAssignableFrom(target.GetType())) return;
              string descr = string.Empty;
              try
              {
                  var firstLevel = true;
                  while(node.Exists)
                  {
                        var bnodes = node[CONFIG_BEHAVIORS_SECTION]
                                          .Children
                                          .Where(c=> c.IsSameName(CONFIG_BEHAVIOR_SECTION) && (firstLevel || c.AttrByName(CONFIG_CASCADE_ATTR).ValueAsBool(false)) )
                                          .OrderBy(c=> c.AttrByName(Configuration.CONFIG_ORDER_ATTR).ValueAsInt());
                        foreach(var bnode in bnodes)
                        {
                            descr = " config path: '{0}', type: '{1}'".Args(bnode.RootPath, bnode.AttrByName(FactoryUtils.CONFIG_TYPE_ATTR).ValueAsString(StringConsts.NULL_STRING));
                            var behavior = FactoryUtils.MakeAndConfigure<Behavior>(bnode);
                            behavior.Apply(target);
                        }
                        node = node.Parent;
                        firstLevel = false;
                 }
             }
             catch(Exception error)
             {
                throw new BehaviorApplyException(StringConsts.CONFIG_BEHAVIOR_APPLY_ERROR.Args(descr, error.ToMessageWithType()), error);
             }
          }
public static void ApplyConfiguredBehaviors ( object target , IConfigSectionNode node ) { if ( target == null ) return ; if ( typeof ( Behavior ) . IsAssignableFrom ( target . GetType ( ) ) ) return ; string descr = string . Empty ; try { var firstLevel = true ; while ( node . Exists ) { var bnodes = node [ CONFIG_BEHAVIORS_SECTION ] . Children . Where ( c => c . IsSameName ( CONFIG_BEHAVIOR_SECTION ) && ( firstLevel || c . AttrByName ( CONFIG_CASCADE_ATTR ) . ValueAsBool ( false ) ) ) . OrderBy ( c => c . AttrByName ( Configuration . CONFIG_ORDER_ATTR ) . ValueAsInt ( ) ) ; foreach ( var bnode in bnodes ) { descr = " " . Args ( bnode . RootPath , bnode . AttrByName ( FactoryUtils . CONFIG_TYPE_ATTR ) . ValueAsString ( StringConsts . NULL_STRING ) ) ; var behavior = FactoryUtils . MakeAndConfigure < Behavior > ( bnode ) ; behavior . Apply ( target ) ; } node = node . Parent ; firstLevel = false ; } } catch ( Exception error ) { throw new BehaviorApplyException ( StringConsts . CONFIG_BEHAVIOR_APPLY_ERROR . Args ( descr , error . ToMessageWithType ( ) ) , error ) ; } }
Applies behaviors to instance as configured from config section node
Applies behaviors to instance as configured from config section node
target
object
node
IConfigSectionNode