Beispiel #1
0
        /// <summary>
        /// Initializes an instance of <see cref="EnumerableWrapperProvider"/>.
        /// </summary>
        /// <param name="sourceEnumerableOfT">Type of the original <see cref="IEnumerable{T}" />
        /// that is being wrapped.</param>
        /// <param name="elementWrapperProvider">The <see cref="IWrapperProvider"/> for the element type.
        /// Can be null.</param>
        public EnumerableWrapperProvider(
            Type sourceEnumerableOfT,
            IWrapperProvider elementWrapperProvider)
        {
            if (sourceEnumerableOfT == null)
            {
                throw new ArgumentNullException(nameof(sourceEnumerableOfT));
            }

            var enumerableOfT = ClosedGenericMatcher.ExtractGenericInterface(
                sourceEnumerableOfT,
                typeof(IEnumerable <>));

            if (!sourceEnumerableOfT.GetTypeInfo().IsInterface || enumerableOfT == null)
            {
                throw new ArgumentException($"The type must be an interface and must be or derive from '{typeof(IEnumerable<>).Name}'.",
                                            nameof(sourceEnumerableOfT));
            }

            _wrapperProvider = elementWrapperProvider;

            var declaredElementType = enumerableOfT.GenericTypeArguments[0];
            var wrappedElementType  = elementWrapperProvider?.WrappingType ?? declaredElementType;

            WrappingType = typeof(DelegatingEnumerable <,>).MakeGenericType(wrappedElementType, declaredElementType);

            _wrappingTypeConstructor = WrappingType.GetConstructor(new[]
            {
                sourceEnumerableOfT,
                typeof(IWrapperProvider)
            });
        }
        /// <summary>
        /// Initializes an instance of <see cref="EnumerableWrapperProvider"/>.
        /// </summary>
        /// <param name="sourceEnumerableOfT">Type of the original <see cref="IEnumerable{T}" />
        /// that is being wrapped.</param>
        /// <param name="elementWrapperProvider">The <see cref="IWrapperProvider"/> for the element type.
        /// Can be null.</param>
        public EnumerableWrapperProvider(
            Type sourceEnumerableOfT,
            IWrapperProvider elementWrapperProvider)
        {
            if (sourceEnumerableOfT == null)
            {
                throw new ArgumentNullException(nameof(sourceEnumerableOfT));
            }

            var enumerableOfT = ClosedGenericMatcher.ExtractGenericInterface(
                sourceEnumerableOfT,
                typeof(IEnumerable <>));

            if (!sourceEnumerableOfT.IsInterface || enumerableOfT == null)
            {
                throw new ArgumentException(
                          Resources.FormatEnumerableWrapperProvider_InvalidSourceEnumerableOfT(typeof(IEnumerable <>).Name),
                          nameof(sourceEnumerableOfT));
            }

            _wrapperProvider = elementWrapperProvider;

            var declaredElementType = enumerableOfT.GenericTypeArguments[0];
            var wrappedElementType  = elementWrapperProvider?.WrappingType ?? declaredElementType;

            WrappingType = typeof(DelegatingEnumerable <,>).MakeGenericType(wrappedElementType, declaredElementType);

            _wrappingTypeConstructor = WrappingType.GetConstructor(new[]
            {
                sourceEnumerableOfT,
                typeof(IWrapperProvider)
            });
        }
Beispiel #3
0
        public static dynamic GetTSObject(WrappingType dynEnum)
        {
            var tsType = TSActivator.CreateInstance("Tekla.Structures.Forming.WrappingType").GetType();

            switch (dynEnum)
            {
            case WrappingType.NOT_SPECIFIED:
                return(System.Enum.Parse(tsType, "NOT_SPECIFIED"));

            case WrappingType.WRAPPED:
                return(System.Enum.Parse(tsType, "WRAPPED"));

            case WrappingType.UNWRAPPED:
                return(System.Enum.Parse(tsType, "UNWRAPPED"));

            default:
                throw new DynamicAPIException(dynEnum.ToString() + "- enum value is not implemented");
            }
        }