Пример #1
0
            public Fixture(double version = 3.0)
            {
                _stringBuilder = new StringBuilder();

                UnderlyingWriter = XmlWriter.Create(
                    _stringBuilder,
                    new XmlWriterSettings
                {
                    OmitXmlDeclaration = true
                });

                Writer = new EdmXmlSchemaWriter(UnderlyingWriter, version, false);
            }
        internal void WriteExtendedProperties(MetadataItem item)
        {
            foreach (MetadataProperty metadataProperty in item.MetadataProperties.Where <MetadataProperty>((Func <MetadataProperty, bool>)(p => p.PropertyKind == PropertyKind.Extended)))
            {
                string xmlNamespaceUri;
                string attributeName;
                if (EdmXmlSchemaWriter.TrySplitExtendedMetadataPropertyName(metadataProperty.Name, out xmlNamespaceUri, out attributeName) && metadataProperty.Name != "http://schemas.microsoft.com/ado/2009/02/edm/annotation:StoreGeneratedPattern")
                {
                    Func <IMetadataAnnotationSerializer> service = this._resolver.GetService <Func <IMetadataAnnotationSerializer> >((object)attributeName);
                    string str = service == null?metadataProperty.Value.ToString() : service().Serialize(attributeName, metadataProperty.Value);

                    this._xmlWriter.WriteAttributeString(attributeName, xmlNamespaceUri, str);
                }
            }
        }
            public Fixture(double version = 3.0)
            {
                _stringBuilder = new StringBuilder();

                UnderlyingWriter = XmlWriter.Create(
                    _stringBuilder,
                    new XmlWriterSettings
                        {
                            OmitXmlDeclaration = true
                        });

                Writer = new EdmXmlSchemaWriter(UnderlyingWriter, version, false);
            }
Пример #4
0
 internal EdmSerializationVisitor(XmlWriter xmlWriter, double edmVersion, bool serializeDefaultNullability = false)
 {
     _edmVersion = edmVersion;
     _schemaWriter = new EdmXmlSchemaWriter(xmlWriter, _edmVersion, serializeDefaultNullability);
 }
Пример #5
0
 public EdmSerializationVisitor(EdmXmlSchemaWriter schemaWriter)
 {
     this._schemaWriter = schemaWriter;
 }
 private static string GetTypeName(EdmType type)
 {
     if (type.BuiltInTypeKind == BuiltInTypeKind.CollectionType)
     {
         return(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Collection({0})", (object)EdmXmlSchemaWriter.GetTypeName(((CollectionType)type).TypeUsage.EdmType)));
     }
     if (type.BuiltInTypeKind != BuiltInTypeKind.PrimitiveType)
     {
         return(type.FullName);
     }
     return(type.Name);
 }
        internal void WritePropertyElementHeader(EdmProperty property)
        {
            this._xmlWriter.WriteStartElement("Property");
            this._xmlWriter.WriteAttributeString("Name", property.Name);
            this._xmlWriter.WriteAttributeString("Type", EdmXmlSchemaWriter.GetTypeReferenceName(property));
            if (property.CollectionKind != CollectionKind.None)
            {
                this._xmlWriter.WriteAttributeString("CollectionKind", property.CollectionKind.ToString());
            }
            if (property.ConcurrencyMode == ConcurrencyMode.Fixed)
            {
                this._xmlWriter.WriteAttributeString("ConcurrencyMode", "Fixed");
            }
            this.WriteExtendedProperties((MetadataItem)property);
            if (property.Annotations.GetClrAttributes() != null)
            {
                int num1 = 0;
                foreach (Attribute clrAttribute in (IEnumerable <Attribute>)property.Annotations.GetClrAttributes())
                {
                    if (clrAttribute.GetType().FullName.Equals("System.Data.Services.MimeTypeAttribute", StringComparison.Ordinal))
                    {
                        this._xmlWriter.WriteAttributeString("m", "MimeType", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", clrAttribute.GetType().GetDeclaredProperty("MimeType").GetValue((object)clrAttribute, (object[])null) as string);
                    }
                    else if (clrAttribute.GetType().FullName.Equals("System.Data.Services.Common.EntityPropertyMappingAttribute", StringComparison.Ordinal))
                    {
                        string str1;
                        if (num1 != 0)
                        {
                            str1 = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "_{0}", (object)num1);
                        }
                        else
                        {
                            str1 = string.Empty;
                        }
                        string str2 = str1;
                        string str3 = clrAttribute.GetType().GetDeclaredProperty("SourcePath").GetValue((object)clrAttribute, (object[])null) as string;
                        int    num2 = str3.IndexOf("/", StringComparison.Ordinal);
                        if (num2 != -1 && num2 + 1 < str3.Length)
                        {
                            this._xmlWriter.WriteAttributeString("m", "FC_SourcePath" + str2, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", str3.Substring(num2 + 1));
                        }
                        object       obj1             = clrAttribute.GetType().GetDeclaredProperty("TargetSyndicationItem").GetValue((object)clrAttribute, (object[])null);
                        string       str4             = clrAttribute.GetType().GetDeclaredProperty("KeepInContent").GetValue((object)clrAttribute, (object[])null).ToString();
                        PropertyInfo declaredProperty = clrAttribute.GetType().GetDeclaredProperty("CriteriaValue");
                        string       str5             = (string)null;
                        if (declaredProperty != (PropertyInfo)null)
                        {
                            str5 = declaredProperty.GetValue((object)clrAttribute, (object[])null) as string;
                        }
                        if (str5 != null)
                        {
                            this._xmlWriter.WriteAttributeString("m", "FC_TargetPath" + str2, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", EdmXmlSchemaWriter.SyndicationItemPropertyToString(obj1));
                            this._xmlWriter.WriteAttributeString("m", "FC_KeepInContent" + str2, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", str4);
                            this._xmlWriter.WriteAttributeString("m", "FC_CriteriaValue" + str2, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", str5);
                        }
                        else if (string.Equals(obj1.ToString(), "CustomProperty", StringComparison.Ordinal))
                        {
                            string str6 = clrAttribute.GetType().GetDeclaredProperty("TargetPath").GetValue((object)clrAttribute, (object[])null).ToString();
                            string str7 = clrAttribute.GetType().GetDeclaredProperty("TargetNamespacePrefix").GetValue((object)clrAttribute, (object[])null).ToString();
                            string str8 = clrAttribute.GetType().GetDeclaredProperty("TargetNamespaceUri").GetValue((object)clrAttribute, (object[])null).ToString();
                            this._xmlWriter.WriteAttributeString("m", "FC_TargetPath" + str2, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", str6);
                            this._xmlWriter.WriteAttributeString("m", "FC_NsUri" + str2, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", str8);
                            this._xmlWriter.WriteAttributeString("m", "FC_NsPrefix" + str2, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", str7);
                            this._xmlWriter.WriteAttributeString("m", "FC_KeepInContent" + str2, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", str4);
                        }
                        else
                        {
                            object obj2 = clrAttribute.GetType().GetDeclaredProperty("TargetTextContentKind").GetValue((object)clrAttribute, (object[])null);
                            this._xmlWriter.WriteAttributeString("m", "FC_TargetPath" + str2, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", EdmXmlSchemaWriter.SyndicationItemPropertyToString(obj1));
                            this._xmlWriter.WriteAttributeString("m", "FC_ContentKind" + str2, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", EdmXmlSchemaWriter.SyndicationTextContentKindToString(obj2));
                            this._xmlWriter.WriteAttributeString("m", "FC_KeepInContent" + str2, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", str4);
                        }
                        ++num1;
                    }
                }
            }
            if (property.IsMaxLength)
            {
                this._xmlWriter.WriteAttributeString("MaxLength", "Max");
            }
            else if (!property.IsMaxLengthConstant && property.MaxLength.HasValue)
            {
                this._xmlWriter.WriteAttributeString("MaxLength", property.MaxLength.Value.ToString((IFormatProvider)CultureInfo.InvariantCulture));
            }
            if (!property.IsFixedLengthConstant && property.IsFixedLength.HasValue)
            {
                this._xmlWriter.WriteAttributeString("FixedLength", XmlSchemaWriter.GetLowerCaseStringFromBoolValue(property.IsFixedLength.Value));
            }
            if (!property.IsUnicodeConstant && property.IsUnicode.HasValue)
            {
                this._xmlWriter.WriteAttributeString("Unicode", XmlSchemaWriter.GetLowerCaseStringFromBoolValue(property.IsUnicode.Value));
            }
            if (!property.IsPrecisionConstant && property.Precision.HasValue)
            {
                this._xmlWriter.WriteAttributeString("Precision", property.Precision.Value.ToString((IFormatProvider)CultureInfo.InvariantCulture));
            }
            if (!property.IsScaleConstant && property.Scale.HasValue)
            {
                this._xmlWriter.WriteAttributeString("Scale", property.Scale.Value.ToString((IFormatProvider)CultureInfo.InvariantCulture));
            }
            if (property.StoreGeneratedPattern != StoreGeneratedPattern.None)
            {
                this._xmlWriter.WriteAttributeString("StoreGeneratedPattern", property.StoreGeneratedPattern == StoreGeneratedPattern.Computed ? "Computed" : "Identity");
            }
            if (this._serializeDefaultNullability || !property.Nullable)
            {
                this._xmlWriter.WriteAttributeString("Nullable", XmlSchemaWriter.GetLowerCaseStringFromBoolValue(property.Nullable));
            }
            MetadataProperty metadataProperty;

            if (!property.MetadataProperties.TryGetValue("http://schemas.microsoft.com/ado/2009/02/edm/annotation:StoreGeneratedPattern", false, out metadataProperty))
            {
                return;
            }
            this._xmlWriter.WriteAttributeString("StoreGeneratedPattern", "http://schemas.microsoft.com/ado/2009/02/edm/annotation", metadataProperty.Value.ToString());
        }
Пример #8
0
        public EdmSerializationVisitor(EdmXmlSchemaWriter schemaWriter)
        {
            DebugCheck.NotNull(schemaWriter);

            _schemaWriter = schemaWriter;
        }