मैं पिछली विधि के IDictionary<string, object>
के रूप में पैरामीटर की एक सूची प्राप्त करने में सक्षम होना चाहता हूं। एक पकड़ है: मैं तीसरे पक्ष के पहलू ओरिएंटेड प्रोग्रामिंग ढांचे का उपयोग तब भी नहीं कर सकता जब यह मुफ़्त हो।सी # में बुलाए गए पैरामीटर की पैरामीटर की आईडीआईआर <स्ट्रिंग, ऑब्जेक्ट> कैसे प्राप्त करें?
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace Question {
internal class Program {
public static void Main(string[] args) {
var impl = new Implementation();
impl.MethodA(1, "two", new OtherClass { Name = "John", Age = 100 });
}
}
internal class Implementation {
public void MethodA(int param1, string param2, OtherClass param3) {
Logger.LogParameters();
}
}
internal class OtherClass {
public string Name { get; set; }
public int Age { get; set; }
}
internal class Logger {
public static void LogParameters() {
var parameters = GetParametersFromPreviousMethodCall();
foreach (var keyValuePair in parameters)
Console.WriteLine(keyValuePair.Key + "=" + keyValuePair.Value);
// keyValuePair.Value may return a object that maybe required to
// inspect to get a representation as a string.
}
private static IDictionary<string, object> GetParametersFromPreviousMethodCall() {
throw new NotImplementedException("I need help here!");
}
}
}
कोई भी सुझाव या विचारों:
उदाहरण के लिए? यदि आवश्यक हो तो प्रतिबिंब का उपयोग करने के लिए स्वतंत्र महसूस करें।
इस प्रतिबिंब की आवश्यकता नहीं है; इसे एक डीबगर की आवश्यकता है। – Gabe