Beispiel #1
0
 internal static MetadataProperty CreateMetadataPropertyFromXmlElement(
     string xmlNamespaceUri,
     string elementName,
     XElement value)
 {
     return(MetadataProperty.CreateAnnotation(xmlNamespaceUri + ":" + elementName, (object)value));
 }
Beispiel #2
0
        internal MetadataProperty CreateMetadataPropertyFromXmlAttribute(
            string xmlNamespaceUri, string attributeName, string value)
        {
            var serializer  = _resolver.GetService <Func <IMetadataAnnotationSerializer> >(attributeName);
            var parsedValue = serializer == null ? value : serializer().Deserialize(attributeName, value);

            return(MetadataProperty.CreateAnnotation(xmlNamespaceUri + ":" + attributeName, parsedValue));
        }
Beispiel #3
0
        internal MetadataProperty CreateMetadataPropertyFromXmlAttribute(
            string xmlNamespaceUri, string artifactName, string value)
        {
            var name        = xmlNamespaceUri + ":" + artifactName;
            var serializer  = _resolver.GetService <IMetadataAnnotationSerializer>(name);
            var parsedValue = serializer == null ? value : serializer.DeserializeValue(name, value);

            return(MetadataProperty.CreateAnnotation(name, parsedValue));
        }
Beispiel #4
0
        internal MetadataProperty CreateMetadataPropertyFromXmlAttribute(
            string xmlNamespaceUri,
            string attributeName,
            string value)
        {
            Func <IMetadataAnnotationSerializer> service = this._resolver.GetService <Func <IMetadataAnnotationSerializer> >((object)attributeName);
            object obj = service == null ? (object)value : service().Deserialize(attributeName, value);

            return(MetadataProperty.CreateAnnotation(xmlNamespaceUri + ":" + attributeName, obj));
        }
Beispiel #5
0
        public void Can_add_retrieve_remove_annotations()
        {
            var mappingItem = new AMappingItem();
            var annotation  = MetadataProperty.CreateAnnotation("N", "V");

            Assert.Equal(0, mappingItem.Annotations.Count);

            mappingItem.Annotations.Add(annotation);

            Assert.Equal(1, mappingItem.Annotations.Count);
            Assert.Same(annotation, mappingItem.Annotations[0]);

            mappingItem.Annotations.Remove(annotation);

            Assert.Equal(0, mappingItem.Annotations.Count);
        }
Beispiel #6
0
        public static void SetAnnotation(
            this ICollection <MetadataProperty> metadataProperties,
            string name,
            object value)
        {
            MetadataProperty metadataProperty = metadataProperties.SingleOrDefault <MetadataProperty>((Func <MetadataProperty, bool>)(p => p.Name.Equals(name, StringComparison.Ordinal)));

            if (metadataProperty == null)
            {
                MetadataProperty annotation = MetadataProperty.CreateAnnotation(name, value);
                metadataProperties.Add(annotation);
            }
            else
            {
                metadataProperty.Value = value;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Sets an annotation on a set of properties.
        /// </summary>
        /// <param name="metadataProperties">The properties.</param>
        /// <param name="name">The name of the annotation.</param>
        /// <param name="value">The value of the annotation.</param>
        public static void SetAnnotation(
            this ICollection <MetadataProperty> metadataProperties, string name, object value)
        {
            DebugCheck.NotNull(metadataProperties);
            DebugCheck.NotEmpty(name);
            DebugCheck.NotNull(value);

            var annotation = metadataProperties.SingleOrDefault(a => a.Name.Equals(name, StringComparison.Ordinal));

            if (annotation == null)
            {
                annotation = MetadataProperty.CreateAnnotation(name, value);
                metadataProperties.Add(annotation);
            }
            else
            {
                annotation.Value = value;
            }
        }
        private static EdmProperty CreateColumn(
            Mock <EntityType> mockTableType, string name, Properties.Primitive.PrimitivePropertyConfiguration config = null)
        {
            var mockColumn = CreateMockMember(mockTableType.Object, name);

            mockColumn.Setup(m => m.Annotations).Returns(
                config == null
                    ? new MetadataProperty[0]
                    : new[]
            {
                MetadataProperty.CreateAnnotation("Configuration", config)
            });

            mockColumn.SetupProperty(
                m => m.TypeUsage, TypeUsage.CreateStringTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String), true, false));

            mockTableType.Setup(m => m.HasMember(mockColumn.Object)).Returns(true);

            return(mockColumn.Object);
        }