本文整理汇总了C#中View.GetProperty方法的典型用法代码示例。如果您正苦于以下问题:C# View.GetProperty方法的具体用法?C# View.GetProperty怎么用?C# View.GetProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类View
的用法示例。
在下文中一共展示了View.GetProperty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
public static void Add(View view, Project project)
{
var prjPlus = project.Lookup();
if (prjPlus.View != null) {
throw new ClrPlusException("Configurations already registered for project");
}
prjPlus.View = view;
var pkgName = view.GetMacroValue("pkgname");
// add the startup/init tasks
var task = project.Xml.AddUsingTask(pkgName + "_Contains", @"$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll", null);
task.TaskFactory = "CodeTaskFactory";
var pgroup = task.AddParameterGroup();
pgroup.AddParameter("Text", "false", string.Empty, "System.String");
pgroup.AddParameter("Library", "false", "true", "System.String");
pgroup.AddParameter("Value", "false", "true", "System.String");
pgroup.AddParameter("Result", "true", string.Empty, "System.String");
var body = task.AddUsingTaskBody(string.Empty, string.Empty);
// thank you.
body.XmlElement().Append("Code").InnerText = @"Result = ((Text ?? """").Split(';').Contains(Library) ) ? Value : String.Empty;";
var initTarget = project.AddInitTarget(pkgName + "_init");
var pivots = view.GetChildPropertyNames();
foreach (var pivot in pivots) {
dynamic cfg = view.GetProperty(pivot);
IEnumerable<string> choices = cfg.choices;
if(!((View)cfg).GetChildPropertyNames().Contains("key")) {
// add init steps for this.
var finalPropName = "{0}-{1}".format(pivot, pkgName);
foreach (var choice in choices) {
var choicePropName = "{0}-{1}".format(pivot, choice);
var tsk = initTarget.AddTask("pkgName_Contains");
tsk.SetParameter("Text", choicePropName);
tsk.SetParameter("Library", pkgName);
tsk.SetParameter("Value", choice);
tsk.Condition = @"'$({0})'==''".format(finalPropName);
tsk.AddOutputProperty("Result", finalPropName);
}
project.Xml.AddPropertyGroup().AddProperty(finalPropName, choices.FirstOrDefault()).Condition = @"'$({0})' == ''".format(finalPropName);
}
}
}
示例2: NormalizeWork
private static IEnumerable<string> NormalizeWork( View view, IEnumerable<string> options, bool fix = false)
{
foreach(var p in view.GetChildPropertyNames()) {
var pivot = p;
foreach (var option in from option in options let cfg = view.GetProperty(pivot) where ((dynamic)cfg).choices.Values.Contains(option) select option) {
yield return option;
break;
}
}
}
示例3: NormalizeConditionKey
public static string NormalizeConditionKey(string key, View configurationsView)
{
if (string.IsNullOrEmpty(key)) {
return string.Empty;
}
var pivots = configurationsView.GetChildPropertyNames().ToArray();
var opts = key.Replace(",", "\\").Replace("&", "\\").Split(new char[] {
'\\', ' '
}, StringSplitOptions.RemoveEmptyEntries);
var options = opts.ToList();
var ordered = new List<string>();
foreach (var pivot in pivots) {
foreach(var option in options) {
dynamic cfg = configurationsView.GetProperty(pivot);
if (cfg.choices.Values.Contains(option)) {
ordered.Add(option);
options.Remove(option);
break;
}
}
}
if(options.Any()) {
// went thru one pass,and we had some that didn't resolve.
// try again, this time cheat if we have to
var unfound = options;
options = opts.ToList();
foreach (var opt in unfound) {
switch (opt.ToLower()) {
case "x86":
case "win32":
case "ia32":
case "386":
options.Remove(opt);
options.Add("Win32");
break;
case "x64":
case "amd64":
case "em64t":
case "intel64":
case "x86-64":
case "x86_64":
options.Remove(opt);
options.Add("x64");
break;
case "woa":
case "arm":
options.Remove(opt);
options.Add("ARM");
break;
case "ia64":
options.Remove(opt);
options.Add("ia64");
break;
}
}
ordered = new List<string>();
foreach(var pivot in pivots) {
foreach(var option in options) {
dynamic cfg = configurationsView.GetProperty(pivot);
IEnumerable<string> choices = cfg.choices.Values;
if(choices.ContainsIgnoreCase(option)) {
ordered.Add(option);
options.Remove(option);
break;
}
}
}
if (options.Any()) {
// STILL?! bail.
throw new ClrPlusException("Unknown configuration choice: {0}".format(options.FirstOrDefault()));
}
}
return ordered.Aggregate((c, e) => c + "\\" + e).Trim('\\');
}
示例4: ProcessNugetFiles
private void ProcessNugetFiles(View filesView, string srcFilesRoot, string currentCondition)
{
currentCondition = Pivots.NormalizeExpression(currentCondition ?? "");
foreach (var containerName in filesView.GetChildPropertyNames()) {
View container = filesView.GetProperty(containerName);
if (containerName == "condition" || containerName == "*") {
foreach (var condition in container.GetChildPropertyNames()) {
ProcessNugetFiles(container.GetElement(condition), srcFilesRoot, condition);
}
continue;
}
// GS01 Workaround for bug in Values not caching the output set when a collection is added to ?
var filemasks = container.Values.Distinct().ToArray();
var relativePaths = new Dictionary<string, string>();
foreach (var mask in filemasks) {
if (string.IsNullOrEmpty(mask)) {
continue;
}
var fileset = mask.FindFilesSmarterComplex(srcFilesRoot).GetMinimalPathsToDictionary();
if (!fileset.Any()) {
Event<Warning>.Raise("ProcessNugetFiles","WARNING: file selection '{0}' failed to find any files ", mask);
continue;
}
foreach (var key in fileset.Keys) {
relativePaths.Add(key, fileset[key]);
}
}
var optionPackages = container.GetMetadataValuesHarder("output.package", currentCondition).Union(container.GetMetadataValuesHarder("output.packages", currentCondition)).ToArray();
if (optionPackages.Length == 0) {
optionPackages = new [] {"default"};
}
var optionExcludes = container.GetMetadataValues("exclude", container, false).Union(container.GetMetadataValues("excludes", container, false)).ToArray();
// var targets = package.GetTargetsProject(optionFramework);
// determine the destination location in the target package
var optionDestination = container.GetMetadataValueHarder("destination", currentCondition);
var destinationFolder = string.IsNullOrEmpty(optionDestination) ? (filesView.GetSingleMacroValue("d_" + containerName) ?? "\\") : optionDestination;
var optionFlatten = container.GetMetadataValueHarder("flatten", currentCondition).IsPositive();
var addEachFiles = container.GetMetadataValuesHarder("add-each-file", currentCondition).ToArray();
var addFolders = container.GetMetadataValuesHarder("add-folder", currentCondition).ToArray();
if (addFolders.Length > 0 ) {
foreach (var addFolder in addFolders) {
var folderView = filesView.GetProperty(addFolder.Replace("${condition}", currentCondition));
if (folderView != null) {
var values = folderView.Values.ToList();
values.Add((filesView.GetSingleMacroValue("pkg_root") + destinationFolder).Replace("\\\\", "\\"));
folderView.Values = values;
}
}
}
foreach (var optionPackage in optionPackages) {
if (!_nugetPackages.Keys.Contains(optionPackage)) {
FailAlways(Event<SourceError>.Raise("AP300", SourceLocation.Unknowns, "Unknown #output-package '{0}' in files section '{1}' ", optionPackage, containerName));
}
var package = _nugetPackages[optionPackage];
foreach (var src in relativePaths.Keys) {
if (optionExcludes.HasWildcardMatch(src)) {
continue;
}
Event<Verbose>.Raise("ProcessNugetFiles (adding file)", "'{0}' + '{1}'", destinationFolder, relativePaths[src]);
string target = Path.Combine(destinationFolder, optionFlatten ? Path.GetFileName(relativePaths[src]) : relativePaths[src]).Replace("${condition}", currentCondition).Replace("\\\\", "\\");
package.AddFile(src, target);
if (addEachFiles.Length > 0) {
foreach (var addEachFile in addEachFiles) {
var fileListView = filesView.GetProperty(addEachFile.Replace("${condition}", currentCondition));
if (fileListView != null) {
var values = fileListView.Values.ToList();
values.Add((filesView.GetSingleMacroValue("pkg_root") + target).Replace("${condition}", currentCondition).Replace("\\\\", "\\"));
fileListView.Values = values;
}
}
}
}
}
}
}
示例5: ProcessNugetFiles
private void ProcessNugetFiles(View filesView, string srcFilesRoot, string currentCondition) {
currentCondition = Pivots.NormalizeExpression(currentCondition ?? "");
foreach (var containerName in filesView.GetChildPropertyNames().ToArray()) {
View container = filesView.GetProperty(containerName);
if (containerName == "condition" || containerName == "*") {
foreach (var condition in container.GetChildPropertyNames()) {
ProcessNugetFiles(container.GetElement(condition), srcFilesRoot, condition);
}
continue;
}
// GS01 Workaround for bug in Values not caching the output set when a collection is added to ?
var filemasks = container.Values.Distinct().ToArray();
var relativePaths = new Dictionary<string, string>();
var optionExcludes = container.GetMetadataValues("exclude", container, false).Union(container.GetMetadataValues("excludes", container, false)).ToArray();
foreach (var mask in filemasks) {
if (string.IsNullOrEmpty(mask)) {
continue;
}
var fileset = mask.FindFilesSmarterComplex(srcFilesRoot, optionExcludes).GetMinimalPathsToDictionary();
if (!fileset.Any()) {
Event<Warning>.Raise("ProcessNugetFiles","WARNING: file selection '{0}' failed to find any files ", mask);
continue;
}
foreach (var key in fileset.Keys) {
relativePaths.Add(key, fileset[key]);
}
}
var optionRenames = container.GetMetadataValues("rename", container, false).Union(container.GetMetadataValues("renames", container, false)).Select(each => {
var s = each.Split('/','\\');
if (s.Length == 2) {
return new {
search = new Regex(s[0]),
replace = s[1]
};
}
return null;
}).Where( each => each != null).ToArray();
// determine the destination location in the target package
var optionDestination = container.GetMetadataValueHarder("destination", currentCondition);
var destinationFolder = string.IsNullOrEmpty(optionDestination) ? (filesView.GetSingleMacroValue("d_" + containerName) ?? "\\") : optionDestination;
var optionFlatten = container.GetMetadataValueHarder("flatten", currentCondition).IsPositive();
var optionNoOverlay = container.GetMetadataValueHarder("overlay", currentCondition).IsNegative();
var addEachFiles = container.GetMetadataValuesHarder("add-each-file", currentCondition).ToArray();
var addFolders = container.GetMetadataValuesHarder("add-folder", currentCondition).ToArray();
var addAllFiles = container.GetMetadataValuesHarder("add-all-files", currentCondition).ToArray();
// add the folder to an Collection somewhere else in the PropertySheet
if (addFolders.Length > 0 && relativePaths.Any() ) {
foreach (var addFolder in addFolders) {
var folderView = filesView.GetProperty(addFolder, lastMinuteReplacementFunction: s => s.Replace("${condition}", currentCondition));
if (folderView != null) {
folderView.AddValue((filesView.GetSingleMacroValue("pkg_root") + destinationFolder).FixSlashes());
}
}
}
// add the folder+/** to an Collection somewhere else in the PropertySheet (useful for making <ItemGroup>s)
if (addAllFiles.Length > 0 && relativePaths.Any()) {
foreach (var addAllFile in addAllFiles) {
var folderView = filesView.GetProperty(addAllFile, lastMinuteReplacementFunction: s => s.Replace("${condition}", currentCondition));
if (folderView != null) {
// add the /** suffix on the path
// so it can be used in an ItemGroup
folderView.AddValue(((filesView.GetSingleMacroValue("pkg_root") + destinationFolder) + "/**").FixSlashes());
}
}
}
foreach (var srcf in relativePaths.Keys) {
var src = srcf;
if (optionExcludes.HasWildcardMatch(src)) {
continue;
}
Event<Verbose>.Raise("ProcessNugetFiles (adding file)", "'{0}' + '{1}'", destinationFolder, relativePaths[src]);
string target = Path.Combine(destinationFolder, optionFlatten ? Path.GetFileName(relativePaths[src]) : relativePaths[src]).Replace("${condition}", currentCondition).FixSlashes();
if (optionRenames.Length > 0) {
// process rename commands
var dir = Path.GetDirectoryName(target);
var filename = Path.GetFileName(target);
foreach (var rename in optionRenames) {
var newFilename = rename.search.Replace(filename, rename.replace);
if (newFilename != filename) {
// generate the new location for the renamed file
//.........这里部分代码省略.........
示例6: ProcessFiles
private void ProcessFiles(View files, string fileRoot, bool implictRules, string appliedCondition)
{
appliedCondition = Configurations.NormalizeConditionKey((appliedCondition ?? ""), _sheet.View.configurations);
foreach(var containerName in files.GetChildPropertyNames()) {
View container = files.GetProperty(containerName);
if (containerName == "condition" || containerName == "*" ) {
foreach(var condition in container.GetChildPropertyNames()) {
ProcessFiles(container.GetElement(condition), fileRoot, implictRules, condition);
}
continue;
}
// get the destination directory
var destinationDirectory = container.GetMetadataValue("destination", false);
var dest = string.IsNullOrEmpty(destinationDirectory) ? files.GetMacroValue("d_" + containerName) : destinationDirectory;
// locate all the files in the collection.
var filemasks = container.Values;
var foundFiles = Enumerable.Empty<string>();
foreach (var mask in filemasks) {
var fileset = mask.FindFilesSmarterComplex(fileRoot).ToCacheEnumerable();
if (!fileset.Any()) {
Console.WriteLine("WARNING: file selection '{0}' failed to find any files ",mask);
}
foundFiles = foundFiles.Union(fileset);
}
if(implictRules && containerName == "include") {
// add this folder to the appropriate target
_targets.LookupItemDefinitionGroup(appliedCondition).LookupItemDefinitionElement("ClCompile").LookupMetadataList("AdditionalIncludeDirectories").AddUnique((files.GetMacroValue("pkg_root") + dest).Replace("${condition}", appliedCondition).Replace("\\\\", "\\"));
}
var flatten = container.GetMetadataValue("flatten", false).IsPositive();
var relativePaths = foundFiles.GetMinimalPathsToDictionary();
foreach (var src in relativePaths.Keys) {
string target = Path.Combine(dest, flatten ? Path.GetFileName(relativePaths[src]) : relativePaths[src]).Replace("${condition}", appliedCondition).Replace("\\\\", "\\");
var file = _nuspec.files.Add("file");
file.Attributes.src = src.GetFullPath().Replace("\\\\", "\\");
file.Attributes.target = target;
if (implictRules) {
switch (containerName) {
case "bin":
// add a per-file copy rule to the appropriate target
var tsk = _targets.LookupTarget("AfterBuild", appliedCondition).AddTask("Copy");
tsk.SetParameter("SourceFiles", (files.GetMacroValue("pkg_root") + target).Replace("\\\\", "\\"));
tsk.SetParameter("DestinationFolder", "$(TargetDir)");
tsk.SetParameter("SkipUnchangedFiles","true");
break;
case "lib":
// add a Libraries += rule to the appropriate target
_targets.LookupItemDefinitionGroup(appliedCondition).LookupItemDefinitionElement("Link").LookupMetadataList("AdditionalDependencies").AddUnique((files.GetMacroValue("pkg_root") + target).Replace("${condition}", appliedCondition).Replace("\\\\", "\\"));
break;
}
}
}
// Console.WriteLine("SET : {0}, => {1}", containerName, dest);
}
}