///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 //
// Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
// rights of fair usage, the disclaimer and warranty conditions. //
///////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace wasSharpNET
{
public static class Reflection
{
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
///
/// Enumerates the fields of an object along with the child objects,
/// provided that all child objects are part of a specified namespace.
///
/// the object to enumerate
/// the namespace to enumerate in
/// child objects of the object
public static IEnumerable> wasGetFields(object @object, string @namespace)
{
if (@object == null) yield break;
foreach (var fi in @object.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public))
{
if (fi.FieldType.FullName.Split('.', '+')
.Contains(@namespace, StringComparer.OrdinalIgnoreCase))
foreach (var sf in wasGetFields(fi.GetValue(@object), @namespace))
yield return sf;
yield return new KeyValuePair(fi, @object);
}
}
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
///
/// Enumerates the properties of an object along with the child objects,
/// provided that all child objects are part of a specified namespace.
///
/// the object to enumerate
/// the namespace to enumerate in
/// child objects of the object
public static IEnumerable> wasGetProperties(object @object,
string @namespace)
{
if (@object == null) yield break;
foreach (var pi in @object.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
{
if (pi.PropertyType.FullName.Split('.', '+')
.Contains(@namespace, StringComparer.OrdinalIgnoreCase))
{
var getMethod = pi.GetGetMethod();
if (getMethod.ReturnType.IsArray)
{
var array = (Array) getMethod.Invoke(@object, null);
foreach (var sp in
array.Cast