Esempio n. 1
0
        public virtual bool Resolve()
        {
            if (this.IsResolved || !this.IsResolvable)
            {
                return(this.IsResolved);
            }
            IMetadataNode node = this.ResolveNodeSource.Find(a => this.IsSatisfiedBy(a.Metadata));

            if (node != null)
            {
                this.DependentMetadataNode = node;
                IReferencable referencable = node as IReferencable;
                if (referencable != null)
                {
                    referencable.AddReferencedConstraint(this);
                }
                this.IsResolved = true;
            }
            else
            {
                this.IsResolvable = false;
            }
            return(this.IsResolvable);
        }
		protected virtual string GetMemberName(IMetadataNode member)
		{
			if (member is EntityField)
				return ((EntityField)member).Name;
			if (member is IndexField)
				return ((IndexField)member).Name;
			if (member is Link)
				return ((Link)member).Name;

			throw new InvalidOperationException("Unrecognized member type: " + member.GetType().ToString());
		}
		private string FormatPropertyAccessorText(IMetadataNode member, string accessorText)
		{
			if (accessorText.IndexOf("\r\n") > 0)
				accessorText = "\r\n" + StringHelper.IndentBlock(accessorText) + "\r\n";

			return accessorText.Replace("${field}", FormatFieldName(GetMemberName(member)));
		}
		private string GetPropertyAccessorText(IMetadataNode member, string nodeName, string defaultCode)
		{
			string txt = "";

			XmlNode node = member.LoadedXmlNode.SelectSingleNode(nodeName);
			if (node != null && node.InnerText.Trim() != "")
				txt = node.InnerText;
			else
				txt = defaultCode;

			return txt;
		}
		protected virtual string GetPropertySetterText(IMetadataNode member)
		{
			return GetPropertyAccessorText(member, "Set", "${field} = value;");
		}
		protected virtual string GetPropertyGetterText(IMetadataNode member)
		{
			return GetPropertyAccessorText(member, "Get", "return ${field};");
		}
		private XmlNode GetOrCreateItemNode (XmlNode listNode, IMetadataNode item, string itemElementName) {
			foreach (XmlNode itemNode in listNode.SelectNodes(itemElementName)) {
				if (item.LoadedXmlNode == itemNode) {
					return itemNode;
				}
			}
			XmlNode node = listNode.OwnerDocument.CreateElement(itemElementName);
			if (item.LoadedXmlNode != null)
			{
				foreach (XmlAttribute attr in item.LoadedXmlNode.Attributes)
				{
					node.Attributes.Append((XmlAttribute)attr.Clone());
				}
				node.InnerXml = item.LoadedXmlNode.InnerXml;
			}
			listNode.AppendChild(node);
			return node;
		}