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


C# Result.SetProperty方法代码示例

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


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

示例1: FxCopConverter_CreateResult_FakeContext_Member

        public void FxCopConverter_CreateResult_FakeContext_Member()
        {
            var context = TestHelper.CreateProjectContext();

            context.RefineTarget(@"mybinary.dll");
            context.RefineModule("mybinary.dll");
            context.RefineNamespace("mynamespace");
            context.RefineType("mytype");
            context.RefineMember("mymember(string)");
            context.RefineMessage("CA0000", "VeryUsefulCheck", "1", "FakeCategory", "Breaking", "ExcludedInSource");
            context.RefineIssue("hello!", "test", "uncertain", "error", @"source", "myfile.cs", 13);

            string expectedLogicalLocation = "mynamespace.mytype.mymember(string)";

            var expectedResult = new Result
            {
                RuleId = "CA0000",
                Message = "hello!",
                ToolFingerprintContribution = "1#test",
                SuppressionStates = SuppressionStates.SuppressedInSource,
                Locations = new List<Location>
                {
                    new Location
                    {
                        AnalysisTarget = new PhysicalLocation
                        {
                            Uri = new Uri("mybinary.dll", UriKind.RelativeOrAbsolute),
                        },
                        ResultFile = new PhysicalLocation
                        {
                            Uri = new Uri("source\\myfile.cs", UriKind.RelativeOrAbsolute),
                            Region = new Region { StartLine = 13 }
                        },
                        FullyQualifiedLogicalName = expectedLogicalLocation,
                    }
                }
            };

            expectedResult.SetProperty("Level", "error");
            expectedResult.SetProperty("Category", "FakeCategory");
            expectedResult.SetProperty("FixCategory", "Breaking");

            var expectedLogicalLocations = new Dictionary<string, LogicalLocation>
            {
                {
                    "mybinary.dll", new LogicalLocation { ParentKey = null, Name = "mybinary.dll", Kind = LogicalLocationKind.Module }
                },
                {
                    "mybinary.dll!mynamespace",
                    new LogicalLocation { ParentKey = "mybinary.dll", Name = "mynamespace", Kind = LogicalLocationKind.Namespace }
                },
                {
                    "mybinary.dll!mynamespace.mytype",
                    new LogicalLocation { ParentKey = "mybinary.dll!mynamespace", Name = "mytype", Kind = LogicalLocationKind.Type }
                },
                {
                    "mybinary.dll!mynamespace.mytype.mymember(string)",
                    new LogicalLocation { ParentKey = "mybinary.dll!mynamespace.mytype", Name = "mymember(string)", Kind = LogicalLocationKind.Member }
                }            };

            var converter = new FxCopConverter();
            Result result = converter.CreateResult(context);

            foreach (string key in expectedLogicalLocations.Keys)
            {
                expectedLogicalLocations[key].ValueEquals(converter.LogicalLocationsDictionary[key]).Should().BeTrue();
            }
            converter.LogicalLocationsDictionary.Count.Should().Be(expectedLogicalLocations.Count);
        }
开发者ID:Microsoft,项目名称:sarif-sdk,代码行数:69,代码来源:FxCopConverterTests.cs

示例2: TryAddProperty

 private static void TryAddProperty(Result result, string value, string key)
 {
     if (!String.IsNullOrWhiteSpace(value))
     {
         result.SetProperty(key, value);
     }
 }
开发者ID:Microsoft,项目名称:sarif-sdk,代码行数:7,代码来源:FxCopConverter.cs

示例3: ConvertFortifyIssueToSarifIssue

        /// <summary>Converts a Fortify result to a static analysis results interchange format result.</summary>
        /// <param name="fortify">The Fortify result convert.</param>
        /// <returns>
        /// A SARIF result <see cref="Result"/> containing the same content as the supplied
        /// <see cref="FortifyIssue"/>.
        /// </returns>
        public static Result ConvertFortifyIssueToSarifIssue(FortifyIssue fortify)
        {
            var result = new Result();
            result.RuleId = fortify.Category;
            result.ToolFingerprintContribution = fortify.InstanceId;
            List<string> messageComponents = new List<string>();
            if (fortify.Abstract != null)
            {
                messageComponents.Add(fortify.Abstract);
            }

            if (fortify.AbstractCustom != null)
            {
                messageComponents.Add(fortify.AbstractCustom);
            }

            if (messageComponents.Count == 0)
            {
                result.Message = String.Format(CultureInfo.InvariantCulture, ConverterResources.FortifyFallbackMessage, result.RuleId);
            }
            else
            {
                result.Message = String.Join(Environment.NewLine, messageComponents);
            }

            result.SetProperty("kingdom", fortify.Kingdom);
            if (fortify.Priority != null)
            {
                result.SetProperty("priority", fortify.Priority);
            }

            if (!fortify.CweIds.IsDefaultOrEmpty)
            {
                result.SetProperty("cwe", String.Join(", ",
                    fortify.CweIds.Select(id => id.ToString(CultureInfo.InvariantCulture))));
            }

            if (fortify.RuleId != null)
            {
                result.SetProperty("fortifyRuleId", fortify.RuleId);
            }

            PhysicalLocation primaryOrSink = ConvertFortifyLocationToPhysicalLocation(fortify.PrimaryOrSink);
            result.Locations = new List<Location>
            {
                new Location
                {
                    ResultFile = primaryOrSink
                }
            };

            if (fortify.Source != null)
            {
                PhysicalLocation source = ConvertFortifyLocationToPhysicalLocation(fortify.Source);
                result.CodeFlows = new List<CodeFlow>
                {
                    new CodeFlow
                    {
                        Locations = new List<AnnotatedCodeLocation>
                        {
                            new AnnotatedCodeLocation
                            {
                                PhysicalLocation = source
                            },

                            new AnnotatedCodeLocation
                            {
                                PhysicalLocation = primaryOrSink
                            }
                        }
                    }
                };
            }

            return result;
        }
开发者ID:Microsoft,项目名称:sarif-sdk,代码行数:82,代码来源:FortifyConverter.cs

示例4: ToSarifIssue

        /// <summary>Converts this instance to <see cref="Result"/>.</summary>
        /// <returns>This instance as an <see cref="Result"/>.</returns>
        public Result ToSarifIssue()
        {
            if (this.Locations.Length == 0)
            {
                throw new InvalidOperationException("At least one location must be present in a SARIF result.");
            }

            var result = new Result
            {
                RuleId = this.Id,
            };

            result.SetProperty("Severity", this.Severity);

            if (!string.IsNullOrEmpty(this.VerboseMessage))
            {
                result.Message = this.VerboseMessage;
            }
            else
            {
                result.Message = this.Message;
            }

            PhysicalLocation lastLocationConverted;
            if (this.Locations.Length == 1)
            {
                lastLocationConverted = this.Locations[0].ToSarifPhysicalLocation();
            }
            else
            {
                var locations = new List<AnnotatedCodeLocation>
                {
                    Capacity = this.Locations.Length
                };

                foreach (CppCheckLocation loc in this.Locations)
                {
                    locations.Add(new AnnotatedCodeLocation
                    {
                        PhysicalLocation = loc.ToSarifPhysicalLocation(),
                        Importance = AnnotatedCodeLocationImportance.Essential
                    });
                }

                var flow = new CodeFlow
                {
                    Locations = locations
                };

                result.CodeFlows = new List<CodeFlow> { flow };

                // In the N != 1 case, set the overall location's location to
                // the last entry in the execution flow.
                lastLocationConverted = locations[locations.Count - 1].PhysicalLocation;
            }

            result.Locations = new List<Location>
            {
                new Location
                {
                    ResultFile = lastLocationConverted
                }
            };

            return result;
        }
开发者ID:Microsoft,项目名称:sarif-sdk,代码行数:68,代码来源:CppCheckError.cs

示例5: CreateResult

        private Result CreateResult(IDictionary<string, object> issueData)
        {
            if (issueData != null)
            {
                // Used for Result.FullMessage
                string description = FindString(issueData, "description");

                // Used as rule id.
                string issueType = FindString(issueData, "type");

                // This data persisted to result property bag
                string category = FindString(issueData, "category");
                string issueContextKind = FindString(issueData, "issue_context_kind");
                string issueContext = FindString(issueData, "issue_context");
                string issueHash = FindString(issueData, "issue_hash");

                int issueLine = 0;
                int issueColumn = 0;
                string fileName = null;

                IDictionary<string, object> location = FindDictionary(issueData, "location");
                if (location != null)
                {
                    issueLine = FindInt(location, "line");
                    issueColumn = FindInt(location, "col");
                    int fileNumber = FindInt(location, "file");
                    if (_files != null && fileNumber < _files.Count)
                    {
                        fileName = _files[fileNumber] as string;
                    }
                }

                var result = new Result
                {
                    RuleId = issueType,
                    Message = description,
                    Locations = new List<Location>
                    {
                        new Location
                        {
                            AnalysisTarget = new PhysicalLocation
                            {
                                Uri = new Uri(fileName, UriKind.RelativeOrAbsolute),
                                Region = new Region()
                                {
                                    StartLine = issueLine,
                                    StartColumn = issueColumn
                                }
                            }
                        }
                    },
                };

                result.SetProperty("category", category);
                result.SetProperty("issue_context_kind", issueContextKind);
                result.SetProperty("issueContext", issueContext);
                result.SetProperty("issueHash", issueHash);

                return result;
            }
            else
            {
                return null;
            }
        }
开发者ID:Microsoft,项目名称:sarif-sdk,代码行数:65,代码来源:ClangAnalyzerConverter.cs

示例6: SetSarifResultPropertiesForProblem

        private static void SetSarifResultPropertiesForProblem(Result result, AndroidStudioProblem problem)
        {
            if (problem.Severity != null)
            {
                result.SetProperty("severity", problem.Severity);
            }

            if (problem.AttributeKey != null)
            {
                result.SetProperty("attributeKey", problem.AttributeKey);
            }
        }
开发者ID:Microsoft,项目名称:sarif-sdk,代码行数:12,代码来源:AndroidStudioConverter.cs


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