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


C# CompositeNode.GetChildNode方法代码示例

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


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

示例1: 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

示例2: ObtainPrimaryKeyValue

		private object ObtainPrimaryKeyValue(ActiveRecordModel model, CompositeNode node, String prefix,
											 out PrimaryKeyModel pkModel)
		{
			pkModel = ObtainPrimaryKey(model);

			var pkPropName = pkModel.Property.Name;

			var idNode = node.GetChildNode(pkPropName);

			if (idNode == null) return null;

			if (idNode != null && idNode.NodeType != NodeType.Leaf)
			{
				throw new BindingException("Expecting leaf node to contain id for ActiveRecord class. " +
										   "Prefix: {0} PK Property Name: {1}", prefix, pkPropName);
			}

			var lNode = (LeafNode) idNode;

			if (lNode == null)
			{
				throw new BindingException("ARDataBinder autoload failed as element {0} " +
										   "doesn't have a primary key {1} value", prefix, pkPropName);
			}

			bool conversionSuc;

			return Converter.Convert(pkModel.Property.PropertyType, lNode.ValueType, lNode.Value, out conversionSuc);
		}
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:29,代码来源:ARDataBinder.cs

示例3: TryGetDateWithUTCFormat

		private string TryGetDateWithUTCFormat(CompositeNode treeRoot, string paramName, out bool conversionSucceeded)
		{
			// YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
			string fullDateTime = "";
			conversionSucceeded = false;

			Node dayNode = treeRoot.GetChildNode(paramName + "day");
			Node monthNode = treeRoot.GetChildNode(paramName + "month");
			Node yearNode = treeRoot.GetChildNode(paramName + "year");

			Node hourNode = treeRoot.GetChildNode(paramName + "hour");
			Node minuteNode = treeRoot.GetChildNode(paramName + "minute");
			Node secondNode = treeRoot.GetChildNode(paramName + "second");

			if (dayNode != null)
			{
				int day = (int) RelaxedConvertLeafNode(typeof(int), dayNode, 0);
				int month = (int) RelaxedConvertLeafNode(typeof(int), monthNode, 0);
				int year = (int) RelaxedConvertLeafNode(typeof(int), yearNode, 0);

				fullDateTime = string.Format("{0:0000}-{1:00}-{2:00}", year, month, day);
				conversionSucceeded = true;
			}

			if (hourNode != null)
			{
				int hour = (int) RelaxedConvertLeafNode(typeof(int), hourNode, 0);
				int minute = (int) RelaxedConvertLeafNode(typeof(int), minuteNode, 0);
				int second = (int) RelaxedConvertLeafNode(typeof(int), secondNode, 0);

				fullDateTime += string.Format("T{0:00}:{1:00}:{2:00}", hour, minute, second);
				conversionSucceeded = true;
			}

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

示例4: 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

示例5: 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

示例6: 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

示例7: BindObjectInstance

		public void BindObjectInstance(object instance, string prefix, string excludedProperties, string allowedProperties,
		                               CompositeNode treeRoot)
		{
			if (instance == null)
			{
				throw new ArgumentNullException("instance");
			}
			if (prefix == null)
			{
				throw new ArgumentNullException("prefix");
			}
			if (treeRoot == null)
			{
				throw new ArgumentNullException("treeRoot");
			}

			errors = new ArrayList();
			instanceStack = new Stack();
			prefixStack = new Stack<string>();

			excludedPropertyList = CreateNormalizedList(excludedProperties);
			allowedPropertyList = CreateNormalizedList(allowedProperties);

			InternalRecursiveBindObjectInstance(instance, prefix, treeRoot.GetChildNode(prefix));
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:25,代码来源:DataBinder.cs

示例8: BindObject

		public object BindObject(Type targetType, string prefix, string excludedProperties, string allowedProperties,
		                         CompositeNode treeRoot)
		{
			if (targetType == null)
			{
				throw new ArgumentNullException("targetType");
			}
			if (prefix == null)
			{
				throw new ArgumentNullException("prefix");
			}
			if (treeRoot == null)
			{
				throw new ArgumentNullException("treeRoot");
			}

			errors = new ArrayList();
			instanceStack = new Stack();
			prefixStack = new Stack<string>();

			excludedPropertyList = CreateNormalizedList(excludedProperties);
			allowedPropertyList = CreateNormalizedList(allowedProperties);

			return InternalBindObject(targetType, prefix, treeRoot.GetChildNode(prefix));
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:25,代码来源:DataBinder.cs

示例9: 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

示例10: 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

示例11: 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

示例12: BindObjectInstance

		public void BindObjectInstance(object instance, string prefix, string excludedProperties, string allowedProperties,
		                               CompositeNode treeRoot)
		{
			if (instance == null)
			{
				throw new ArgumentNullException("instance");
			}
			if (prefix == null)
			{
				throw new ArgumentNullException("prefix");
			}
			if (treeRoot == null)
			{
				throw new ArgumentNullException("treeRoot");
			}

			errors = new ArrayList();
			instanceStack = new Stack();
			prefixStack = new Stack<string>();

			excludedPropertyList = CreateNormalizedList(excludedProperties);
			allowedPropertyList = CreateNormalizedList(allowedProperties);

			if (instance != null)
			{
				var instanceType = instance.GetType();
				if (IsGenericList(instanceType))
				{
					bool success;
					var elemType = instanceType.GetGenericArguments()[0];
					ConvertToGenericList((IList)instance, elemType, prefix, treeRoot.GetChildNode(prefix), out success);
				}
			}

			InternalRecursiveBindObjectInstance(instance, prefix, treeRoot.GetChildNode(prefix));
		}
开发者ID:hjlfmy,项目名称:Castle.Components.Binder-READONLY,代码行数:36,代码来源:DataBinder.cs


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