本文整理汇总了C#中Project.GetProjectItemByName方法的典型用法代码示例。如果您正苦于以下问题:C# Project.GetProjectItemByName方法的具体用法?C# Project.GetProjectItemByName怎么用?C# Project.GetProjectItemByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Project
的用法示例。
在下文中一共展示了Project.GetProjectItemByName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckFilesCodeFirst
private static void CheckFilesCodeFirst(Project project)
{
var modelfile = project.GetProjectItemByName("Model1.cs");
Assert.IsNotNull(modelfile, "modelfile is null");
var coursfile = project.GetProjectItemByName("Cours.cs");
Assert.IsNotNull(coursfile, "coursfile is null");
var departmentfile = project.GetProjectItemByName("Department.cs");
Assert.IsNotNull(departmentfile, "departmentfile is null");
var officeassignmentfile = project.GetProjectItemByName("OfficeAssignment.cs");
Assert.IsNotNull(officeassignmentfile, "officeassignmentfile is null");
var personfile = project.GetProjectItemByName("Person.cs");
Assert.IsNotNull(personfile, "personfile is null");
var studentgradefile = project.GetProjectItemByName("StudentGrade.cs");
Assert.IsNotNull(studentgradefile, "studentgradefile is null");
}
示例2: CheckFilesExistingModel
private static void CheckFilesExistingModel(Project project)
{
var csfile = project.GetProjectItemByName("Model1.designer.cs");
Assert.IsNotNull(csfile, "csfile is null");
var diagramFile = project.GetProjectItemByName("Model1.edmx.diagram");
Assert.IsNotNull(diagramFile, "diagramfile is null");
var contextFile = project.GetProjectItemByName("Model1.context.cs");
Assert.IsNotNull(contextFile, "context is null");
var ttFile = project.GetProjectItemByName("Model1.tt");
Assert.IsNotNull(ttFile, "ttfile is null");
var personfile = project.GetProjectItemByName("person.cs");
Assert.IsNotNull(personfile, "personfile is null");
var edmxFile = project.GetProjectItemByName("Model1.edmx");
Assert.IsNotNull(edmxFile, "edmxfile is null");
var edmxPath = edmxFile.Properties.Item("FullPath").Value.ToString();
var xmlEntries = XDocument.Load(edmxPath);
var edmx = XNamespace.Get("http://schemas.microsoft.com/ado/2009/11/edmx");
var ssdl = XNamespace.Get("http://schemas.microsoft.com/ado/2009/11/edm/ssdl");
var cs = XNamespace.Get("http://schemas.microsoft.com/ado/2009/11/mapping/cs");
var element = xmlEntries.Elements(edmx + "Edmx")
.Elements(edmx + "Runtime")
.Elements(edmx + "StorageModels")
.Elements(ssdl + "Schema").First();
Assert.IsNotNull(element);
Assert.AreEqual((string)element.Attribute("Namespace"), "SchoolModel.Store");
Assert.AreEqual((string)element.Attribute("Provider"), "System.Data.SqlClient");
var entityTypes = (from el in element.Elements(ssdl + "EntityType") select el.Attribute("Name").Value).ToList();
foreach (var entityName in _entityNames.Where(entityName => !entityName.Contains("Migration")))
{
Assert.IsTrue(entityTypes.Any(el => el.Equals(entityName)), string.Format("Looking for Entity name:" + entityName));
}
element =
(from el in
element.Elements(ssdl + "EntityType")
.Where(el => el.Attribute("Name").Value.Equals("People", StringComparison.CurrentCulture))
.Descendants(ssdl + "Property")
where (string)el.Attribute("Name") == "PersonID"
select el).First();
Assert.AreEqual((string)element.Attribute("Type"), "int");
Assert.AreEqual((string)element.Attribute("StoreGeneratedPattern"), "Identity");
Assert.AreEqual((string)element.Attribute("Nullable"), "false");
element = xmlEntries.Elements(edmx + "Edmx")
.Elements(edmx + "Runtime")
.Elements(edmx + "Mappings")
.Elements(cs + "Mapping")
.Elements(cs + "EntityContainerMapping").First();
Assert.AreEqual((string)element.Attribute("StorageEntityContainer"), "SchoolModelStoreContainer");
Assert.AreEqual((string)element.Attribute("CdmEntityContainer"), "SchoolEntities");
}
示例3: CheckAppConfig
private static void CheckAppConfig(Project project)
{
var appConfigFile = project.GetProjectItemByName("app.config");
var appConfigPath = appConfigFile.Properties.Item("FullPath").Value.ToString();
var xmlEntries = XDocument.Load(appConfigPath);
var element = xmlEntries.Elements("configuration")
.Elements("connectionStrings")
.Elements("add").First();
Assert.AreEqual((string)element.Attribute("name"), "SchoolEntities");
}
示例4: CheckFilesEmptyModel
private static void CheckFilesEmptyModel(Project project)
{
var edmxFile = project.GetProjectItemByName("Model1.edmx");
Assert.IsNotNull(edmxFile, "edmxfile is null");
var edmxPath = edmxFile.Properties.Item("FullPath").Value.ToString();
var xmlEntries = XDocument.Load(edmxPath);
var edmx = XNamespace.Get("http://schemas.microsoft.com/ado/2009/11/edmx");
var edm = XNamespace.Get("http://schemas.microsoft.com/ado/2009/11/edm");
var conceptualElement = xmlEntries.Elements(edmx + "Edmx")
.Elements(edmx + "Runtime")
.Elements(edmx + "ConceptualModels")
.Elements(edm + "Schema").First();
Assert.AreEqual((string)conceptualElement.Attribute("Namespace"), "Model1");
var entity1Element = (from el in conceptualElement.Descendants(edm + "EntityType")
where (string)el.Attribute("Name") == "Entity_1"
select el).First();
Assert.IsNotNull(entity1Element);
var entity2Element = (from el in conceptualElement.Descendants(edm + "EntityType")
where (string)el.Attribute("Name") == "Entity_2"
select el).First();
Assert.IsNotNull(entity2Element);
var entity3Element = (from el in conceptualElement.Descendants(edm + "EntityType")
where (string)el.Attribute("Name") == "Entity_3"
select el).First();
Assert.IsNotNull(entity3Element);
var entity4Element = (from el in conceptualElement.Descendants(edm + "EntityType")
where (string)el.Attribute("Name") == "Entity_4"
select el).First();
Assert.IsNotNull(entity4Element);
var association1Element = (from el in conceptualElement.Descendants(edm + "Association")
where (string)el.Attribute("Name") == "Entity_1Entity_2"
select el).First();
Assert.IsNotNull(association1Element);
var association2Element = (from el in conceptualElement.Descendants(edm + "Association")
where (string)el.Attribute("Name") == "Entity_3Entity_4"
select el).First();
Assert.IsNotNull(association2Element);
var association3Element = (from el in conceptualElement.Descendants(edm + "Association")
where (string)el.Attribute("Name") == "Entity_1Entity_3"
select el).First();
Assert.IsNotNull(association3Element);
var enumElement = (from el in conceptualElement.Descendants(edm + "EnumType")
where (string)el.Attribute("Name") == "EnumType5"
select el).First();
Assert.IsNotNull(enumElement);
}
示例5: TestLoadingArtifact
private void TestLoadingArtifact(Project project, string filePath, ArtifactStatus expectedArtifactStatus)
{
Assert.IsNotNull(expectedArtifactStatus);
// get a new artifact, which will automatically open up the EDMX file in VS
EntityDesignArtifact entityDesignArtifact = null;
try
{
var edmxProjectItem = project.GetProjectItemByName(Path.GetFileName(filePath));
Assert.IsNotNull(edmxProjectItem);
Dte.OpenFile(edmxProjectItem.FileNames[0]);
entityDesignArtifact =
(EntityDesignArtifact)_efArtifactHelper.GetNewOrExistingArtifact(
TestUtils.FileName2Uri(edmxProjectItem.FileNames[0]));
Assert.AreEqual(expectedArtifactStatus.IsStructurallySafe, entityDesignArtifact.IsStructurallySafe);
Assert.AreEqual(expectedArtifactStatus.IsVersionSafe, entityDesignArtifact.IsVersionSafe);
Assert.AreEqual(expectedArtifactStatus.IsDesignerSafe, entityDesignArtifact.IsDesignerSafe);
}
finally
{
if (entityDesignArtifact != null)
{
Dte.CloseDocument(entityDesignArtifact.Uri.LocalPath, false);
}
}
}