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)); }
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)); }
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()}'."); }
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); }