static ContainerPropertyBag() { if (!RuntimeTypeInfoCache.IsContainerType(typeof(TContainer))) { throw new InvalidOperationException($"Failed to create a property bag for Type=[{typeof(TContainer)}]. The type is not a valid container type."); } }
public CollectionElementProperty(ArrayProperty <TContainer, TElement> property, int index, IPropertyAttributeCollection attributes = null) { m_Property = property; IsContainer = RuntimeTypeInfoCache <TElement> .IsContainerType(); Attributes = attributes; Index = index; }
/// <summary> /// Initializes a new instance of the <see cref="GeneratePropertyBagsForTypeAttribute"/> attribute. /// </summary> /// <param name="type">The type to generate a property bag for.</param> /// <exception cref="ArgumentException">The specified type is not a valid container type.</exception> public GeneratePropertyBagsForTypeAttribute(Type type) { if (!RuntimeTypeInfoCache.IsContainerType(type)) { throw new ArgumentException($"{type.Name} is not a valid container type."); } Type = type; }
/// <summary> /// Tries to visit the specified <paramref name="container"/> by ref using the specified <paramref name="visitor"/>. /// </summary> /// <param name="visitor">The visitor.</param> /// <param name="container">The container to visit.</param> /// <param name="errorCode">When this method returns, contains the error code.</param> /// <typeparam name="TContainer">The declared container type.</typeparam> /// <returns><see langword="true"/> if the visitation succeeded; <see langword="false"/> otherwise.</returns> public static bool TryAccept <TContainer>(IPropertyBagVisitor visitor, ref TContainer container, out VisitErrorCode errorCode) { if (!RuntimeTypeInfoCache <TContainer> .IsContainerType) { errorCode = VisitErrorCode.InvalidContainerType; return(false); } // Can not visit a null container. if (RuntimeTypeInfoCache <TContainer> .CanBeNull) { if (EqualityComparer <TContainer> .Default.Equals(container, default)) { errorCode = VisitErrorCode.NullContainer; return(false); } } if (!RuntimeTypeInfoCache <TContainer> .IsValueType && typeof(TContainer) != container.GetType()) { if (!RuntimeTypeInfoCache.IsContainerType(container.GetType())) { errorCode = VisitErrorCode.InvalidContainerType; return(false); } var properties = PropertyBagStore.GetPropertyBag(container.GetType()); if (null == properties) { errorCode = VisitErrorCode.MissingPropertyBag; return(false); } // At this point the generic parameter is useless to us since it's not the correct type. // Instead we need to retrieve the untyped property bag and accept on that. Since we don't know the type // We need to box the container and let the property bag cast it internally. var boxed = (object)container; properties.Accept(visitor, ref boxed); container = (TContainer)boxed; } else { var properties = PropertyBagStore.GetPropertyBag <TContainer>(); if (null == properties) { errorCode = VisitErrorCode.MissingPropertyBag; return(false); } PropertyBag.AcceptWithSpecializedVisitor(properties, visitor, ref container); } errorCode = VisitErrorCode.Ok; return(true); }
public UnmanagedProperty(string name, int offset, bool readOnly = false, IPropertyAttributeCollection attributes = null) { m_Name = name; Offset = offset; IsReadOnly = readOnly; IsContainer = RuntimeTypeInfoCache <TValue> .IsContainerType(); Attributes = attributes; }