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


C# Util.StringTokenizer类代码示例

本文整理汇总了C#中NHibernate.Util.StringTokenizer的典型用法代码示例。如果您正苦于以下问题:C# StringTokenizer类的具体用法?C# StringTokenizer怎么用?C# StringTokenizer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StringTokenizer类属于NHibernate.Util命名空间,在下文中一共展示了StringTokenizer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NotSoSimpleWithDelimiters

		public void NotSoSimpleWithDelimiters()
		{
			string s = "The lazy... I don't know ";
			StringTokenizer st = new StringTokenizer(s, " .", true);
			IEnumerator enumerator = st.GetEnumerator();
			enumerator.MoveNext();
			Assert.AreEqual("The", (string) enumerator.Current, "Can't get first token");
			enumerator.MoveNext();
			Assert.AreEqual(" ", (string) enumerator.Current, "Can't get first space");
			enumerator.MoveNext();
			Assert.AreEqual("lazy", (string) enumerator.Current, "Can't get second token");
			enumerator.MoveNext();
			Assert.AreEqual(".", (string) enumerator.Current, "Can't get first dot");
			enumerator.MoveNext();
			Assert.AreEqual(".", (string) enumerator.Current, "Can't get second dot");
			enumerator.MoveNext();
			Assert.AreEqual(".", (string) enumerator.Current, "Can't get third dot");
			enumerator.MoveNext();
			Assert.AreEqual(" ", (string) enumerator.Current, "Can't get second space");
			enumerator.MoveNext();
			Assert.AreEqual("I", (string) enumerator.Current, "Can't get third token");
			enumerator.MoveNext();
			Assert.AreEqual(" ", (string) enumerator.Current, "Can't get third space");
			enumerator.MoveNext();
			Assert.AreEqual("don't", (string) enumerator.Current, "Can't get fourth token");
			enumerator.MoveNext();
			Assert.AreEqual(" ", (string) enumerator.Current, "Can't get fourth space");
			enumerator.MoveNext();
			Assert.AreEqual("know", (string) enumerator.Current, "Can't get fifth token");
			enumerator.MoveNext();
			Assert.AreEqual(" ", (string) enumerator.Current, "Can't get last space");
			Assert.AreEqual(false, enumerator.MoveNext(), "Still thinking there are more tokens");
		}
开发者ID:tkellogg,项目名称:NHibernate3-withProxyHooks,代码行数:33,代码来源:StringTokenizerFixture.cs

示例2: BindIndex

 protected static void BindIndex(XmlAttribute indexAttribute, Table table, Column column)
 {
     if (indexAttribute != null && table != null)
     {
         StringTokenizer tokens = new StringTokenizer(indexAttribute.Value, ", ");
         foreach (string token in tokens)
             table.GetOrCreateIndex(token).AddColumn(column);
     }
 }
开发者ID:aistrate,项目名称:TypingPracticeTexts,代码行数:9,代码来源:ClassBinder.cs

示例3: Parse

		public static void Parse(IParser p, string text, string seperators, QueryTranslator q)
		{
			StringTokenizer tokens = new StringTokenizer(text, seperators, true);
			p.Start(q);
			foreach (string token in tokens)
			{
				p.Token(token, q);
			}
			p.End(q);
		}
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:10,代码来源:ParserHelper.cs

示例4: SimpleStringWithoutDelimiters

		public void SimpleStringWithoutDelimiters()
		{
			string s = "Hello world!";
			StringTokenizer st = new StringTokenizer(s);
			IEnumerator enumerator = st.GetEnumerator();
			enumerator.MoveNext();
			Assert.AreEqual("Hello", (string) enumerator.Current, "Can't get first token");
			enumerator.MoveNext();
			Assert.AreEqual("world!", (string) enumerator.Current, "Can't get second token");
			Assert.AreEqual(false, enumerator.MoveNext(), "Still thinking there are more tokens");
		}
开发者ID:tkellogg,项目名称:NHibernate3-withProxyHooks,代码行数:11,代码来源:StringTokenizerFixture.cs

示例5: Format

        private static string Format(string sql)
        {
            if (sql.IndexOf("\"") > 0 || sql.IndexOf("'") > 0)
            {
                return sql;
            }

            string formatted;

            if (sql.ToLower(System.Globalization.CultureInfo.InvariantCulture).StartsWith("create table"))
            {
                StringBuilder result = new StringBuilder(60);
                StringTokenizer tokens = new StringTokenizer(sql, "(,)", true);

                int depth = 0;

                foreach (string tok in tokens)
                {
                    if (StringHelper.ClosedParen.Equals(tok))
                    {
                        depth--;
                        if (depth == 0)
                        {
                            result.AppendLine();
                        }
                    }
                    result.Append(tok);
                    if (StringHelper.Comma.Equals(tok) && depth == 1)
                    {
                        result.AppendLine().Append(' ');
                    }
                    if (StringHelper.OpenParen.Equals(tok))
                    {
                        depth++;
                        if (depth == 1)
                        {
                            result.AppendLine().Append(' ');
                        }
                    }
                }

                formatted = result.ToString();
            }
            else
            {
                formatted = sql;
            }

            return formatted;
        }
开发者ID:andreyu,项目名称:Reports,代码行数:50,代码来源:Program.cs

示例6: ToDictionary

		/// <summary>
		/// 
		/// </summary>
		/// <param name="property"></param>
		/// <param name="delim"></param>
		/// <param name="properties"></param>
		/// <returns></returns>
		public static IDictionary ToDictionary( string property, string delim, IDictionary properties )
		{
			IDictionary map = new Hashtable();
			string propValue = ( string ) properties[ property ];
			if( propValue != null )
			{
				StringTokenizer tokens = new StringTokenizer( propValue, delim, false );
				IEnumerator en = tokens.GetEnumerator();
				while( en.MoveNext() )
				{
					string key = ( string ) en.Current;

					string value = en.MoveNext() ? ( string ) en.Current : String.Empty;
					map[ key ] = value;
				}
			}
			return map;
		}
开发者ID:rcarrillopadron,项目名称:nhibernate-1.0.2.0,代码行数:25,代码来源:PropertiesHelper.cs

示例7: ToDictionary

		public static IDictionary<string, string> ToDictionary(string property, string delim, IDictionary<string, string> properties)
		{
			IDictionary<string, string> map = new Dictionary<string, string>();
			
			if (properties.ContainsKey(property))
			{
				string propValue = properties[property];
				StringTokenizer tokens = new StringTokenizer(propValue, delim, false);
				IEnumerator<string> en = tokens.GetEnumerator();
				while (en.MoveNext())
				{
					string key = en.Current;

					string value = en.MoveNext() ? en.Current : String.Empty;
					map[key] = value;
				}
			}
			return map;
		}
开发者ID:khaliyo,项目名称:Spring.net-NHibernate.net-Asp.net-MVC-DWZ-,代码行数:19,代码来源:PropertiesHelper.cs

示例8: Split

		/// <summary>
		/// Splits the String using the StringTokenizer.  
		/// </summary>
		/// <param name="separators">separators for the tokens of the list</param>
		/// <param name="list">the string that will be broken into tokens</param>
		/// <param name="include">true to include the separators in the tokens.</param>
		/// <returns></returns>
		/// <remarks>
		/// This is more powerful than Split because you have the option of including or 
		/// not including the separators in the tokens.
		/// </remarks>
		public static string[] Split(string separators, string list, bool include)
		{
			var tokens = new StringTokenizer(list, separators, include);
			return tokens.ToArray();
		}
开发者ID:peterbeams,项目名称:nhibernate-core,代码行数:16,代码来源:StringHelper.cs

示例9: Format

        /// <summary>
        /// Format an SQL statement using simple rules
        /// </summary>
        /// <param name="sql">The string containing the sql to format.</param>
        /// <returns>A string that contains formatted sql.</returns>
        /// <remarks>
        /// The simple rules to used when formatting are:
        /// <list type="number">
        ///		<item>
        ///			<description>Insert a newline after each comma</description>
        ///		</item>
        ///		<item>
        ///			<description>Indent three spaces after each inserted newline</description>
        ///		</item>
        ///		<item>
        ///			<description>
        ///			If the statement contains single/double quotes return unchanged because
        ///			it is too complex and could be broken by simple formatting.
        ///			</description>
        ///		</item>
        /// </list>
        /// </remarks>
        private static string Format(string sql)
        {
            if (sql.IndexOf("\"") > 0 || sql.IndexOf("'") > 0)
            {
                return sql;
            }

            string formatted;

            if (StringHelper.StartsWithCaseInsensitive(sql, "create table"))
            {
                StringBuilder result = new StringBuilder(60);
                StringTokenizer tokens = new StringTokenizer(sql, "(,)", true);

                int depth = 0;

                foreach (string tok in tokens)
                {
                    if (StringHelper.ClosedParen.Equals(tok))
                    {
                        depth--;
                        if (depth == 0)
                        {
                            result.Append("\n");
                        }
                    }
                    result.Append(tok);
                    if (StringHelper.Comma.Equals(tok) && depth == 1)
                    {
                        result.Append("\n  ");
                    }
                    if (StringHelper.OpenParen.Equals(tok))
                    {
                        depth++;
                        if (depth == 1)
                        {
                            result.Append("\n  ");
                        }
                    }
                }

                formatted = result.ToString();
            }
            else
            {
                formatted = sql;
            }

            return formatted;
        }
开发者ID:pallmall,项目名称:WCell,代码行数:72,代码来源:SchemaExport.cs

示例10: DoPathExpression

		private void DoPathExpression(string token, QueryTranslator q)
		{
			Preprocess(token, q);

			StringTokenizer tokens = new StringTokenizer(token, ".", true);
			pathExpressionParser.Start(q);
			foreach (string tok in tokens)
			{
				pathExpressionParser.Token(tok, q);
			}
			pathExpressionParser.End(q);

			if (pathExpressionParser.IsCollectionValued)
			{
				OpenExpression(q, string.Empty);
				AppendToken(q, pathExpressionParser.GetCollectionSubquery(q.EnabledFilters));
				CloseExpression(q, string.Empty);
				// this is ugly here, but needed because its a subquery
				q.AddQuerySpaces(q.GetCollectionPersister(pathExpressionParser.CollectionRole).CollectionSpaces);
			}
			else
			{
				if (pathExpressionParser.IsExpectingCollectionIndex)
				{
					expectingIndex++;
				}
				else
				{
					AddJoin(pathExpressionParser.WhereJoin, q);
					AppendToken(q, pathExpressionParser.WhereColumn);
				}
			}
		}
开发者ID:nikson,项目名称:nhibernate-core,代码行数:33,代码来源:WhereParser.cs

示例11: ProcessFilters

		public void ProcessFilters(SqlString sql, ISessionImplementor session)
		{
			filteredParameterValues = new List<object>();
			filteredParameterTypes = new List<IType>();
			filteredParameterLocations = new List<int>();

			if (session.EnabledFilters.Count == 0 || sql.ToString().IndexOf(ParserHelper.HqlVariablePrefix) < 0)
			{
				processedSQL = sql.Copy();
				return;
			}

			Dialect.Dialect dialect = session.Factory.Dialect;
			string symbols = ParserHelper.HqlSeparators + dialect.OpenQuote + dialect.CloseQuote;

			var result = new SqlStringBuilder();

			int originalParameterIndex = 0; // keep track of the positional parameter
			int newParameterIndex = 0;
			_adjustedParameterLocations = new Dictionary<int, int>();

			foreach (var part in sql.Parts)
			{
				if (part is Parameter)
				{
					result.AddParameter();

					// (?) can be a position parameter or a named parameter (already substituted by (?),
					// but only the positional parameters are available at this point. Adding them in the
					// order of appearance is best that can be done at this point of time, but if they
					// are mixed with named parameters, the order is still wrong, because values and
					// types for the named parameters are added later to the end of the list.
					// see test fixture NH-1098

					_adjustedParameterLocations[originalParameterIndex] = newParameterIndex;
					originalParameterIndex++;
					newParameterIndex++;
					continue;
				}

				var tokenizer = new StringTokenizer((string) part, symbols, true);

				foreach (var token in tokenizer)
				{
					if (token.StartsWith(ParserHelper.HqlVariablePrefix))
					{
						string filterParameterName = token.Substring(1);
						object value = session.GetFilterParameterValue(filterParameterName);
						IType type = session.GetFilterParameterType(filterParameterName);

						// If the value is not a value of the type but a collection of values...
						if (value != null && !type.ReturnedClass.IsAssignableFrom(value.GetType()) && // Added to fix NH-882
						    typeof (ICollection).IsAssignableFrom(value.GetType()))
						{
							var coll = (ICollection) value;
							int i = 0;
							foreach (var elementValue in coll)
							{
								i++;
								int span = type.GetColumnSpan(session.Factory);
								if (span > 0)
								{
									result.AddParameter();
									filteredParameterTypes.Add(type);
									filteredParameterValues.Add(elementValue);
									filteredParameterLocations.Add(newParameterIndex);
									newParameterIndex++;
									if (i < coll.Count)
									{
										result.Add(", ");
									}
								}
							}
						}
						else
						{
							int span = type.GetColumnSpan(session.Factory);
							if (span > 0)
							{
								result.AddParameter();
								filteredParameterTypes.Add(type);
								filteredParameterValues.Add(value);
								filteredParameterLocations.Add(newParameterIndex);
								newParameterIndex++;
							}
						}
					}
					else
					{
						result.Add(token);
					}
				}
			}

			processedSQL = result.ToSqlString();
		}
开发者ID:tkellogg,项目名称:NHibernate3-withProxyHooks,代码行数:96,代码来源:QueryParameters.cs

示例12: ExpandDynamicFilterParameters

		protected SqlString ExpandDynamicFilterParameters(SqlString sqlString, ICollection<IParameterSpecification> parameterSpecs, ISessionImplementor session)
		{
			var enabledFilters = session.EnabledFilters;
			if (enabledFilters.Count == 0 || sqlString.ToString().IndexOf(ParserHelper.HqlVariablePrefix) < 0)
			{
				return sqlString;
			}

			Dialect.Dialect dialect = session.Factory.Dialect;
			string symbols = ParserHelper.HqlSeparators + dialect.OpenQuote + dialect.CloseQuote;

			var originSql = sqlString.Compact();
			var result = new SqlStringBuilder();
			foreach (var sqlPart in originSql.Parts)
			{
				var parameter = sqlPart as Parameter;
				if (parameter != null)
				{
					result.Add(parameter);
					continue;
				}

				var sqlFragment = sqlPart.ToString();
				var tokens = new StringTokenizer(sqlFragment, symbols, true);

				foreach (string token in tokens)
				{
					if (token.StartsWith(ParserHelper.HqlVariablePrefix))
					{
						string filterParameterName = token.Substring(1);
						string[] parts = StringHelper.ParseFilterParameterName(filterParameterName);
						string filterName = parts[0];
						string parameterName = parts[1];
						var filter = (FilterImpl)enabledFilters[filterName];

						object value = filter.GetParameter(parameterName);
						IType type = filter.FilterDefinition.GetParameterType(parameterName);
						int parameterColumnSpan = type.GetColumnSpan(session.Factory);
						var collectionValue = value as ICollection;
						int? collectionSpan = null;

						// Add query chunk
						string typeBindFragment = string.Join(", ", Enumerable.Repeat("?", parameterColumnSpan).ToArray());
						string bindFragment;
						if (collectionValue != null && !type.ReturnedClass.IsArray)
						{
							collectionSpan = collectionValue.Count;
							bindFragment = string.Join(", ", Enumerable.Repeat(typeBindFragment, collectionValue.Count).ToArray());
						}
						else
						{
							bindFragment = typeBindFragment;
						}

						// dynamic-filter parameter tracking
						var filterParameterFragment = SqlString.Parse(bindFragment);
						var dynamicFilterParameterSpecification = new DynamicFilterParameterSpecification(filterName, parameterName, type, collectionSpan);
						var parameters = filterParameterFragment.GetParameters().ToArray();
						var sqlParameterPos = 0;
						var paramTrackers = dynamicFilterParameterSpecification.GetIdsForBackTrack(session.Factory);
						foreach (var paramTracker in paramTrackers)
						{
							parameters[sqlParameterPos++].BackTrack = paramTracker;
						}

						parameterSpecs.Add(dynamicFilterParameterSpecification);
						result.Add(filterParameterFragment);
					}
					else
					{
						result.Add(token);
					}
				}
			}
			return result.ToSqlString().Compact();
		}
开发者ID:henryjwr,项目名称:nhibernate-core,代码行数:76,代码来源:Loader.cs

示例13: AddColumnsFromList

        private void AddColumnsFromList(HbmId idSchema, SimpleValue id)
        {
            int count = 0;

            foreach (HbmColumn columnSchema in idSchema.column ?? new HbmColumn[0])
            {
                Column column = CreateColumn(columnSchema, id, count++);
                column.Name = mappings.NamingStrategy.ColumnName(columnSchema.name);

                if (id.Table != null)
                    id.Table.AddColumn(column);
                //table=null -> an association, fill it in later

                id.AddColumn(column);

                if (columnSchema.index != null && id.Table != null)
                {
                    StringTokenizer tokens = new StringTokenizer(columnSchema.index, ", ");
                    foreach (string token in tokens)
                        id.Table.GetOrCreateIndex(token).AddColumn(column);
                }

                if (columnSchema.uniquekey != null && id.Table != null)
                {
                    StringTokenizer tokens = new StringTokenizer(columnSchema.uniquekey, ", ");
                    foreach (string token in tokens)
                        id.Table.GetOrCreateUniqueKey(token).AddColumn(column);
                }
            }
        }
开发者ID:zibler,项目名称:zibler,代码行数:30,代码来源:ClassIdBinder.cs

示例14: Replace

        private string Replace(string message, object entity)
        {
            var tokens = new StringTokenizer(message, "#${}", true);
            var buf = new StringBuilder(100);
            var escaped = false;
            var el = false;
            var isMember = false;

            IEnumerator ie = tokens.GetEnumerator();

            while (ie.MoveNext())
            {
                string token = (string) ie.Current;

                if (!escaped && "#".Equals(token))
                {
                    el = true;
                }

                if(!el && ("$".Equals(token)))
                {
                    isMember = true;
                }
                else if("}".Equals(token) && isMember)
                {
                    isMember = false;
                }
                if (!el && "{".Equals(token))
                {
                    escaped = true;
                }
                else if (escaped && "}".Equals(token))
                {
                    escaped = false;
                }
                else if (!escaped)
                {
                    if ("{".Equals(token))
                    {
                        el = false;
                    }

                    if(!"$".Equals(token)) buf.Append(token);
                }
                else if(!isMember)
                {
                    object variable;
                    if (attributeParameters.TryGetValue(token.ToLowerInvariant(), out variable))
                    {
                        buf.Append(variable);
                    }
                    else
                    {
                        string _string = null;
                        try
                        {
                            _string = messageBundle != null ? messageBundle.GetString(token, culture) : null;
                        }
                        catch (MissingManifestResourceException)
                        {
                            //give a second chance with the default resource bundle
                        }
                        if (_string == null)
                        {
                            _string = defaultMessageBundle.GetString(token, culture);
                            // in this case we don't catch the MissingManifestResourceException because
                            // we are sure that we DefaultValidatorMessages.resx is an embedded resource
                        }
                        if (_string == null)
                        {
                            buf.Append('{').Append(token).Append('}');
                        }
                        else
                        {
                            buf.Append(Replace(_string,entity));
                        }
                    }
                }
                else
                {
                    ReplaceValue(buf, entity, token);
                }
            }
            return buf.ToString();
        }
开发者ID:mpielikis,项目名称:nhibernate-contrib,代码行数:85,代码来源:DefaultMessageInterpolator.cs

示例15: GetPathInfo

		private ICriteriaInfoProvider GetPathInfo(string path)
		{
			StringTokenizer tokens = new StringTokenizer(path, ".", false);
			string componentPath = string.Empty;

			// start with the 'rootProvider'
			ICriteriaInfoProvider provider;
			if (nameCriteriaInfoMap.TryGetValue(rootEntityName, out provider) == false)
				throw new ArgumentException("Could not find ICriteriaInfoProvider for: " + path);


			foreach (string token in tokens)
			{
				componentPath += token;
				logger.DebugFormat("searching for {0}", componentPath);
				IType type = provider.GetType(componentPath);
				if (type.IsAssociationType)
				{
					// CollectionTypes are always also AssociationTypes - but there's not always an associated entity...
					IAssociationType atype = (IAssociationType)type;

					CollectionType ctype = type.IsCollectionType ? (CollectionType)type : null;
					IType elementType = (ctype != null) ? ctype.GetElementType(sessionFactory) : null;
					// is the association a collection of components or value-types? (i.e a colloction of valued types?)
					if (ctype != null && elementType.IsComponentType)
					{
						provider = new ComponentCollectionCriteriaInfoProvider(helper.GetCollectionPersister(ctype.Role));
					}
					else if (ctype != null && !elementType.IsEntityType)
					{
						provider = new ScalarCollectionCriteriaInfoProvider(helper, ctype.Role);
					}
					else
					{
						provider = new EntityCriteriaInfoProvider((NHibernate_Persister_Entity.IQueryable)sessionFactory.GetEntityPersister(
																				   atype.GetAssociatedEntityName(
																					   sessionFactory)
																				   ));
					}

					componentPath = string.Empty;
				}
				else if (type.IsComponentType)
				{
					componentPath += '.';
				}
				else
				{
					throw new QueryException("not an association: " + componentPath);
				}
			}

			logger.DebugFormat("returning entity name={0} for path={1} class={2}",
				provider.Name, path, provider.GetType().Name);
			return provider;
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:56,代码来源:CriteriaQueryTranslator.cs


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