Exemple #1
0
        private object ActivateRd(Type type)
        {
#if JET_MODE_ASSERT
            Assertion.Assert(!myCurrentActivationChain.Contains(type),
                             $"Unable to activate {type.FullName}: circular dependency detected: {string.Join(" -> ", myCurrentActivationChain.Select(t => t.FullName).ToArray())}");
            myCurrentActivationChain.Enqueue(type);
#endif

            var typeInfo = type.GetTypeInfo();
            ReflectionSerializerVerifier.AssertEitherExtModelAttribute(typeInfo);
            var implementingType = ReflectionSerializerVerifier.GetImplementingType(typeInfo);
            Assertion.Assert(typeof(RdBindableBase).GetTypeInfo().IsAssignableFrom(implementingType),
                             $"Unable to activate {type.FullName}: type should be {nameof(RdBindableBase)}");

            object instance;
            try
            {
                instance = Activator.CreateInstance(implementingType);
            }
            catch (MissingMethodException e)
            {
                throw new MissingMethodException($"Unable to create instance of: {implementingType.ToString(true)}.{e.Message}");
            }

            ReflectionInitInternal(instance);
#if JET_MODE_ASSERT
            myCurrentActivationChain.Dequeue();
#endif
            return(instance);
        }
Exemple #2
0
        internal static MemberInfo[] GetBindableMembers(TypeInfo typeInfo)
        {
            ReflectionSerializerVerifier.AssertEitherExtModelAttribute(typeInfo);

            var list = new List <MemberInfo>();

            foreach (var mi in typeInfo.GetMembers(BindingFlags.Public | BindingFlags.Instance))
            {
                if ((mi.MemberType == MemberTypes.Property && ReflectionUtil.TryGetSetter(mi) != null) ||
                    mi.MemberType == MemberTypes.Field)
                {
                    if (mi.DeclaringType != null && !mi.DeclaringType.GetTypeInfo().IsAssignableFrom(typeof(RdReflectionBindableBase)))
                    {
                        list.Add(mi);
                    }
                }
            }

            return(list.ToArray());
        }