Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public dynamic propertyGet(object obj_, string propName, string type)
- {
- return propertyGet_static2(obj_, propName, type);
- }
- public static dynamic propertyGet_static(object obj_, string propName)
- {
- return propertyGet_static2(obj_, propName, "");
- }
- public static dynamic propertyGet_static2(object obj_, string propName, string type)
- {
- var propInfo = obj_.GetType().GetProperty(propName);
- if (propInfo != null)
- {
- if (type == "string")
- {
- return ((string)propInfo.GetValue(obj_, null));
- }
- else if (type == "bool")
- {
- return ((bool)propInfo.GetValue(obj_, null));
- }
- else if (type == "dictionary_string_string")
- {
- return ((Dictionary<string, string>)propInfo.GetValue(obj_, null));
- }
- return (dynamic)propInfo.GetValue(obj_, null);
- }
- var fieldInfo = obj_.GetType().GetField(propName);
- if (fieldInfo != null)
- {
- if (type == "string")
- {
- return ((string)fieldInfo.GetValue(obj_));
- }
- else if (type == "bool")
- {
- return ((bool)fieldInfo.GetValue(obj_));
- }
- else if (type == "dictionary_string_string")
- {
- return ((Dictionary<string, string>)fieldInfo.GetValue(obj_));
- }
- return ((dynamic)propInfo.GetValue(obj_));
- }
- return "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement