Example #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="type"><see cref="System.Type"/> to wrap.</param>
        /// <param name="flags">Flags that must be taken into account to get members.</param>
        internal ImmediateType([NotNull] Type type, BindingFlags flags = TypeAccessor.DefaultFlags)
            : base(type)
        {
            _flags        = flags;
            Type          = type;
            BaseType      = type.BaseType;
            DeclaringType = type.DeclaringType;
            FullName      = type.FullName ?? Name;

            // Default constructor
#if SUPPORTS_CACHING
            ConstructorData <DefaultConstructorDelegate> defaultCtorData = CachesHandler.Instance.GetDefaultConstructor(Type);
            _constructor          = defaultCtorData.Constructor;
            HasDefaultConstructor = defaultCtorData.HasConstructor;
#else
            _constructor          = DelegatesFactory.CreateDefaultConstructor(Type, out bool hasConstructor);
            HasDefaultConstructor = hasConstructor;
#endif

            // Copy constructor
#if SUPPORTS_CACHING
            ConstructorData <CopyConstructorDelegate> copyCtorData = CachesHandler.Instance.GetCopyConstructor(Type);
            _copyConstructor   = copyCtorData.Constructor;
            HasCopyConstructor = copyCtorData.HasConstructor;
#else
            _copyConstructor   = DelegatesFactory.CreateCopyConstructor(Type, out bool hasConstructor);
            HasCopyConstructor = hasConstructor;
#endif

            if (type.IsEnum)
            {
#if SUPPORTS_LAZY
                _fields = new Lazy <ImmediateFields>(() => new ImmediateFields(type.GetFields()));
#else
                Fields = new ImmediateFields(type.GetFields());
#endif

#if SUPPORTS_SYSTEM_CORE
                Properties = new ImmediateProperties(Enumerable.Empty <PropertyInfo>());
#else
                Properties = new ImmediateProperties(Empty <PropertyInfo>());
#endif
            }
            else
            {
#if SUPPORTS_LAZY
                _fields = new Lazy <ImmediateFields>(() => new ImmediateFields(IgnoreBackingFields(type.GetFields(_flags))));
#else
                Fields = new ImmediateFields(IgnoreBackingFields(type.GetFields(_flags)));
#endif

                Properties = new ImmediateProperties(type.GetProperties(_flags));
            }
        }
        /// <inheritdoc />
        public bool Equals(ImmediateProperties other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }
            if (_properties.Count != other._properties.Count)
            {
                return(false);
            }

#if SUPPORTS_SYSTEM_CORE
            return(!_properties.Except(other._properties).Any());
#else
            return(!Except(_properties, other._properties)
                   .GetEnumerator()
                   .MoveNext());
#endif
        }