internal static string GetSchemaAttributes(SMERelationshipProperty relationship, SMEResource resource)
        {
            if (relationship == null)
                return String.Empty;

            var builder = new StringBuilder();

            //builder.AppendFormat("{0}=\"{1}\" ", SDataResource.FormatSME(IncludeByDefaultName), IncludeByDefaultName, relationship.IncludeByDefault ? "true" : "false");

            if (relationship.Relationship != 0)
                builder.AppendFormat("{0}=\"{1}\" ", SDataResource.FormatSME(RelationshipName), relationship.Relationship);

            if (resource == null)
            {
                builder.AppendFormat("{0}=\"{1}\" ", SDataResource.FormatSME(CanGetName), relationship.CanGet ? "true" : "false");
                builder.AppendFormat("{0}=\"{1}\" ", SDataResource.FormatSME(CanPostName), relationship.CanPost ? "true" : "false");
                builder.AppendFormat("{0}=\"{1}\" ", SDataResource.FormatSME(CanPutName), relationship.CanPut ? "true" : "false");
                builder.AppendFormat("{0}=\"{1}\" ", SDataResource.FormatSME(CanDeleteName), relationship.CanDelete ? "true" : "false");

                builder.AppendFormat("{0}=\"{1}\" ", SDataResource.FormatSME(CanPagePreviousName), relationship.CanPagePrevious ? "true" : "false");
                builder.AppendFormat("{0}=\"{1}\" ", SDataResource.FormatSME(CanPageNextName), relationship.CanPageNext ? "true" : "false");
                builder.AppendFormat("{0}=\"{1}\" ", SDataResource.FormatSME(CanPageIndexName), relationship.CanPageIndex ? "true" : "false");
            }

            builder.AppendFormat("{0}=\"{1}\" ", SDataResource.FormatSME(IsCollectionName), relationship.IsCollection ? "true" : "false");
            builder.AppendFormat("{0}=\"{1}\"", SDataResource.XmlConstants.MinOccurs, relationship.MinOccurs);

            if (relationship.MaxOccurs != 0)
                builder.AppendFormat("{0}=\"{1}\"", SDataResource.XmlConstants.MaxOccurs, relationship.MaxOccurs == -1 ? SDataResource.XmlConstants.Unbounded : relationship.MaxOccurs.ToString());

            return builder.ToString();
        }
        private SMEProperty LoadProperty(XmlSchemaElement element, XmlSchemaElement originalElement, XmlSchemaSet schemaSet)
        {
            SMEProperty metaDataProperty = null;

            if (element != null)
            {
                // Load the metadata from the schema type
                metaDataProperty = GetMetadataProperty(element.SchemaTypeName, element.QualifiedName, schemaSet);

                if (metaDataProperty != null)
                {
                    var hasRelationship = false;

                    metaDataProperty.Nillable = element.IsNillable;

                    // Load SData/SME attributes which are applied at the resource level
                    if (element.UnhandledAttributes != null && element.UnhandledAttributes.Length > 0)
                    {
                        foreach (var attribute in element.UnhandledAttributes)
                        {
                            if (SMERelationshipProperty.IsRelationshipAttribute(attribute.LocalName))
                                hasRelationship = true;

                            metaDataProperty.LoadUnhandledAttribute(attribute);
                        }
                    }

                    if (hasRelationship)
                    {
                        var relationship = new SMERelationshipProperty(metaDataProperty.Label, RelationshipType.Association);
                        relationship.Name = metaDataProperty.Name;
                        relationship.Namespace = metaDataProperty.Namespace;
                        foreach (var attribute in originalElement.UnhandledAttributes)
                        {
                            relationship.LoadUnhandledAttribute(attribute);
                        }

                        if (metaDataProperty is SDataResource)
                        {
                            ((SDataResource) metaDataProperty).RelationshipInformation = relationship;
                        }
                        else
                        {
                            metaDataProperty = relationship;
                        }
                    }

                    if (originalElement != null && originalElement != element)
                    {
                        // Load SData/SME attributes which are applied at the resource level
                        if (originalElement.UnhandledAttributes != null && originalElement.UnhandledAttributes.Length > 0)
                        {
                            foreach (var attribute in originalElement.UnhandledAttributes)
                                metaDataProperty.LoadUnhandledAttribute(attribute);
                        }
                    }

                    // Check for a collection
                    if (element.MaxOccursString == XmlConstants.Unbounded)
                    {
                        if (_oRelationshipInformation == null)
                        {
                            _oRelationshipInformation = new SMERelationshipProperty();
                            _oRelationshipInformation.IsCollection = true;
                        }
                    }
                }
            }

            return metaDataProperty;
        }
 public SMERelationshipProperty(SMERelationshipProperty copy)
 {
     _eRelationship = copy.Relationship;
     _bIncludeByDefault = copy.IncludeByDefault;
     _bCanGet = copy.CanGet;
     _bCanPost = copy.CanPost;
     _bCanPut = copy.CanPut;
     _bCanDelete = copy.CanDelete;
     _bCanPagePrevious = copy.CanPagePrevious;
     _bCanPageNext = copy.CanPageNext;
     _bCanPageIndex = copy.CanPageIndex;
     _bIsCollection = copy.IsCollection;
 }
        private void Clone(SDataResource source)
        {
            _strTypeName = source.TypeName;
            _oBaseType = source.BaseType;

            if (source.RelationshipInformation != null)
                _oRelationshipInformation = new SMERelationshipProperty(source.RelationshipInformation);

            if (source.ResourceInformation != null)
                _oResourceInfo = new SMEResource(source.ResourceInformation);

            _oProperties = new List<SMEProperty>();
            _oNameToProperty = new Dictionary<string, SMEProperty>(StringComparer.InvariantCultureIgnoreCase);

            foreach (var property in source.Properties)
                AddProperty(property);

            _oNamespaces = new XmlNamespaceManager(new NameTable());

            foreach (var ns in source.Namespaces.GetNamespacesInScope(XmlNamespaceScope.All))
            {
                // Don't add default namespaces
                if (!String.IsNullOrEmpty(ns.Key))
                    _oNamespaces.AddNamespace(ns.Key, ns.Value);
            }
        }