c# - How to get unique key for any method invocation? -
i need generate 'hash' unique method invocation in project. example, have method string getsomestring(int someint)
. so, need different hashes in cases:
string getsomestring(1) -- key 1 string getsomestring(2) -- key 2 string getsomestring(3) -- key 3
how generate kind of hashes?
upd: want log method execution unique hash each method invocation. this:
public delegate t helperfactorymethod<t>(); public static logmethodexecution<t>(helperfactorymethod<t> factorymethod) t: class { string key = gethashstring(factorymethod); storetodatabase(key); ... }
result example of gethashstring() must :
- list getsomeobjects(1, objecttype.simple) must 'listgetsomeobjects_1_objecttype.simple' or this.
- list getsomeobjects(2, objecttype.none) must 'listgetsomeobjects_2_objecttype.none' or this.
you use hash function generete unique key parameter values. example:
public string getsomestring(int someint) { md5cryptoserviceprovider cryptoserviceprovider = new md5cryptoserviceprovider(); byte[] data = encoding.ascii.getbytes(string.format("{0}{1}", "methodname", someint)); data = cryptoserviceprovider.computehash(data); return convert.tostring(data); }
every unique 'methodname' , parameter return unique key
Comments
Post a Comment