本文整理汇总了C#中PropertyDictionary.Set方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyDictionary.Set方法的具体用法?C# PropertyDictionary.Set怎么用?C# PropertyDictionary.Set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyDictionary
的用法示例。
在下文中一共展示了PropertyDictionary.Set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateToolsetTranslation
public void ValidateToolsetTranslation()
{
PropertyDictionary<ProjectPropertyInstance> buildProperties = new PropertyDictionary<ProjectPropertyInstance>();
buildProperties.Set(ProjectPropertyInstance.Create("a", "a1"));
PropertyDictionary<ProjectPropertyInstance> environmentProperties = new PropertyDictionary<ProjectPropertyInstance>();
environmentProperties.Set(ProjectPropertyInstance.Create("b", "b1"));
PropertyDictionary<ProjectPropertyInstance> globalProperties = new PropertyDictionary<ProjectPropertyInstance>();
globalProperties.Set(ProjectPropertyInstance.Create("c", "c1"));
PropertyDictionary<ProjectPropertyInstance> subToolsetProperties = new PropertyDictionary<ProjectPropertyInstance>();
subToolsetProperties.Set(ProjectPropertyInstance.Create("d", "d1"));
Dictionary<string, SubToolset> subToolsets = new Dictionary<string, SubToolset>(StringComparer.OrdinalIgnoreCase);
subToolsets.Add("dogfood", new SubToolset("dogfood", subToolsetProperties));
Toolset t = new Toolset("4.0", "c:\\bar", buildProperties, environmentProperties, globalProperties, subToolsets, "c:\\foo", "4.0");
((INodePacketTranslatable)t).Translate(TranslationHelpers.GetWriteTranslator());
Toolset t2 = Toolset.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());
Assert.Equal(t.ToolsVersion, t2.ToolsVersion);
Assert.Equal(t.ToolsPath, t2.ToolsPath);
Assert.Equal(t.OverrideTasksPath, t2.OverrideTasksPath);
Assert.Equal(t.Properties.Count, t2.Properties.Count);
foreach (string key in t.Properties.Keys)
{
Assert.Equal(t.Properties[key].Name, t2.Properties[key].Name);
Assert.Equal(t.Properties[key].EvaluatedValue, t2.Properties[key].EvaluatedValue);
}
Assert.Equal(t.SubToolsets.Count, t2.SubToolsets.Count);
foreach (string key in t.SubToolsets.Keys)
{
SubToolset subToolset1 = t.SubToolsets[key];
SubToolset subToolset2 = null;
if (t2.SubToolsets.TryGetValue(key, out subToolset2))
{
Assert.Equal(subToolset1.SubToolsetVersion, subToolset2.SubToolsetVersion);
Assert.Equal(subToolset1.Properties.Count, subToolset2.Properties.Count);
foreach (string subToolsetPropertyKey in subToolset1.Properties.Keys)
{
Assert.Equal(subToolset1.Properties[subToolsetPropertyKey].Name, subToolset2.Properties[subToolsetPropertyKey].Name);
Assert.Equal(subToolset1.Properties[subToolsetPropertyKey].EvaluatedValue, subToolset2.Properties[subToolsetPropertyKey].EvaluatedValue);
}
}
else
{
Assert.True(false, string.Format("Sub-toolset {0} was lost in translation.", key));
}
}
Assert.Equal(t.DefaultOverrideToolsVersion, t2.DefaultOverrideToolsVersion);
}
示例2: MatchProperty
public void MatchProperty()
{
PropertyDictionary<ProjectPropertyInstance> dictionary = new PropertyDictionary<ProjectPropertyInstance>();
ProjectPropertyInstance p = ProjectPropertyInstance.Create("foo", "bar");
dictionary.Set(p);
string s = "$(foo)";
ProjectPropertyInstance value = MSBuildNameIgnoreCaseComparer.Mutable.GetValueWithConstraints<ProjectPropertyInstance>(dictionary, s, 2, 4);
Assert.IsTrue(Object.ReferenceEquals(p, value), "Should have returned the same object as was inserted");
try
{
MSBuildNameIgnoreCaseComparer.Mutable.SetConstraintsForUnitTestingOnly(s, 2, 4);
Assert.AreEqual(MSBuildNameIgnoreCaseComparer.Default.GetHashCode("foo"), MSBuildNameIgnoreCaseComparer.Mutable.GetHashCode(s));
}
finally
{
MSBuildNameIgnoreCaseComparer.Mutable.RemoveConstraintsForUnitTestingOnly();
}
}
示例3: CreateItemFunctionExpander
/// <summary>
/// Creates an expander populated with some ProjectPropertyInstances and ProjectPropertyItems.
/// </summary>
/// <returns></returns>
private Expander<ProjectPropertyInstance, ProjectItemInstance> CreateItemFunctionExpander()
{
ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();
pg.Set(ProjectPropertyInstance.Create("p", "v0"));
pg.Set(ProjectPropertyInstance.Create("p", "v1"));
pg.Set(ProjectPropertyInstance.Create("Val", "2"));
pg.Set(ProjectPropertyInstance.Create("a", "filename"));
ItemDictionary<ProjectItemInstance> ig = new ItemDictionary<ProjectItemInstance>();
for (int n = 0; n < 10; n++)
{
ProjectItemInstance pi = new ProjectItemInstance(project, "i", "i" + n.ToString(), project.FullPath);
for (int m = 0; m < 5; m++)
{
pi.SetMetadata("Meta" + m.ToString(), @"c:\firstdirectory\seconddirectory\file" + m.ToString() + ".ext");
}
pi.SetMetadata("Meta9", @"seconddirectory\file.ext");
pi.SetMetadata("Meta10", @";someo%3bherplace\foo.txt;secondd%3brectory\file.ext;");
pi.SetMetadata("MetaBlank", @"");
if (n % 2 > 0)
{
pi.SetMetadata("Even", "true");
pi.SetMetadata("Odd", "false");
}
else
{
pi.SetMetadata("Even", "false");
pi.SetMetadata("Odd", "true");
}
ig.Add(pi);
}
Dictionary<string, string> itemMetadataTable = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
itemMetadataTable["Culture"] = "abc%253bdef;$(Gee_Aych_Ayee)";
itemMetadataTable["Language"] = "english";
IMetadataTable itemMetadata = new StringMetadataTable(itemMetadataTable);
Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg, ig, itemMetadata);
return expander;
}
示例4: PropertyFunctionConsumingItemMetadata
public void PropertyFunctionConsumingItemMetadata()
{
ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();
Dictionary<string, string> itemMetadataTable = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
itemMetadataTable["Compile.Identity"] = "fOo.Cs";
StringMetadataTable itemMetadata = new StringMetadataTable(itemMetadataTable);
List<ProjectItemInstance> ig = new List<ProjectItemInstance>();
pg.Set(ProjectPropertyInstance.Create("SomePath", @"c:\some\path"));
ig.Add(new ProjectItemInstance(project, "Compile", "fOo.Cs", project.FullPath));
ItemDictionary<ProjectItemInstance> itemsByType = new ItemDictionary<ProjectItemInstance>();
itemsByType.ImportItems(ig);
Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg, itemsByType, itemMetadata);
string result = expander.ExpandIntoStringLeaveEscaped(@"$([System.IO.Path]::Combine($(SomePath),%(Compile.Identity)))", ExpanderOptions.ExpandAll, MockElementLocation.Instance);
Assert.Equal(@"c:\some\path\fOo.Cs", result);
}
示例5: PropertySimpleSpaced
public void PropertySimpleSpaced()
{
PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();
pg.Set(ProjectPropertyInstance.Create("SomeStuff", "This IS SOME STUff"));
Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg);
string result = expander.ExpandIntoStringLeaveEscaped(@"$( SomeStuff )", ExpanderOptions.ExpandProperties, MockElementLocation.Instance);
Assert.Equal(String.Empty, result);
}
示例6: PropertyFunctionStaticMethodRegex1
public void PropertyFunctionStaticMethodRegex1()
{
PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();
pg.Set(ProjectPropertyInstance.Create("File", @"foo\file.txt"));
Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg);
// Support enum combines as Enum.Parse expects them
string result = expander.ExpandIntoStringLeaveEscaped(@"$([System.Text.RegularExpressions.Regex]::IsMatch(`-42`, `^-?\d+(\.\d{2})?$`, `RegexOptions.IgnoreCase,RegexOptions.Singleline`))", ExpanderOptions.ExpandProperties, MockElementLocation.Instance);
Assert.Equal(@"True", result);
// We support the C# style enum combining syntax too
result = expander.ExpandIntoStringLeaveEscaped(@"$([System.Text.RegularExpressions.Regex]::IsMatch(`-42`, `^-?\d+(\.\d{2})?$`, System.Text.RegularExpressions.RegexOptions.IgnoreCase|RegexOptions.Singleline))", ExpanderOptions.ExpandProperties, MockElementLocation.Instance);
Assert.Equal(@"True", result);
result = expander.ExpandIntoStringLeaveEscaped(@"$([System.Text.RegularExpressions.Regex]::IsMatch(`100 GBP`, `^-?\d+(\.\d{2})?$`))", ExpanderOptions.ExpandProperties, MockElementLocation.Instance);
Assert.Equal(@"False", result);
}
示例7: PropertyFunctionConstructor2
public void PropertyFunctionConstructor2()
{
PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();
pg.Set(ProjectPropertyInstance.Create("ver1", @"1.2.3.4"));
pg.Set(ProjectPropertyInstance.Create("ver2", @"2.2.3.4"));
Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg);
string result = expander.ExpandIntoStringLeaveEscaped(@"$([System.Version]::new($(ver1)).CompareTo($([System.Version]::new($(ver2)))))", ExpanderOptions.ExpandProperties, MockElementLocation.Instance);
Assert.Equal(@"-1", result);
}
示例8: PropertyFunctionStaticMethodMakeRelative
public void PropertyFunctionStaticMethodMakeRelative()
{
PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();
pg.Set(ProjectPropertyInstance.Create("ParentPath", @"c:\abc\def"));
pg.Set(ProjectPropertyInstance.Create("FilePath", @"c:\abc\def\foo.cpp"));
Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg);
string result = expander.ExpandIntoStringLeaveEscaped(@"$([MSBuild]::MakeRelative($(ParentPath), `$(FilePath)`))", ExpanderOptions.ExpandProperties, MockElementLocation.Instance);
Assert.Equal(@"foo.cpp", result);
}
示例9: PropertyFunctionNoArgumentsTrim
public void PropertyFunctionNoArgumentsTrim()
{
PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();
pg.Set(ProjectPropertyInstance.Create("FileName", " foo.ext "));
Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg);
string result = expander.ExpandIntoStringLeaveEscaped("$(FileName.Trim())", ExpanderOptions.ExpandProperties, MockElementLocation.Instance);
Assert.Equal("foo.ext", result);
}
示例10: PropertyFunctionNullReturn
public void PropertyFunctionNullReturn()
{
PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();
pg.Set(ProjectPropertyInstance.Create("SomeStuff", "This IS SOME STUff"));
Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg);
string result = expander.ExpandIntoStringLeaveEscaped("$([System.Convert]::ChangeType(,$(SomeStuff.GetType())))", ExpanderOptions.ExpandProperties, MockElementLocation.Instance);
Assert.Equal("", result);
}
示例11: ExpandPropertiesIntoProjectPropertyInstances
public void ExpandPropertiesIntoProjectPropertyInstances()
{
ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();
pg.Set(ProjectPropertyInstance.Create("a", "aaa"));
pg.Set(ProjectPropertyInstance.Create("b", "bbb"));
pg.Set(ProjectPropertyInstance.Create("c", "cc;dd"));
Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg);
ProjectItemInstanceFactory itemFactory = new ProjectItemInstanceFactory(project, "i");
IList<ProjectItemInstance> itemsOut = expander.ExpandIntoItemsLeaveEscaped("foo$(a);$(b);$(c);$(d", itemFactory, ExpanderOptions.ExpandProperties, MockElementLocation.Instance);
Assert.Equal(5, itemsOut.Count);
}
示例12: StringMetadataTable
/// <summary>
/// Creates a set of complicated item metadata and properties, and items to exercise
/// the Expander class. The data here contains escaped characters, metadata that
/// references properties, properties that reference items, and other complex scenarios.
/// </summary>
/// <param name="pg"></param>
/// <param name="primaryItemsByName"></param>
/// <param name="secondaryItemsByName"></param>
/// <param name="itemMetadata"></param>
private void CreateComplexPropertiesItemsMetadata
(
out ReadOnlyLookup readOnlyLookup,
out StringMetadataTable itemMetadata
)
{
ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
Dictionary<string, string> itemMetadataTable = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
itemMetadataTable["Culture"] = "abc%253bdef;$(Gee_Aych_Ayee)";
itemMetadataTable["Language"] = "english";
itemMetadata = new StringMetadataTable(itemMetadataTable);
PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();
pg.Set(ProjectPropertyInstance.Create("Gee_Aych_Ayee", "ghi"));
pg.Set(ProjectPropertyInstance.Create("OutputPath", @"\jk ; l\mno%253bpqr\stu"));
pg.Set(ProjectPropertyInstance.Create("TargetPath", "@(IntermediateAssembly->'%(RelativeDir)')"));
List<ProjectItemInstance> intermediateAssemblyItemGroup = new List<ProjectItemInstance>();
ProjectItemInstance i1 = new ProjectItemInstance(project, "IntermediateAssembly", @"subdir1\engine.dll", project.FullPath);
intermediateAssemblyItemGroup.Add(i1);
i1.SetMetadata("aaa", "111");
ProjectItemInstance i2 = new ProjectItemInstance(project, "IntermediateAssembly", @"subdir2\tasks.dll", project.FullPath);
intermediateAssemblyItemGroup.Add(i2);
i2.SetMetadata("bbb", "222");
List<ProjectItemInstance> contentItemGroup = new List<ProjectItemInstance>();
ProjectItemInstance i3 = new ProjectItemInstance(project, "Content", "splash.bmp", project.FullPath);
contentItemGroup.Add(i3);
i3.SetMetadata("ccc", "333");
List<ProjectItemInstance> resourceItemGroup = new List<ProjectItemInstance>();
ProjectItemInstance i4 = new ProjectItemInstance(project, "Resource", "string$(p).resx", project.FullPath);
resourceItemGroup.Add(i4);
i4.SetMetadata("ddd", "444");
ProjectItemInstance i5 = new ProjectItemInstance(project, "Resource", "dialogs%253b.resx", project.FullPath);
resourceItemGroup.Add(i5);
i5.SetMetadata("eee", "555");
List<ProjectItemInstance> contentItemGroup2 = new List<ProjectItemInstance>();
ProjectItemInstance i6 = new ProjectItemInstance(project, "Content", "about.bmp", project.FullPath);
contentItemGroup2.Add(i6);
i6.SetMetadata("fff", "666");
ItemDictionary<ProjectItemInstance> secondaryItemsByName = new ItemDictionary<ProjectItemInstance>();
secondaryItemsByName.ImportItems(resourceItemGroup);
secondaryItemsByName.ImportItems(contentItemGroup2);
Lookup lookup = new Lookup(secondaryItemsByName, pg, null);
// Add primary items
lookup.EnterScope("x");
lookup.PopulateWithItems("IntermediateAssembly", intermediateAssemblyItemGroup);
lookup.PopulateWithItems("Content", contentItemGroup);
readOnlyLookup = new ReadOnlyLookup(lookup);
}
示例13: ExpandAllIntoTaskItems4
public void ExpandAllIntoTaskItems4()
{
PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();
pg.Set(ProjectPropertyInstance.Create("a", "aaa"));
pg.Set(ProjectPropertyInstance.Create("b", "bbb"));
pg.Set(ProjectPropertyInstance.Create("c", "cc;dd"));
Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg);
IList<TaskItem> itemsOut = expander.ExpandIntoTaskItemsLeaveEscaped("foo$(a);$(b);$(c)", ExpanderOptions.ExpandProperties, MockElementLocation.Instance);
ObjectModelHelpers.AssertItemsMatch(@"
fooaaa
bbb
cc
dd
", GetTaskArrayFromItemList(itemsOut));
}
示例14: ModifiedProperty
public void ModifiedProperty()
{
PropertyDictionary<ProjectPropertyInstance> group = new PropertyDictionary<ProjectPropertyInstance>();
group.Set(ProjectPropertyInstance.Create("p1", "v1"));
Lookup lookup = LookupHelpers.CreateLookup(group);
// Enter scope so that property sets are allowed on it
Lookup.Scope enteredScope = lookup.EnterScope("x");
// Change the property value
lookup.SetProperty(ProjectPropertyInstance.Create("p1", "v2"));
// Lookup is updated, but not original item group
Assert.Equal("v2", lookup.GetProperty("p1").EvaluatedValue);
Assert.Equal("v1", group["p1"].EvaluatedValue);
Lookup.Scope enteredScope2 = lookup.EnterScope("x");
// Change the value again in the new scope
lookup.SetProperty(ProjectPropertyInstance.Create("p1", "v3"));
// Lookup is updated, but not the original item group
Assert.Equal("v3", lookup.GetProperty("p1").EvaluatedValue);
Assert.Equal("v1", group["p1"].EvaluatedValue);
Lookup.Scope enteredScope3 = lookup.EnterScope("x");
// Change the value again in the new scope
lookup.SetProperty(ProjectPropertyInstance.Create("p1", "v4"));
Assert.Equal("v4", lookup.GetProperty("p1").EvaluatedValue);
enteredScope3.LeaveScope();
Assert.Equal("v4", lookup.GetProperty("p1").EvaluatedValue);
// Leave to the outer scope
enteredScope2.LeaveScope();
enteredScope.LeaveScope();
// Now the lookup and original group are updated
Assert.Equal("v4", lookup.GetProperty("p1").EvaluatedValue);
Assert.Equal("v4", group["p1"].EvaluatedValue);
}
示例15: UnmodifiedProperty
public void UnmodifiedProperty()
{
PropertyDictionary<ProjectPropertyInstance> group = new PropertyDictionary<ProjectPropertyInstance>();
ProjectPropertyInstance property = ProjectPropertyInstance.Create("p1", "v1");
group.Set(property);
Lookup lookup = LookupHelpers.CreateLookup(group);
Assert.Equal(property, lookup.GetProperty("p1"));
Lookup.Scope enteredScope = lookup.EnterScope("x");
Assert.Equal(property, lookup.GetProperty("p1"));
}