public override int GetHashCode() { return(Hash.Combine( EmitMetadataOnly, Hash.Combine( BaseAddress.GetHashCode(), Hash.Combine( FileAlignment, Hash.Combine( HighEntropyVirtualAddressSpace, Hash.Combine( SubsystemVersion.GetHashCode(), Hash.Combine( (int)DebugInformationFormat, Hash.Combine( PdbFilePath, Hash.Combine( PdbChecksumAlgorithm.GetHashCode(), Hash.Combine( OutputNameOverride, Hash.Combine( RuntimeMetadataVersion, Hash.Combine( TolerateErrors, Hash.Combine( IncludePrivateMembers, Hash.Combine( Hash.CombineValues( InstrumentationKinds ), Hash.Combine( DefaultSourceFileEncoding, Hash.Combine( FallbackSourceFileEncoding, 0 ) ) ) ) ) ) ) ) ) ) ) ) ) ) )); }
private static string GetChecksumName(PdbChecksumAlgorithm checksumAlgorithm) { switch (checksumAlgorithm) { case PdbChecksumAlgorithm.Md5: return(Md5AlgName); case PdbChecksumAlgorithm.Sha1: return(Sha1AlgName); default: throw CodeExceptions.UnexpectedArgumentValue(nameof(checksumAlgorithm), checksumAlgorithm); } }
/// <summary>Initializes a new instance of the <see cref="SourceAnnotationInfo"/> class.</summary> /// <param name="path">The path to the source file.</param> /// <param name="methodLinesMap">Range that stores start/end lines for each method in the document.</param> /// <param name="sourceLanguage">Language of the source.</param> /// <param name="checksumAlgorithm">The checksum algorithm.</param> /// <param name="checksum">The checksum.</param> public SourceAnnotationInfo( string path, CompositeRange <int, MethodBase> methodLinesMap, SourceLanguage sourceLanguage, PdbChecksumAlgorithm checksumAlgorithm, byte[] checksum) { Code.NotNullNorEmpty(path, nameof(path)); Code.NotNull(checksum, nameof(checksum)); Path = path; MethodLinesMap = methodLinesMap; SourceLanguage = sourceLanguage; ChecksumAlgorithm = checksumAlgorithm; Checksum = checksum; }
public static byte[] TryGetChecksum([NotNull] string file, PdbChecksumAlgorithm checksumAlgorithm) { Code.NotNullNorEmpty(file, nameof(file)); var algName = GetChecksumName(checksumAlgorithm); if (!File.Exists(file)) { return(Array <byte> .Empty); } using (var stream = File.OpenRead(file)) using (var hashAlgorithm = HashAlgorithm.Create(algName)) { // ReSharper disable once PossibleNullReferenceException return(hashAlgorithm.ComputeHash(stream)); } }
public static byte[] TryGetChecksum(ResourceKey resourceKey, PdbChecksumAlgorithm checksumAlgorithm) { Code.AssertArgument(!resourceKey.IsEmpty, nameof(resourceKey), "The resource key should be non empty."); var algName = GetChecksumName(checksumAlgorithm); using (var stream = resourceKey.TryGetResourceStream()) { if (stream == null) { return(Array <byte> .Empty); } using (var hashAlgorithm = HashAlgorithm.Create(algName)) { // ReSharper disable once PossibleNullReferenceException return(hashAlgorithm.ComputeHash(stream)); } } }
internal void ValidateOptions(DiagnosticBag diagnostics, CommonMessageProvider messageProvider, bool isDeterministic) { if (!DebugInformationFormat.IsValid()) { diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.ERR_InvalidDebugInformationFormat, Location.None, (int)DebugInformationFormat)); } foreach (var instrumentationKind in InstrumentationKinds) { if (!instrumentationKind.IsValid()) { diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.ERR_InvalidInstrumentationKind, Location.None, (int)instrumentationKind)); } } if (OutputNameOverride != null) { MetadataHelpers.CheckAssemblyOrModuleName(OutputNameOverride, messageProvider, messageProvider.ERR_InvalidOutputName, diagnostics); } if (FileAlignment != 0 && !IsValidFileAlignment(FileAlignment)) { diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.ERR_InvalidFileAlignment, Location.None, FileAlignment)); } if (!SubsystemVersion.Equals(SubsystemVersion.None) && !SubsystemVersion.IsValid) { diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.ERR_InvalidSubsystemVersion, Location.None, SubsystemVersion.ToString())); } if (PdbChecksumAlgorithm.Name != null) { try { IncrementalHash.CreateHash(PdbChecksumAlgorithm).Dispose(); } catch { diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.ERR_InvalidHashAlgorithmName, Location.None, PdbChecksumAlgorithm.ToString())); } } else if (isDeterministic) { diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.ERR_InvalidHashAlgorithmName, Location.None, "")); } if (PdbFilePath != null && !PathUtilities.IsValidFilePath(PdbFilePath)) { diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.FTL_InvalidInputFileName, Location.None, PdbFilePath)); } }