https://github.com/wk-j/reference-source-link
https://github.com/wk-j/reference-source-link
Last synced: 28 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/wk-j/reference-source-link
- Owner: wk-j
- Created: 2016-08-22T11:14:21.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-13T18:26:38.000Z (about 8 years ago)
- Last Synced: 2025-02-08T18:15:19.383Z (3 months ago)
- Language: C#
- Homepage: https://wk-j.github.io/reference-source-link
- Size: 20.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Reference Source Link
How to create link that match code in http://referencesource.microsoft.com.
## Signature
We need two signature to create URL.
- Assembly name (`mscorlib`)
- Symbol ID (`M:System.Int32.TryParse(System.String,System.Int32@)`)## Symbol prefix
- M: = Method
- E: = Event
- T: = Type
- P: = Property
- F: = Field## How to create URL
1. Encode symbol ID with following hash function.
```csharp
public static string GetMD5Hash(string input, int digits) {
using (var md5 = MD5.Create()) {
var bytes = Encoding.UTF8.GetBytes(input);
var hashBytes = md5.ComputeHash(bytes);
return ByteArrayToHexString(hashBytes, digits);
}
}public static string ByteArrayToHexString(byte[] bytes, int digits = 0) {
if (digits == 0) {
digits = bytes.Length * 2;
}
char[] c = new char[digits];
byte b;
for (int i = 0; i < digits / 2; i++) {
b = ((byte)(bytes[i] >> 4));
c[i * 2] = (char)(b > 9 ? b + 87 : b + 0x30);
b = ((byte)(bytes[i] & 0xF));
c[i * 2 + 1] = (char)(b > 9 ? b + 87 : b + 0x30);
}
return new string(c);
}
```
2. Create URL from assembly name and hash value.```csharp
var hash = GetMD5Hash("M:System.Int32.TryParse(System.String,System.Int32@)", 16);
var assemblyName = "mscorlib";
var baseUrl = "http://referencesource.microsoft.com";
var url = baseUrl + "/" + assemblyName + "/a.html#" + hash;
```3. Try in browser.
- http://referencesource.microsoft.com/mscorlib/a.html#325507e509229dbc
## Resources
- https://github.com/SLaks/Ref12
- https://github.com/KirillOsenkov/SourceBrowser