当前位置: 首页>>代码示例>>C#>>正文


C# IConfigSectionNode.Navigate方法代码示例

本文整理汇总了C#中IConfigSectionNode.Navigate方法的典型用法代码示例。如果您正苦于以下问题:C# IConfigSectionNode.Navigate方法的具体用法?C# IConfigSectionNode.Navigate怎么用?C# IConfigSectionNode.Navigate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IConfigSectionNode的用法示例。


在下文中一共展示了IConfigSectionNode.Navigate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Apply

        /// <summary>
        /// Applies config values to fields/properties as specified by config attributes
        /// </summary>
        public static void Apply(object entity, IConfigSectionNode node)
        {
            if (entity==null || node==null) return;

             var etp = entity.GetType();

             //20130708 DKh - support for [ConfigMacroContext] injection
             var macroAttr = etp.GetCustomAttributes(typeof(ConfigMacroContextAttribute), true).FirstOrDefault() as ConfigMacroContextAttribute;
             if (macroAttr!=null)
             node.Configuration.MacroRunnerContext = entity;
             //---

             var cattr = etp.GetCustomAttributes(typeof(ConfigAttribute), true).FirstOrDefault() as ConfigAttribute;

             if (cattr!=null)//rebase root config node per supplied path
             {
               cattr.evalAttributeVars(etp);

               var path = cattr.Path ?? StringConsts.NULL_STRING;
               node = node.Navigate(path) as ConfigSectionNode;
               if (node==null)
            throw new ConfigException(string.Format(StringConsts.CONFIGURATION_NAVIGATION_REQUIRED_ERROR, cattr.Path));
             }

             var members =  getAllFieldsOrProps( etp );

             foreach(var mem in members)
             {
               var mattr = mem.GetCustomAttributes(typeof(ConfigAttribute), true).FirstOrDefault() as ConfigAttribute;
               if (mattr==null) continue;

               //20130708 DKh - default attribute name taken from member name if path==null
               if (string.IsNullOrWhiteSpace(mattr.Path))
                mattr.Path =  GetConfigPathsForMember(mem);
               //---

               mattr.evalAttributeVars(etp);

               var mnode = node.Navigate(mattr.Path);

               if (mem.MemberType == MemberTypes.Field)
               {
                 var finf = (FieldInfo)mem;

                 if (typeof(IConfigSectionNode).IsAssignableFrom(finf.FieldType))
                 {
                       if (finf.IsInitOnly)
                         throw new ConfigException(string.Format(StringConsts.CONFIGURATION_ATTRIBUTE_MEMBER_READONLY_ERROR, etp.FullName, finf.Name));

                       var snode = mnode as IConfigSectionNode;
                       if (snode==null)
                          throw new ConfigException(string.Format(StringConsts.CONFIGURATION_PATH_ICONFIGSECTION_SECTION_ERROR, etp.FullName, finf.Name));
                       finf.SetValue(entity, mnode);
                 }
                 else
                 if (typeof(IConfigurable).IsAssignableFrom(finf.FieldType))
                 {
                       var snode = mnode as IConfigSectionNode;
                       if (snode==null)
                          throw new ConfigException(string.Format(StringConsts.CONFIGURATION_PATH_ICONFIGURABLE_SECTION_ERROR, etp.FullName, finf.Name));

                       if (finf.GetValue(entity)!=null)
                         ((IConfigurable)finf.GetValue(entity)).Configure(snode);
                 }
                 else
                 {
                       if (finf.IsInitOnly)
                         throw new ConfigException(string.Format(StringConsts.CONFIGURATION_ATTRIBUTE_MEMBER_READONLY_ERROR, etp.FullName, finf.Name));

                       if (mnode.Exists && mnode.VerbatimValue!=null)
                        finf.SetValue(entity, getVal(mnode, finf.FieldType, etp.FullName, finf.Name));
                       else
                        if (mattr.Default!=null) finf.SetValue(entity, mattr.Default);

                 }

               }
               else
               if (mem.MemberType == MemberTypes.Property)
               {
                 var pinf = (PropertyInfo)mem;

                 if (typeof(IConfigSectionNode).IsAssignableFrom(pinf.PropertyType))
                 {
                       if (!pinf.CanWrite)
                         throw new ConfigException(string.Format(StringConsts.CONFIGURATION_ATTRIBUTE_MEMBER_READONLY_ERROR, etp.FullName, pinf.Name));

                       var snode = mnode as IConfigSectionNode;
                       if (snode==null)
                          throw new ConfigException(string.Format(StringConsts.CONFIGURATION_PATH_ICONFIGSECTION_SECTION_ERROR, etp.FullName, pinf.Name));
                       pinf.SetValue(entity, mnode, null);
                 }
                 else
                 if (typeof(IConfigurable).IsAssignableFrom(pinf.PropertyType))
                 {
                       var snode = mnode as IConfigSectionNode;
                       if (snode==null)
//.........这里部分代码省略.........
开发者ID:itadapter,项目名称:nfx,代码行数:101,代码来源:Attributes.cs

示例2: DoColumn

        /// <summary>
        /// Override to compile a RDBMS Table
        /// </summary>
        protected virtual void DoColumn(IConfigSectionNode columnNode, RDBMSEntity table, StringBuilder sb, ref bool firstColumn, Outputs outputs)
        {
            var colComment = columnNode.AttrByName(SCRIPT_COMMENT_ATTR).Value;
                if (colComment.IsNotNullOrWhiteSpace())
                    sb.AppendLine("  -- {0}".Args( colComment ) );

                var columnName = columnNode.Value;
                if (columnName.IsNullOrWhiteSpace())
                {
                  m_CompileErrors.Add(new SchemaCompilationException(columnNode.RootPath, "Table '{0}' missing column name.".Args(table.OriginalName)));
                  return;
                }

                var column = new RDBMSEntity(table, columnNode, RDBMSEntityType.Column, columnName, columnNode.AttrByName(SHORT_NAME_ATTR).Value ?? columnName);
                TransformEntityName(column);

                var typeNode = columnNode.Navigate(TYPE_ATTR + "|$"+TYPE_ATTR);
                if (typeNode==null || typeNode.VerbatimValue.IsNullOrWhiteSpace())
                {
                  m_CompileErrors.Add(new SchemaCompilationException(columnNode.RootPath, "Column '{0}' missing {1} attribute.".Args(columnName, TYPE_ATTR)));
                  return;
                }

                var columnType = typeNode.Value;
                var type = new RDBMSEntity(column, typeNode, RDBMSEntityType.Domain, columnType);
                TransformEntityName(type);

                var domain = CreateDomain("{0}.{1}::{2}".Args(table.OriginalName, column.OriginalName, type.OriginalName), type.OriginalName, typeNode);
                if (domain==null)
                {
                    m_CompileErrors.Add(new SchemaCompilationException(columnNode.RootPath, "Domain could not be created: " +type.TransformedName ));
                    return;
                }

                domain.TransformColumnName(this, column);

                if (!firstColumn) sb.AppendLine(",");

                #region Column Line
                {
                    var cn = GetQuotedIdentifierName(RDBMSEntityType.Column, column.TransformedName);
                    var tn = GetQuotedIdentifierName(RDBMSEntityType.Domain, domain.GetTypeName(this));
                    var required = (domain.GetColumnRequirement(this) ?? false) || columnNode.AttrByName(REQUIRED_ATTR).ValueAsBool();
                    var nn = TransformKeywordCase( GetColumnNullNotNullClause(column, required) );
                    var auto = domain.GetColumnAutoGeneratedScript(this, column, outputs);
                    var dfltValue = columnNode.AttrByName(DEFAULT_ATTR).Value ?? domain.GetColumnDefaultScript(this, column, outputs);
                    var dflt = dfltValue.IsNotNullOrWhiteSpace()? "{0} {1}".Args(TransformKeywordCase("default"), EscapeString(dfltValue)) : string.Empty;
                    var chk = domain.GetColumnCheckScript(this, column, outputs);
                    var cmntValue = columnNode.AttrByName(COMMENT_ATTR).Value;
                    var cmnt = cmntValue.IsNotNullOrWhiteSpace()? "{0} {1}".Args(TransformKeywordCase("comment"), EscapeString(cmntValue)) : string.Empty;
                    sb.Append( FormatColumnStatement(cn, tn, nn, auto, dflt, chk, cmnt) );
                }
                #endregion

                firstColumn = false;

                foreach(var colSubNode in columnNode.Children)
                {
                    if (colSubNode.IsSameName(PRIMARY_KEY_SECTION) || colSubNode.IsSameName(REFERENCE_SECTION))
                    {
                        var keyType = colSubNode.IsSameName(PRIMARY_KEY_SECTION) ? RDBMSEntityType.PrimaryKey : RDBMSEntityType.Reference;
                        var keyName = colSubNode.Value;
                        if (keyName.IsNullOrWhiteSpace())
                            keyName = column.OriginalShortName;
                        var key = new RDBMSEntity(column, colSubNode, keyType, keyName, colSubNode.AttrByName(SHORT_NAME_ATTR).Value);
                        TransformEntityName(key);
                    }
                    else  if (colSubNode.IsSameName(TYPE_ATTR)) { } //type may be used as section as well
                    else
                        m_CompileErrors.Add(new SchemaCompilationException(colSubNode.RootPath,
                                                                           "Unrecognized item inside '{0}.{1}' column, section '{2}'"
                                                                           .Args(table.OriginalName, columnName, colSubNode.Name)));
                }
        }
开发者ID:itadapter,项目名称:nfx,代码行数:77,代码来源:RDBMSCompiler.cs

示例3: Run

        public string Run(IConfigSectionNode node, string inputValue, string macroName, IConfigSectionNode macroParams, object context = null)
        {
            if (macroName.StartsWith(AS_PREFIX, StringComparison.InvariantCultureIgnoreCase) && macroName.Length > AS_PREFIX.Length)
            {
               var type = macroName.Substring(AS_PREFIX.Length);

               return GetValueAs(inputValue,
                                 type,
                                 macroParams.Navigate("$dflt|$default").Value,
                                 macroParams.Navigate("$fmt|$format").Value);

            }
            else if (string.Equals(macroName, "now", StringComparison.InvariantCultureIgnoreCase))
            {
               var utc = macroParams.AttrByName("utc").ValueAsBool(false);

               var fmt = macroParams.Navigate("$fmt|$format").ValueAsString();

               var valueAttr = macroParams.AttrByName("value");

               DateTime now;

               if (utc)
                    now = App.TimeSource.UTCNow;
               else
               {
                    ILocalizedTimeProvider timeProvider = App.Instance;

                    if (context is ILocalizedTimeProvider)
                        timeProvider = (ILocalizedTimeProvider) context;

                    now = timeProvider.LocalizedTime;
               }

               // We inspect the "value" param that may be provided for testing purposes
               if (valueAttr.Exists)
                   now = valueAttr.Value.AsDateTimeFormat(now, fmt,
                            utc ? DateTimeStyles.AssumeUniversal : DateTimeStyles.AssumeLocal);

               return fmt == null ? now.ToString() : now.ToString(fmt);
            }
            else if (string.Equals(macroName, "ctx-name", StringComparison.InvariantCultureIgnoreCase))
            {
               if (context is INamed)
                return ((INamed)context).Name;
            }

            return inputValue;
        }
开发者ID:itadapter,项目名称:nfx,代码行数:49,代码来源:MacroRunner.cs


注:本文中的IConfigSectionNode.Navigate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。