从数组中获取数组

编程入门 行业动态 更新时间:2024-10-25 02:18:39
本文介绍了从数组中获取数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个有一些属性和数组的数组。我需要从数组中找到数组。

Hi, I have an array which has some properties and an array. I need to find the array from the array.

public class User { public MainArray[] mainArray { get; set; } } public class MainArray { public bool IsFlat { get; set; } public bool IsStandard { get; set; } public bool IsCustom { get; set; } public string CustomName { get; set; } public SubArray[] subArray { get; set; } } public class SubArray { public string Amount { get; set; } public string Fee { get; set; } }

我需要使用反射从mainArray中找到subArray。有没有办法做到这一点?我有使用反射的mainArray。有没有办法检查mainArray是否包含任何数组?

I need to find subArray from mainArray using reflection. Is there any way to do that? I have got my mainArray using reflection. Is there any way to check if mainArray contains any array or not?

推荐答案

嗨sanket.raj8, 我想我明白你想要什么。但我不知道你可能被困在哪里。对你来说这似乎是一个非常可管理的任务,因为你提到你已经发现你的 mainArray 属性是一个数组。 无论如何 - 所以你有这样的方法/功能: Hi sanket.raj8, I think I understand what you want. But I don't see where you possibly have been stuck. It seems quite a managable task for you because you mentioned you already found out that your mainArray property is an Array. Anyway - so you have a method/function like this: public static bool HasAtLeastOneArrayProperty(object obj) { PropertyInfo[] aPropertyInfos = obj.GetType().GetProperties(); return aPropertyInfos.Any(p => p.PropertyType.IsArray); }

现在,如果您想要查看完整的对象图(请注意参考圈),应该能够对每个属性及其子属性等进行此方法的递归调用。 (或者你打算问你是否可以避免这种情况?) 听起来像是一个不寻常的要求 - 我很抱你有充分的理由 - 只是想知道为什么要这样做?你可以开导我吗? 如果你有任何进一步/其他问题随时问我 - 也许我可以反思我的一些记忆并帮助你。 亲切的问候 Johannes

Now if you want to go down the complete object graph (be aware of "reference circles"), you should be able to just do recursive calls to this methods for every property and their subproperties and so on. (Or was your intention to ask whether you can avoid that?) Sounds like a "unusual" requirement - I'm shure you have good reasons for it - just wondering why want to do this? Can you enlighten me? If you have any further/other problems feel free to ask me - Maybe I can REFLECT on some of my memories and help you out. Kind regards Johannes

更多推荐

从数组中获取数组

本文发布于:2023-10-19 18:09:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508342.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   组中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!