public ConstructorData <CopyConstructorDelegate> GetCopyConstructor([NotNull] Type type) { Debug.Assert(type != null); return(_cachedCopyConstructors.GetOrCreate(type, () => { CopyConstructorDelegate ctor = DelegatesFactory.CreateCopyConstructor(type, out bool hasConstructor); return new ConstructorData <CopyConstructorDelegate>(ctor, hasConstructor); })); }
/// <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)); } }