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


C# XElement.AddElement方法代码示例

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


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

示例1: SerializeLayer

 public static void SerializeLayer(XElement parent, Layer layer)
 {
     var layerElement = new XElement("Layer");
     layerElement.AddElement("Id", layer.Id);
     layerElement.AddElement("Size", layer.Size.ToString());
     if (layer.HasWeights)
     {
         var weights = layer.GetArray(ArrayName.Weights);
         var biasWeights = layer.GetArray(ArrayName.BiasWeights);
         weights.CopyToHost();
         biasWeights.CopyToHost();
         layerElement.AddElement("Weights", SerializeArrayValues(weights));
         layerElement.AddElement("BiasWeights", SerializeArrayValues(biasWeights));
     }
     parent.Add(layerElement);
 }
开发者ID:zhimingz,项目名称:kaggle_criteo,代码行数:16,代码来源:NetSerializer.cs

示例2: CreateElement

        /// <summary>
        /// 
        /// </summary>
        /// <param name="xmlns"></param>
        /// <returns></returns>
        public override XElement CreateElement(XNamespace xmlns)
        {
            var rdf = RssNamespace.RDF;

            var seq = new XElement(rdf + "Seq");
            foreach (var r in Resources)
            {
                seq.AddElement(new XElement(r.ElementName)
                    .AddAttribute("resource", r.Resource));
            }
            var element = new XElement(xmlns + "items")
                .AddElement(seq);

            return element;
        }
开发者ID:fengweijp,项目名称:higlabo,代码行数:20,代码来源:RssChannelItems.cs

示例3: ToXml

        /// <summary>
        /// Emits WiX XML.
        /// </summary>
        /// <returns></returns>
        public override XContainer[] ToXml()
        {
            XNamespace bal = "http://schemas.microsoft.com/wix/BalExtension";

            var root = new XElement("BootstrapperApplicationRef");

            var app = new XElement(bal + "WixStandardBootstrapperApplication");

            app.Add(this.MapToXmlAttributes());

            if (LicensePath.IsNotEmpty() && LicensePath.EndsWith(".rtf", StringComparison.OrdinalIgnoreCase))
            {
                root.SetAttribute("Id", "WixStandardBootstrapperApplication.RtfLicense");
                app.SetAttribute("LicenseFile", LicensePath);
            }
            else
            {
                root.SetAttribute("Id", "WixStandardBootstrapperApplication.HyperlinkLicense");

                if (LicensePath.IsEmpty())
                {
                    //cannot use SetAttribute as we want to preserve empty attrs
                    app.Add(new XAttribute("LicenseUrl", ""));
                }
                else
                {
                    if (LicensePath.StartsWith("http")) //online HTML file
                    {
                        app.SetAttribute("LicenseUrl", LicensePath);
                    }
                    else
                    {
                        app.SetAttribute("LicenseUrl", System.IO.Path.GetFileName(LicensePath));
                        root.AddElement("Payload").AddAttributes("SourceFile=" + LicensePath);
                    }
                }
            }

            root.Add(app);

            return new[] { root };
        }
开发者ID:Eun,项目名称:WixSharp,代码行数:46,代码来源:BootstrapperApplication.cs

示例4: ToXElement

        /// <summary>
        /// Converts the <see cref="T:WixSharp.CustomUI"/> instance into WiX <see cref="T:System.Xml.Linq.XElement"/>.
        /// </summary>
        /// <returns><see cref="T:System.Xml.Linq.XElement"/> instance.</returns>
        public virtual XElement ToXElement()
        {
            var ui = new XElement("UI")
                         .AddAttributes(this.Attributes);

            foreach (string key in TextStyles.Keys)
            {
                var font = TextStyles[key];
                var style = ui.AddElement(new XElement("TextStyle",
                                              new XAttribute("Id", key),
                                              new XAttribute("FaceName", font.FontFamily.Name),
                                              new XAttribute("Size", font.Size),
                                              new XAttribute("Bold", font.Bold.ToYesNo()),
                                              new XAttribute("Italic", font.Italic.ToYesNo()),
                                              new XAttribute("Strike", font.Strikeout.ToYesNo()),
                                              new XAttribute("Underline", font.Underline.ToYesNo())));
            }

            foreach (string key in Properties.Keys)
                ui.Add(new XElement("Property",
                           new XAttribute("Id", key),
                           new XAttribute("Value", Properties[key])));

            foreach (string dialogId in DialogRefs)
                ui.Add(new XElement("DialogRef",
                           new XAttribute("Id", dialogId)));

            foreach (PublishingInfo info in this.UISequence)
            {
                int index = 0;
                foreach (DialogAction action in info.Actions)
                {
                    index++;
                    var element = ui.AddElement(new XElement("Publish",
                                                    new XAttribute("Dialog", info.Dialog),
                                                    new XAttribute("Control", info.Control),
                                                    action.Condition));

                    Action<string, string> AddAttribute = (name, value) =>
                    {
                        if (!value.IsEmpty())
                            element.Add(new XAttribute(name, value));
                    };

                    AddAttribute("Event", action.Name);
                    AddAttribute("Value", action.Value);
                    AddAttribute("Property", action.Property);

                    if (action.Order.HasValue)
                    {
                        element.Add(new XAttribute("Order", action.Order.Value));
                    }
                    else if (info.Actions.Count > 1)
                    {
                        element.Add(new XAttribute("Order", index));
                    }
                }
            }

            foreach (Dialog dialog in this.CustomDialogs)
            {
                ui.Add(dialog.ToXElement());
            }

            return ui;
        }
开发者ID:Eun,项目名称:WixSharp,代码行数:70,代码来源:CustomUI.cs

示例5: MappingComplexProperties

        private static IEnumerable<XElement> MappingComplexProperties(TypeBase type, MappingBase mapping, EDMObjects.SSDL.EntityType.EntityType table, string entityContainerNamespace)
        {
            foreach (ComplexProperty complexProperty in type.AllComplexProperties)
            {
                ComplexPropertyMapping complexPropertyMapping = mapping.GetEntityTypeSpecificComplexPropertyMapping(complexProperty);

                if (complexPropertyMapping != null)
                {
                    XElement complexPropertyElement = new XElement(mslNamespace + "ComplexProperty",
                        new XAttribute("Name", complexProperty.Name));

                    IEnumerable<PropertyMapping> scalarMappings = complexPropertyMapping.GetSpecificMappingForTable(table);

                    foreach (PropertyMapping scalarMapping in scalarMappings)
                    {
                        complexPropertyElement.AddElement(new XElement(mslNamespace + "ScalarProperty",
                            new XAttribute("Name", scalarMapping.Property.Name),
                            new XAttribute("ColumnName", scalarMapping.Column.Name)));
                    }

                    foreach (ComplexProperty subComplexProperty in complexProperty.ComplexType.ComplexProperties)
                    {
                        complexPropertyElement.Add(MappingComplexProperties(complexProperty.ComplexType, complexPropertyMapping, table, entityContainerNamespace));
                    }

                    yield return complexPropertyElement;
                }
            }
        }
开发者ID:hpsa,项目名称:SharpDevelop,代码行数:29,代码来源:MSLIO.cs

示例6: AddDir

        static XElement AddDir(XElement parent, Dir wDir)
        {
            string name = wDir.Name;
            string id = "";

            if (wDir.IsIdSet())
            {
                id = wDir.Id;
            }
            else
            {
                //Special folder defined either directly or by Wix# environment constant
                //e.g. %ProgramFiles%, [ProgramFilesFolder] -> ProgramFilesFolder
                if (Compiler.EnvironmentConstantsMapping.ContainsKey(wDir.Name) ||                              // %ProgramFiles%
                    Compiler.EnvironmentConstantsMapping.ContainsValue(wDir.Name) ||                            // ProgramFilesFolder
                    Compiler.EnvironmentConstantsMapping.ContainsValue(wDir.Name.TrimStart('[').TrimEnd(']')))  // [ProgramFilesFolder]
                {
                    id = wDir.Name.Expand();
                    name = wDir.Name.Expand(); //name needs to be escaped
                }
                else
                {
                    id = parent.Attribute("Id").Value + "." + wDir.Name.Expand();
                }
            }

            XElement newSubDir = parent.AddElement(
                                             new XElement("Directory",
                                                 new XAttribute("Id", id),
                                                 new XAttribute("Name", name)));

            return newSubDir;
        }
开发者ID:denis-peshkov,项目名称:WixSharp,代码行数:33,代码来源:Compiler.cs

示例7: ProcessProperties

        static void ProcessProperties(Project wProject, XElement product)
        {
            foreach (var prop in wProject.Properties)
            {
                if (prop is PropertyRef)
                {
                    var propRef = (prop as PropertyRef);

                    if (propRef.Id.IsEmpty())
                        throw new Exception("'" + typeof(PropertyRef).Name + "'.Id must be set before compiling the project.");

                    product.Add(new XElement("PropertyRef",
                                    new XAttribute("Id", propRef.Id)));
                }
                else if (prop is RegValueProperty)
                {
                    var rvProp = (prop as RegValueProperty);

                    XElement RegistrySearchElement;
                    XElement xProp = product.AddElement(
                                new XElement("Property",
                                    new XAttribute("Id", rvProp.Name),
                                    RegistrySearchElement = new XElement("RegistrySearch",
                                        new XAttribute("Id", rvProp.Name + "_RegSearch"),
                                        new XAttribute("Root", rvProp.Root.ToWString()),
                                        new XAttribute("Key", rvProp.Key),
                                        new XAttribute("Type", "raw")
                                        ))
                                    .AddAttributes(rvProp.Attributes));

                    if (!rvProp.Value.IsEmpty())
                        xProp.Add(new XAttribute("Value", rvProp.Value));

                    if (rvProp.EntryName != "")
                        RegistrySearchElement.Add(new XAttribute("Name", rvProp.EntryName));
                }
                else
                {
                    product.Add(new XElement("Property",
                                    new XAttribute("Id", prop.Name),
                                    new XAttribute("Value", prop.Value))
                                    .AddAttributes(prop.Attributes));
                }
            }
        }
开发者ID:denis-peshkov,项目名称:WixSharp,代码行数:45,代码来源:Compiler.cs

示例8: InsertWebSite

        static void InsertWebSite(WebSite webSite, string dirID, XElement element)
        {
            XNamespace ns = "http://schemas.microsoft.com/wix/IIsExtension";

            var id = webSite.Name.Expand();
            XElement xWebSite = element.AddElement(new XElement(ns + "WebSite",
                                                   new XAttribute("Id", id),
                                                   new XAttribute("Description", webSite.Description),
                                                   new XAttribute("Directory", dirID)));

            xWebSite.AddAttributes(webSite.Attributes);

            foreach (WebSite.WebAddress address in webSite.Addresses)
            {
                XElement xAddress = xWebSite.AddElement(new XElement(ns + "WebAddress",
                                                            new XAttribute("Id", address.Address == "*" ? "AllUnassigned" : address.Address),
                                                            new XAttribute("Port", address.Port)));

                xAddress.AddAttributes(address.Attributes);
            }
        }
开发者ID:denis-peshkov,项目名称:WixSharp,代码行数:21,代码来源:Compiler.cs

示例9: ProcessMergeModules

        static void ProcessMergeModules(Dir wDir, XElement dirItem, Dictionary<Feature, List<string>> featureComponents, List<string> defaultFeatureComponents)
        {
            foreach (Merge msm in wDir.MergeModules)
            {
                XElement media = dirItem.Parent("Product").Select("Media");
                XElement package = dirItem.Parent("Product").Select("Package");

                string language = package.Attribute("Languages").Value; //note Wix# expects package.Attribute("Languages") to have a single value (yest it is a temporary limitation)
                string diskId = media.Attribute("Id").Value;

                XElement merge = dirItem.AddElement(
                    new XElement("Merge",
                        new XAttribute("Id", msm.Id),
                        new XAttribute("FileCompression", msm.FileCompression.ToYesNo()),
                        new XAttribute("Language", language),
                        new XAttribute("SourceFile", msm.SourceFile),
                        new XAttribute("DiskId", diskId))
                        .AddAttributes(msm.Attributes));

                if (!featureComponents.ContainsKey(msm.Feature))
                    featureComponents[msm.Feature] = new List<string>();

                //currently WiX does not allow child Condition element but in the future release it most likely will
                //if (msm.Condition != null)
                //    merge.AddElement(
                //        new XElement("Condition", new XCData(msm.Condition.ToCData()))
                //            .AddAttributes(msm.Condition.Attributes));
            }
        }
开发者ID:denis-peshkov,项目名称:WixSharp,代码行数:29,代码来源:Compiler.cs

示例10: ProcessDirectoryFiles

        static void ProcessDirectoryFiles(Dir wDir, Project wProject, Dictionary<Feature, List<string>> featureComponents, List<string> defaultFeatureComponents, XElement dirItem)
        {
            //insert files in the last leaf directory node
            foreach (File wFile in wDir.Files)
            {
                string fileId = wFile.Id;
                string compId = "Component." + wFile.Id;

                if (wFile.Feature != null)
                {
                    featureComponents.Map(wFile.Feature, compId);
                }
                else
                {
                    defaultFeatureComponents.Add(compId);
                }

                XElement comp = dirItem.AddElement(
                    new XElement("Component",
                        new XAttribute("Id", compId),
                        new XAttribute("Guid", WixGuid.NewGuid(compId))));

                if (wFile.Condition != null)
                    comp.AddElement(
                        new XElement("Condition", new XCData(wFile.Condition.ToCData()))
                            .AddAttributes(wFile.Condition.Attributes));

                XElement file = comp.AddElement(
                    new XElement("File",
                        new XAttribute("Id", fileId),
                        new XAttribute("Source", Utils.PathCombine(wProject.SourceBaseDir, wFile.Name)))
                        .AddAttributes(wFile.Attributes));

                if (wFile.ServiceInstaller != null)
                    comp.Add(wFile.ServiceInstaller.ToXml(wProject));

                if (wFile is Assembly && (wFile as Assembly).RegisterInGAC)
                {
                    file.Add(new XAttribute("KeyPath", "yes"),
                             new XAttribute("Assembly", ".net"),
                             new XAttribute("AssemblyManifest", fileId),
                             new XAttribute("ProcessorArchitecture", ((Assembly)wFile).ProcessorArchitecture.ToString()));
                }

                wFile.DriverInstaller.Compile(wProject, comp);

                //insert file associations
                foreach (FileAssociation wFileAssociation in wFile.Associations)
                {
                    XElement progId;
                    comp.Add(progId = new XElement("ProgId",
                                          new XAttribute("Id", wFileAssociation.Extension + ".file"),
                                          new XAttribute("Advertise", wFileAssociation.Advertise.ToYesNo()),
                                          new XAttribute("Description", wFileAssociation.Description),
                                          new XElement("Extension",
                                              new XAttribute("Id", wFileAssociation.Extension),
                                              new XAttribute("ContentType", wFileAssociation.ContentType),
                                              new XElement("Verb",
                                                  wFileAssociation.Advertise ?
                                                     new XAttribute("Sequence", wFileAssociation.SequenceNo) :
                                                     new XAttribute("TargetFile", fileId),
                                                  new XAttribute("Id", wFileAssociation.Command),
                                                  new XAttribute("Command", wFileAssociation.Command),
                                                  new XAttribute("Argument", wFileAssociation.Arguments)))));

                    if (wFileAssociation.Icon != null)
                    {
                        progId.Add(
                            new XAttribute("Icon", wFileAssociation.Icon != "" ? wFileAssociation.Icon : fileId),
                            new XAttribute("IconIndex", wFileAssociation.IconIndex));
                    }
                }

                //insert file owned shortcuts
                foreach (Shortcut wShortcut in wFile.Shortcuts)
                {
                    string locationDirId;

                    if (wShortcut.Location.IsEmpty())
                    {
                        locationDirId = wDir.Id;
                    }
                    else
                    {
                        Dir locationDir = wProject.FindDir(wShortcut.Location);

                        if (locationDir != null)
                        {
                            locationDirId = locationDir.Id;
                        }
                        else
                        {
                            if (!autogeneratedShortcutLocations.ContainsKey(wShortcut.Location))
                                autogeneratedShortcutLocations.Add(wShortcut.Location, wShortcut.Feature);

                            locationDirId = wShortcut.Location.Expand();
                        }
                    }

                    var shortcutElement =
//.........这里部分代码省略.........
开发者ID:Eun,项目名称:WixSharp,代码行数:101,代码来源:Compiler.cs

示例11: PostProcessMsm

        static void PostProcessMsm(Project project, XElement product)
        {
            var modules = from dir in project.AllDirs
                          from msm in dir.MergeModules
                          select new
                          {
                              Feature = msm.Feature,
                              MsmId = msm.Id
                          };

            var features = product.Descendants("Feature")
                                  .ToDictionary(x => x.Attribute("Id").Value);

            foreach (var item in modules)
            {
                XElement xFeature;

                if (item.Feature == null)
                {
                    if (features.ContainsKey("Complete"))
                        xFeature = features["Complete"];
                    else
                        throw new Exception("Merge Module " + item.MsmId + " does not belong to any feature and \"Complete\" feature is not found");
                }
                else
                {
                    if (features.ContainsKey(item.Feature.Id))
                    {
                        xFeature = features[item.Feature.Id];
                    }
                    else
                    {
                        xFeature = product.AddElement(item.Feature.ToXml());
                        features.Add(item.Feature.Id, xFeature);
                    }
                }

                xFeature.Add(new XElement("MergeRef",
                                 new XAttribute("Id", item.MsmId)));
            }
        }
开发者ID:Eun,项目名称:WixSharp,代码行数:41,代码来源:Compiler.cs

示例12: CrteateComponentFor

        static XElement CrteateComponentFor(this XDocument doc, XElement xDir)
        {
            string compId = xDir.Attribute("Id").Value;
            XElement xComponent = xDir.AddElement(
                              new XElement("Component",
                                  new XAttribute("Id", compId),
                                  new XAttribute("Guid", WixGuid.NewGuid(compId))));

            foreach (XElement xFeature in doc.Root.Descendants("Feature"))
                xFeature.Add(new XElement("ComponentRef",
                    new XAttribute("Id", xComponent.Attribute("Id").Value)));

            return xComponent;
        }
开发者ID:denis-peshkov,项目名称:WixSharp,代码行数:14,代码来源:AutoElements.cs

示例13: Write

        public static XElement Write(CSDLContainer csdlContainer)
        {
            // Instantiate Schema
            XElement schema = new XElement(csdlNamespace + "Schema",
                new XAttribute("Namespace", csdlContainer.Namespace),
                new XAttribute("Alias", csdlContainer.Alias),
                new XAttribute(XNamespace.Xmlns + "annotation", csdlAnnotationNamespace.NamespaceName),
                new XAttribute("xmlns", csdlNamespace.NamespaceName));

            // EntityContainer
            string entityContainerNamespace = string.Concat(csdlContainer.Namespace, ".");
            XElement entityContainer = new XElement(csdlNamespace + "EntityContainer", new XAttribute("Name", csdlContainer.Name));
            schema.Add(entityContainer);

            // EntityContainer : EntitySets
            foreach (EntityType entityType in csdlContainer.EntitySets)
            {
                XElement entitySetElement = new XElement(csdlNamespace + "EntitySet",
                    new XAttribute("Name", entityType.EntitySetName), 
                    new XAttribute("EntityType", string.Concat(entityContainerNamespace, entityType.Name)));
                    //.AddAttribute(csdlCodeGenerationNamespace, "GetterAccess", entityType.EntitySetVisibility); // Not available in EF 4.0

                entityContainer.Add(entitySetElement);
            }

            // EntityContainer : AssociationSets
            foreach (Association association in csdlContainer.Associations)
            {
                XElement associationSetElement = new XElement(csdlNamespace + "AssociationSet",
                    new XAttribute("Name", association.AssociationSetName),
                    new XAttribute("Association", string.Concat(entityContainerNamespace, association.Name)));

                associationSetElement.Add(
                    new XElement(csdlNamespace + "End", new XAttribute("Role", association.PropertyEnd1Role), new XAttribute("EntitySet", association.PropertyEnd1.EntityType.EntitySetName)),
                    new XElement(csdlNamespace + "End", new XAttribute("Role", association.PropertyEnd2Role), new XAttribute("EntitySet", association.PropertyEnd2.EntityType.EntitySetName)));

                entityContainer.AddElement(associationSetElement);
            }

            // EntityContainer : FunctionImports
            foreach (Function function in csdlContainer.Functions)
            {
                XElement functionElement = new XElement(csdlNamespace + "FunctionImport",
                    new XAttribute("Name", function.Name))
                    .AddAttribute("EntitySet", function.EntityType == null ? null : function.EntityType.EntitySetName)
                    .AddAttribute("ReturnType", function.ReturnType);

                foreach (FunctionParameter functionParameter in function.Parameters)
                {
                    functionElement.AddElement(new XElement(csdlNamespace + "Paramter",
                        new XAttribute("Name", functionParameter.Name),
                        new XAttribute("Type", functionParameter.Type))
                        .AddAttribute("MaxLength", functionParameter.MaxLength)
                        .AddAttribute("Mode", functionParameter.Mode)
                        .AddAttribute("Precision", functionParameter.Precision)
                        .AddAttribute("Scale", functionParameter.Scale));
                }

                entityContainer.AddElement(functionElement);
            }

            // ComplexTypes
            foreach (ComplexType complexType in csdlContainer.ComplexTypes)
            {
                XElement complexTypeElement = new XElement(csdlNamespace + "ComplexType",
                    new XAttribute("Name", complexType.Name));
                    //.AddAttribute(new XAttribute(csdlCodeGenerationNamespace + "TypeAccess", complexType.Visibility)); // Not available in EF 4.0

                complexTypeElement.Add(WriteScalarProperties(complexType));
                complexTypeElement.Add(WriteComplexProperties(complexType, string.Concat(csdlContainer.Alias, ".")));

                schema.AddElement(complexTypeElement);
            }

            // EntityTypes
            foreach (EntityType entityType in csdlContainer.EntityTypes)
            {
                XElement entityTypeElement = new XElement(csdlNamespace + "EntityType")
                    .AddAttribute("Name", entityType.Name)
                    //.AddAttribute(csdlCodeGenerationNamespace, "TypeAccess", entityType.Visibility) // Not available in EF 4.0
                    .AddAttribute("BaseType", entityType.BaseType == null ? null : string.Concat(entityContainerNamespace, entityType.BaseType.Name))
                    .AddAttribute("Abstract", entityType.Abstract);

                if (entityType.SpecificKeys.Any())
                {
                    XElement keyElement = new XElement(csdlNamespace + "Key");
                    
                    entityType.ScalarProperties.Where(sp => sp.IsKey).ForEach(scalarProperty =>
                    {
                        keyElement.AddElement(new XElement(csdlNamespace + "PropertyRef")
                            .AddAttribute("Name", scalarProperty.Name));                        
                    });

                    entityTypeElement.AddElement(keyElement);
                }

                entityTypeElement.Add(WriteScalarProperties(entityType));
                entityTypeElement.Add(WriteComplexProperties(entityType, string.Concat(csdlContainer.Alias, ".")));

                // EntityType : NavigationProperties
//.........这里部分代码省略.........
开发者ID:hpsa,项目名称:SharpDevelop,代码行数:101,代码来源:CSDLIO.cs

示例14: WriteXElement

        public static XElement WriteXElement(SSDLContainer ssdlContainer)
        {
            // Instantiate Schema
            XElement schema = new XElement(ssdlNamespace + "Schema",
                new XAttribute("Namespace", ssdlContainer.Namespace), 
                new XAttribute("Alias", "Self"),
                new XAttribute(XNamespace.Xmlns + "store", storeNamespace.NamespaceName),
                new XAttribute("xmlns", ssdlNamespace.NamespaceName))
                .AddAttribute("Provider", ssdlContainer.Provider)
                .AddAttribute("ProviderManifestToken", ssdlContainer.ProviderManifestToken);
            
            // EntityContainer
            string entityContainerNamespace = string.Concat(ssdlContainer.Namespace, ".");
            XElement entityContainer = new XElement(ssdlNamespace + "EntityContainer", new XAttribute("Name", ssdlContainer.Name));
            schema.Add(entityContainer);

            // EntityContainer : EntitySets
            foreach (EntityType entityType in ssdlContainer.EntityTypes)
            {
                XElement entitySet = new XElement(ssdlNamespace + "EntitySet",
                    new XAttribute("Name", entityType.EntitySetName), new XAttribute("EntityType", string.Concat(entityContainerNamespace, entityType.Name)))
                        .AddAttribute(entityType.StoreType == StoreType.Views ? null : new XAttribute("Schema", entityType.Schema))
                        .AddAttribute("Table", entityType.Table)
                        .AddAttribute(storeNamespace, "Name", entityType.StoreName)
                        .AddAttribute(storeNamespace, "Schema", entityType.StoreSchema)
                        .AddAttribute(storeNamespace, "Type", entityType.StoreType)
                        .AddElement(string.IsNullOrEmpty(entityType.DefiningQuery) ? null : new XElement(ssdlNamespace + "DefiningQuery", entityType.DefiningQuery));

                entityContainer.Add(entitySet);
            }

            // EntityContainer : Associations
            foreach (Association association in ssdlContainer.AssociationSets)
            {
                XElement associationSet = new XElement(ssdlNamespace + "AssociationSet", 
                    new XAttribute("Name", association.AssociationSetName), new XAttribute("Association", string.Concat(entityContainerNamespace, association.Name)));

                string role2Name = association.Role2.Name;

                // If the association end properties are the same properties
                if (association.Role1.Name == association.Role2.Name && association.Role1.Type.Name == association.Role2.Type.Name)
                    role2Name += "1";

                associationSet.Add(
                        new XElement(ssdlNamespace + "End", new XAttribute("Role", association.Role1.Name), new XAttribute("EntitySet", association.Role1.Type.Name)),
                        new XElement(ssdlNamespace + "End", new XAttribute("Role", role2Name), new XAttribute("EntitySet", association.Role2.Type.Name)));
            
                entityContainer.Add(associationSet);
            }

            // EntityTypes
            foreach (EntityType entityType in ssdlContainer.EntityTypes)
            {
                XElement entityTypeElement = new XElement(ssdlNamespace + "EntityType", new XAttribute("Name", entityType.Name));

                XElement keys = new XElement(ssdlNamespace + "Key");

                foreach (Property property in entityType.Properties)
                {
                    // If we have a table then we set a key element if the current property is a primary key or part of a composite key.
                    // AND: If we have a view then we make a composite key of all non-nullable properties of the entity (VS2010 is also doing this).
                    if ((entityType.StoreType == StoreType.Tables && property.IsKey) || (entityType.StoreType == StoreType.Views && property.Nullable == false))
                        keys.Add(new XElement(ssdlNamespace + "PropertyRef", new XAttribute("Name", property.Name)));
                }

                if (!keys.IsEmpty)
                    entityTypeElement.Add(keys);

                foreach (Property property in entityType.Properties)
                {
                    entityTypeElement.Add(new XElement(ssdlNamespace + "Property", new XAttribute("Name", property.Name), new XAttribute("Type", property.Type))
                        .AddAttribute("Collation", property.Collation)
                        .AddAttribute("DefaultValue", property.DefaultValue)
                        .AddAttribute("FixedLength", property.FixedLength)
                        .AddAttribute("MaxLength", property.MaxLength)
                        .AddAttribute("Nullable", property.Nullable)
                        .AddAttribute("Precision", property.Precision)
                        .AddAttribute("Scale", property.Scale)
                        .AddAttribute("StoreGeneratedPattern", property.StoreGeneratedPattern)
                        .AddAttribute(storeNamespace, "Name", property.StoreName)
                        .AddAttribute(storeNamespace, "Schema", property.StoreSchema)
                        .AddAttribute(storeNamespace, "Type", property.StoreType)
                        .AddAttribute("Unicode", property.Unicode));
                }

                schema.AddElement(entityTypeElement);
            }

            foreach (Association association in ssdlContainer.AssociationSets)
            {
                string role2Name = association.Role2.Name;

                // If the association end properties are the same properties
                if (association.Role1.Name == association.Role2.Name && association.Role1.Type.Name == association.Role2.Type.Name)
                    role2Name += "1";
                
                XElement associationElement = new XElement(ssdlNamespace + "Association", new XAttribute("Name", association.Name),
                        new XElement(ssdlNamespace + "End", new XAttribute("Role", association.Role1.Name), new XAttribute("Type", string.Concat(entityContainerNamespace, association.Role1.Type.Name)), new XAttribute("Multiplicity", CardinalityStringConverter.CardinalityToString(association.Role1.Cardinality))),
                        new XElement(ssdlNamespace + "End", new XAttribute("Role", role2Name), new XAttribute("Type", string.Concat(entityContainerNamespace, association.Role2.Type.Name)), new XAttribute("Multiplicity", CardinalityStringConverter.CardinalityToString(association.Role2.Cardinality))));

//.........这里部分代码省略.........
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:101,代码来源:SSDLIO.cs

示例15: ToXElement

        /// <summary>
        /// Converts the <see cref="T:WixSharp.Control"/> instance into WiX <see cref="T:System.Xml.Linq.XElement"/>.
        /// </summary>
        /// <returns><see cref="T:System.Xml.Linq.XElement"/> instance.</returns>
        public virtual XElement ToXElement()
        {
            var control =
                new XElement("Control",
                    new XAttribute("Id", this.Id),
                    new XAttribute("Width", this.Width),
                    new XAttribute("Height", this.Height),
                    new XAttribute("X", this.X),
                    new XAttribute("Y", this.Y),
                    new XAttribute("Type", this.Type))
                    .AddAttributes(this.Attributes);

            if (!Property.IsEmpty()) control.Add(new XAttribute("Property", this.Property));

            if (Hidden) control.Add(new XAttribute("Hidden", this.Hidden.ToYesNo()));

            if (Disabled) control.Add(new XAttribute("Disabled", this.Disabled.ToYesNo()));

            if (!Tooltip.IsEmpty()) control.Add(new XAttribute("ToolTip", this.Tooltip));
            if (!Text.IsEmpty()) control.Add(new XElement("Text", this.Text));

            if (!EmbeddedXML.IsEmpty())
            {
                foreach (var element in XDocument.Parse("<root>" + EmbeddedXML + "</root>").Root.Elements())
                    control.Add(element);
            }

            int index = 0;
            foreach (ControlActionData data in Actions)
            {
                index++;
                var publishElement = control.AddElement(new XElement("Publish",
                                                            new XAttribute("Value", data.Value),
                                                            new XAttribute("Order", index),
                                                            data.Condition));
                if (!data.Event.IsEmpty())
                    publishElement.Add(new XAttribute("Event", data.Event));

                if (!data.Property.IsEmpty())
                    publishElement.Add(new XAttribute("Property", data.Property));
            }

            foreach (WixControlCondition condition in Conditions)
            {
                control.AddElement(new XElement("Condition",
                                       new XAttribute("Action", condition.Action.ToString()),
                                       condition.Value));
            }

            return control;
        }
开发者ID:denis-peshkov,项目名称:WixSharp,代码行数:55,代码来源:Control.cs


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