I have a method in Base class which calls ( by reflection to another method).
type.InvokeMember(context.Request["MethodName"],
System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance,
null,
this,
new object[] { context, Jobj }); // jObj is dynamic
jObj parameter type is dynamic ( can’t change this type).
if the MethodName string value is : "getFinanceDetails" so that method is called..
void getFinanceDetails(object contextObj, dynamic obj)
{
//Here I need to do obj["Inv_num"].ToString().Decrpyt() ( my extension method).
//but it goes Bang cause I cant use extension method for dynamic.
//But I cant also send it decrypted from base cause not all values are encrpyrted.
}
However – I did solve it by using (inside the method):
((object) obj["Inv_num"]).ToString().Decrypt();
But I dont want to cast every time to object , just to enable extension method.
Is there anything I can do with the param type sending to fix it ?
my desire :
I want to be able to do : obj.ToString().Decrpyt()obj["Inv_num"].ToString().Decrpyt()
edit
public static string Decrypt(this string obj)
{
Func<string, string> Decrypt = Encryptions.GetDecryptedCode;
return Decrypt(obj);
}
- obj ( in this case is
IDictionary<string , object>) .
so I should be able to read properties. (inv_num in this sample.
Assuming
obj["Inv_num"].ToString()already returns the right value, you could easily do it in two steps:To be honest, it’s not clear why
getFinanceDetails(which should be changed to follow .NET naming conventions) can’t be written as:Do you ever need to call it with something that doesn’t implement
IDictionary<string, object>?