Пример #1
0
        /// <summary>
        /// Performs application-defined tasks associated with
        /// freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (!this.IsDisposed && this.apiContext != null)
            {
                ApiConfiguratorAttribute.ApplyDisposal(
                    this.GetType(), this, this.apiContext);
            }

            this.Dispose(true);
            GC.SuppressFinalize(this);
        }
        /// <summary>
        /// Applies disposal routines from any API configurator
        /// attributes specified on an API type to an API context.
        /// </summary>
        /// <param name="type">
        /// An API type.
        /// </param>
        /// <param name="instance">
        /// An API instance, if applicable.
        /// </param>
        /// <param name="context">
        /// An API context.
        /// </param>
        public static void ApplyDisposal(
            Type type, object instance, ApiContext context)
        {
            Ensure.NotNull(type, "type");
            Ensure.NotNull(context, "context");
            var attributes = type.GetCustomAttributes(
                typeof(ApiConfiguratorAttribute), false);

            foreach (ApiConfiguratorAttribute attribute in attributes.Reverse())
            {
                attribute.Dispose(context, type, instance);
            }

            if (type.BaseType != null)
            {
                ApiConfiguratorAttribute.ApplyDisposal(
                    type.BaseType, instance, context);
            }
        }