Exemplo n.º 1
0
 private static ObjectDataConverter GetDefaultOrCreate(Type type)
 {
     if (!AssignableMember.TryGet(type, "Default", BindingAttributes.DeclareStatic, out var member))
     {
         return(null);
     }
     if (!typeof(ObjectDataConverter).IsAssignableFrom(member.ValueType))
     {
         return(null);
     }
     return((ObjectDataConverter)member.GetValue(null));
 }
Exemplo n.º 2
0
 private static IEnumerable <AssignableMember> SelectDataMembers(Type type)
 {
     return(type.GetMembers()
            .Where(m => !m.IsDefined(typeof(CompilerGeneratedAttribute)))
            .Select(m =>
     {
         var got = AssignableMember.TryGet(m, out var am);
         return (got, am);
     })
            .Where(t => t.got && t.am.CanGetValue)
            .Select(t => t.am));
 }
Exemplo n.º 3
0
        private static void SetMemberValue(object container, string name, object value)
        {
            var type = container.GetType();

            while (type != null)
            {
                if (AssignableMember.TryGet(type, name, BindingAttributes.Instance, out var m))
                {
                    m.SetValue(container, value);
                    return;
                }
                type = type.BaseType;
            }
            Debug.LogError($"Failed to set member({name}) value for '{container.GetType()}'.");
        }
Exemplo n.º 4
0
        private static object GetMemberValue(object container, string name)
        {
            if (container == null)
            {
                return(null);
            }

            var type = container.GetType();

            while (type != null)
            {
                if (AssignableMember.TryGet(type, name, BindingAttributes.Instance, out var m))
                {
                    return(m.GetValue(container));
                }
                type = type.BaseType;
            }
            return(null);
        }