• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Binder.CompositeNode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: PopulateTree

		/// <summary>
		/// 
		/// </summary>
		/// <param name="root"></param>
		/// <param name="reader"></param>
		/// <param name="prefix"></param>
		public void PopulateTree(CompositeNode root, IDataReader reader, String prefix)
		{
			string[] fields = GetFields(reader);

			int[] indexesToSkip = FindDuplicateFields(fields);
			
			IndexedNode indexNode = new IndexedNode(prefix);
			
			int row = 0;

			while(reader.Read())
			{
				CompositeNode node = new CompositeNode(row.ToString());

				for(int i=0; i<reader.FieldCount; i++)
				{
					// Is in the skip list?
					if (Array.IndexOf(indexesToSkip, i) >= 0) continue;
					
					// Is null?
					if (reader.IsDBNull(i)) continue;
					
					Type fieldType = reader.GetFieldType(i);
					
					node.AddChildNode(new LeafNode(fieldType, fields[i], reader.GetValue(i)));
				}

				indexNode.AddChildNode(node);
			
				row++;
			}
			
			root.AddChildNode(indexNode);
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:40,代码来源:DataReaderTreeBuilder.cs


示例2: BuildNode

		public CompositeNode BuildNode(XDocument doc)
		{
			var rootNode = new CompositeNode("root");
			rootNode.AddChildNode(ProcessElement(doc.Root));
			return rootNode;

		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:7,代码来源:XmlTreeBuilder.cs


示例3: PopulateTree

		public void PopulateTree(CompositeNode root, NameValueCollection nameValueCollection)
		{
			foreach (String key in nameValueCollection.Keys)
			{
				if (key == null) continue;
				string singleKeyName = NormalizeKey(key);
				String[] values = nameValueCollection.GetValues(key);

				if (values == null) continue;

				if (values.Length == 1 && key.EndsWith("[]"))
				{
					if (values[0] == string.Empty)
					{
						ProcessNode(root, typeof (String[]), singleKeyName, new string[0]);
					}
					else
					{
						values = values[0].Split(',');
						ProcessNode(root, typeof (String[]), singleKeyName, values);
					}
				}
				else if (values.Length == 1)
				{
					ProcessNode(root, typeof (String), key, values[0]);
				}
				else
				{
					ProcessNode(root, typeof (String[]), singleKeyName, values);
				}
			}
		}
开发者ID:gitter-badger,项目名称:Core-8,代码行数:32,代码来源:TreeBuilder.cs


示例4: CanBindParameter

		public bool CanBindParameter(Type desiredType, String paramName, CompositeNode treeRoot)
		{
			bool canConvert;

			Node childNode = treeRoot.GetChildNode(paramName);

			if (childNode != null)
			{
				canConvert = true;
			}
			else if (desiredType == typeof (DateTime))
			{
				TrySpecialDateTimeBinding(desiredType, treeRoot, paramName, out canConvert);
			}
			else if (desiredType == typeof(DateTimeOffset))
			{
				TrySpecialDateTimeOffsetBinding(desiredType, treeRoot, paramName, out canConvert);
			}
			else
			{
				canConvert = false;
			}

			return canConvert;
		}
开发者ID:radiy,项目名称:Castle.Components.Binder,代码行数:25,代码来源:DataBinder.cs


示例5: ProcessElement

		public Node ProcessElement(XElement startEl)
		{
			if (IsComplex(startEl))
			{
				CompositeNode top = new CompositeNode(startEl.Name.LocalName);
				foreach (var attr in startEl.Attributes())
				{
					var leaf = new LeafNode(typeof(String), attr.Name.LocalName, attr.Value);
					top.AddChildNode(leaf);
				}
				foreach (var childEl in startEl.Elements())
				{
					var childNode = ProcessElement(childEl);
					top.AddChildNode(childNode);
				}

				return top;
			}
			else
			{
				LeafNode top = new LeafNode(typeof(String), "", "");
				return top;
			}

			
		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:26,代码来源:XmlTreeBuilder.cs


示例6: GetParamsNode

		private static CompositeNode GetParamsNode(int expectedValue)
		{
			CompositeNode paramsNode = new CompositeNode("root");
			IndexedNode listNode = new IndexedNode("myList");
			paramsNode.AddChildNode(listNode);
			listNode.AddChildNode(new LeafNode(typeof(int), "", expectedValue));
			return paramsNode;
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:8,代码来源:GenericBindingTestCase.cs


示例7: BuildSourceNode

		public CompositeNode BuildSourceNode(NameValueCollection nameValueCollection)
		{
			var root = new CompositeNode("root");

			PopulateTree(root, nameValueCollection);

			return root;
		}
开发者ID:gitter-badger,项目名称:Core-8,代码行数:8,代码来源:TreeBuilder.cs


示例8: BuildSourceNode

		/// <summary>
		/// 
		/// </summary>
		/// <param name="reader"></param>
		/// <param name="prefix"></param>
		/// <returns></returns>
		public CompositeNode BuildSourceNode(IDataReader reader, String prefix)
		{
			CompositeNode root = new CompositeNode("root");
			
			PopulateTree(root, reader, prefix);
			
			return root;
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:14,代码来源:DataReaderTreeBuilder.cs


示例9: ConvertToSimpleValue

		private object ConvertToSimpleValue(Type desiredType, string key, CompositeNode parent, out bool conversionSucceeded)
		{
			conversionSucceeded = false;

			Node childNode = parent.GetChildNode(key);

			if (childNode == null && IsDateTimeType(desiredType))
			{
				return TrySpecialDateTimeBinding(desiredType, parent, key, out conversionSucceeded);
			}
			else if (childNode == null)
			{
				return null;
			}
			else if (childNode.NodeType == NodeType.Leaf)
			{
				return ConvertLeafNode(desiredType, (LeafNode) childNode, out conversionSucceeded);
			}
			else
			{
				throw new BindingException("Could not convert param as the node related " +
				                           "to the param is not a leaf node. Param {0} parent node: {1}", key, parent.Name);
			}
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:24,代码来源:DataBinder.cs


示例10: BeforeBindingProperty

		protected virtual void BeforeBindingProperty(object instance, PropertyInfo prop, string prefix, CompositeNode node)
		{
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:3,代码来源:DataBinder.cs


示例11: CheckForValidationFailures

		protected bool CheckForValidationFailures(object instance, Type instanceType,
		                                          PropertyInfo prop, CompositeNode node,
		                                          string name, string prefix,
		                                          ErrorSummary summary)
		{
			object value = null;

			if (validator == null)
			{
				return false;
			}

			IValidator[] validators = validator.GetValidators(instanceType, prop);

			if (validators.Length != 0)
			{
				Node valNode = node.GetChildNode(name);

				if (valNode != null && valNode.NodeType == NodeType.Leaf)
				{
					value = ((LeafNode)valNode).Value;
				}

				if (value == null && IsDateTimeType(prop.PropertyType))
				{
					bool conversionSucceeded;
					value = TryGetDateWithUTCFormat(node, name, out conversionSucceeded);
				}

				if (value == null && valNode == null)
				{
					// Value was not present on the data source. Skip validation
					return false;
				}
			}

			return CheckForValidationFailures(instance, instanceType, prop, value, name, prefix, summary);
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:38,代码来源:DataBinder.cs


示例12: InternalRecursiveBindObjectInstance

		protected void InternalRecursiveBindObjectInstance(object instance, String prefix, CompositeNode node)
		{
			if (node == null || instance == null)
			{
				return;
			}

			BeforeBinding(instance, prefix, node);

			if (PerformCustomBinding(instance, prefix, node))
			{
				return;
			}

			PushInstance(instance, prefix);

			ErrorSummary summary = new ErrorSummary();

			validationErrorSummaryPerInstance[instance] = summary;

			Type instanceType = instance.GetType();

			PropertyInfo[] props = instanceType.GetProperties(PropertiesBindingFlags);

			string nodeFullName = node.FullName;

			foreach(PropertyInfo prop in props)
			{
				if (ShouldIgnoreProperty(prop, nodeFullName))
				{
					continue;
				}

				Type propType = prop.PropertyType;
				String paramName = prop.Name;

				String translatedParamName = Translate(instanceType, paramName);

				if (translatedParamName == null)
				{
					continue;
				}

				bool isSimpleProperty = IsSimpleProperty(propType);

				// There are some caveats by running the validators here. 
				// We should follow the validator's execution order...
				if (isSimpleProperty)
				{
					if (CheckForValidationFailures(instance, instanceType, prop, node, translatedParamName, prefix, summary))
					{
						continue;
					}
				}

				BeforeBindingProperty(instance, prop, prefix, node);

				try
				{
					bool conversionSucceeded;

					if (isSimpleProperty)
					{
						object value = ConvertToSimpleValue(propType, translatedParamName, node, out conversionSucceeded);

						if (conversionSucceeded)
						{
							SetPropertyValue(instance, prop, value);
						}
					}
					else
					{
						// if the property is an object, we look if it is already instanciated
						object value = prop.GetValue(instance, null);

						Node nestedNode = node.GetChildNode(paramName);

						if (nestedNode != null)
						{
							if (ShouldRecreateInstance(value, propType, paramName, nestedNode))
							{
								value = InternalBindObject(propType, paramName, nestedNode, out conversionSucceeded);

								if (conversionSucceeded)
								{
									SetPropertyValue(instance, prop, value);
								}
							}
							else
							{
								InternalRecursiveBindObjectInstance(value, paramName, nestedNode);
							}
						}

						CheckForValidationFailures(instance, instanceType, prop, value, translatedParamName, prefix, summary);
					}
				}
				catch(Exception ex)
				{
					errors.Add(new DataBindError(prefix, prop.Name, ex));
//.........这里部分代码省略.........
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:101,代码来源:DataBinder.cs


示例13: GetOrCreateIndexedNode

		private IndexedNode GetOrCreateIndexedNode(CompositeNode parent, string nodeName)
		{
			Node node = parent.GetChildNode(nodeName);

			if (node != null && node.NodeType != NodeType.Indexed)
			{
				throw new BindingException("Attempt to create or obtain an indexed node " +
				                           "named {0}, but a node with the same exists with the type {1}", nodeName, node.NodeType);
			}

			if (node == null)
			{
				node = new IndexedNode(nodeName);
				parent.AddChildNode(node);
			}

			return (IndexedNode) node;
		}
开发者ID:gitter-badger,项目名称:Core-8,代码行数:18,代码来源:TreeBuilder.cs


示例14: IsPropertyExpected

		private bool IsPropertyExpected(PropertyInfo prop, CompositeNode node)
		{
			var propId = string.Format("{0}.{1}", node.FullName, prop.Name);

			if (expectCollPropertiesList != null)
			{
				return Array.BinarySearch(expectCollPropertiesList, propId, CaseInsensitiveComparer.Default) >= 0;
			}

			return false;
		}
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:11,代码来源:ARDataBinder.cs


示例15: BindObject

		public object BindObject(Type targetType, string prefix, string exclude, string allow, string expect,
								 CompositeNode treeRoot)
		{
			expectCollPropertiesList = CreateNormalizedList(expect);

			return BindObject(targetType, prefix, exclude, allow, treeRoot);
		}
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:7,代码来源:ARDataBinder.cs


示例16: BindObject

		public object BindObject(Type targetType, string prefix, CompositeNode treeRoot)
		{
			return BindObject(targetType, prefix, null, null, treeRoot);
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:4,代码来源:DataBinder.cs


示例17: BindParameter

		public object BindParameter(Type desiredType, String paramName, CompositeNode treeRoot)
		{
			bool conversionSucceeded;
			object result;

			try
			{
				if (desiredType.IsArray)
				{
					Node childNode = treeRoot.GetChildNode(paramName);

					result = ConvertToArray(desiredType, paramName, childNode, out conversionSucceeded);
				}
				else
				{
					result = ConvertToSimpleValue(desiredType, paramName, treeRoot, out conversionSucceeded);
				}
			}
			catch(Exception ex)
			{
				// Something unexpected during convertion
				// throw new exception with paramName specified

				throw new BindingException(
					"Exception converting param '" + paramName + "' to " + desiredType + ". Check inner exception for details", ex);
			}

			return result;
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:29,代码来源:DataBinder.cs


示例18: CanBindObject

		public bool CanBindObject(Type targetType, String prefix, CompositeNode treeRoot)
		{
			Node childNode = treeRoot.GetChildNode(prefix);

			return childNode != null;
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:6,代码来源:DataBinder.cs


示例19: ProcessNode

		protected void ProcessNode(CompositeNode node, Type type, String name, object value)
		{
			if (name == null || name == String.Empty)
			{
				// Ignore
				return;
			}
			if (name[0] == '.' || name[0] == '[' || name[0] == ']')
			{
				AddLeafNode(node, type, name, value);
				return;
			}

			int dotIndex = name.IndexOf('.');
			int startBracketIndex = name.IndexOf('[');

			if (dotIndex != -1 && (startBracketIndex == -1 || dotIndex < startBracketIndex))
			{
				// Child node

				String childNodeName = name.Substring(0, dotIndex);

				CompositeNode newNode = GetOrCreateCompositeNode(node, childNodeName);

				ProcessNode(newNode, type, name.Substring(dotIndex + 1), value);
			}
			else if (startBracketIndex != -1)
			{
				// Indexed node

				int endBracket = name.IndexOf(']');

				if (endBracket == -1)
				{
					// TODO: Something is wrong
				}

				String enclosed = name.Substring(startBracketIndex + 1, endBracket - startBracketIndex - 1);

				if (enclosed == null || enclosed == String.Empty)
				{
					// TODO: Something is wrong
				}

				String indexedNodeName = name.Substring(0, startBracketIndex);

				CompositeNode newNode = GetOrCreateIndexedNode(node, indexedNodeName);

				if (endBracket + 1 == name.Length) // entries like emails[0] = value
				{
					AddLeafNode(newNode, type, value);
				}
				else
				{
					name = name.Substring(endBracket + 2); // entries like customer[0].name = value

					newNode = GetOrCreateCompositeNode(newNode, enclosed);

					ProcessNode(newNode, type, name, value);
				}
			}
			else
			{
				AddLeafNode(node, type, name, value);
			}
		}
开发者ID:gitter-badger,项目名称:Core-8,代码行数:66,代码来源:TreeBuilder.cs


示例20: AddLeafNode

		private void AddLeafNode(CompositeNode parent, Type type, object value)
		{
			AddLeafNode(parent, type, String.Empty, value);
		}
开发者ID:gitter-badger,项目名称:Core-8,代码行数:4,代码来源:TreeBuilder.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DictionaryAdapter.PropertyDescriptor类代码示例发布时间:2022-05-24
下一篇:
C# Model.Blog类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap