예제 #1
0
        private static Type FindProviderAttributeType(Type type)
        {
            var concreteType = MixinTypeUtility.GetConcreteMixedType(type);
            var attribute    = AttributeUtility.GetCustomAttribute <BusinessObjectProviderAttribute> (concreteType, true);

            if (attribute == null)
            {
                var message = string.Format(
                    "The type '{0}' does not have the '{1}' applied.",
                    type.FullName,
                    typeof(BusinessObjectProviderAttribute).FullName);
                throw new ArgumentException(message, "type");
            }

            if (!TypeExtensions.CanAscribeTo(attribute.BusinessObjectProviderType, typeof(BindableObjectProvider)))
            {
                var message = string.Format(
                    "The business object provider associated with the type '{0}' is not of type '{1}'.",
                    type.FullName,
                    typeof(BindableObjectProvider).FullName);
                throw new ArgumentException(message, "type");
            }

            return(attribute.GetType());
        }
        /// <summary>
        /// Sets the <see cref="IBusinessObjectProvider"/> to be associated with the <see cref="BusinessObjectProviderAttribute"/> type specified.
        /// </summary>
        /// <param name="businessObjectProviderAttributeType">
        /// A <see cref="Type"/> derived from <see cref="BusinessObjectProviderAttribute"/>. Must not be <see langword="null" />.
        /// </param>
        /// <param name="provider">
        /// The <see cref="IBusinessObjectProvider"/> instance to be associated with the <paramref name="businessObjectProviderAttributeType"/>.
        /// Pass <see langword="null"/> to remove the association.
        /// </param>
        public static void SetProvider(Type businessObjectProviderAttributeType, IBusinessObjectProvider provider)
        {
            ArgumentUtility.CheckNotNullAndTypeIsAssignableFrom(
                "businessObjectProviderAttributeType", businessObjectProviderAttributeType, typeof(BusinessObjectProviderAttribute));

            if (provider != null)
            {
                BusinessObjectProviderAttribute attribute = CreateBusinessObjectProviderAttribute(businessObjectProviderAttributeType);
                if (!TypeExtensions.CanAscribeTo(provider.GetType(), attribute.BusinessObjectProviderType))
                {
                    throw new ArgumentException(
                              "The provider is not compatible with the provider-type required by the businessObjectProviderAttributeType's instantiation.", "provider");
                }

                if (provider is BusinessObjectProvider)
                {
                    ((BusinessObjectProvider)provider)._providerAttribute = attribute;
                }
            }

            s_businessObjectProviderStore.Remove(businessObjectProviderAttributeType);
            if (provider != null)
            {
                s_businessObjectProviderStore.Add(businessObjectProviderAttributeType, provider);
            }
        }
        public static BindableObjectBaseImplementation Create(BindableObjectBase wrapper)
        {
            ArgumentUtility.CheckNotNull("wrapper", wrapper);
            Assertion.DebugAssert(!TypeExtensions.CanAscribeTo(typeof(BindableObjectBaseImplementation), typeof(Mixin <,>)),
                                  "we assume the mixin does not have a base object");
            var impl = new BindableObjectBaseImplementation(wrapper);

            ((IInitializableMixin)impl).Initialize(wrapper, null, false);
            return(impl);
        }
예제 #4
0
        public void CheckValid(IComponentValidationCollector collector)
        {
            ArgumentUtility.CheckNotNull("collector", collector);

            if (TypeExtensions.CanAscribeTo(collector.ValidatedType, typeof(Mixin <>)))
            {
                throw new NotSupportedException(
                          string.Format(
                              "Validation rules for type '{0}' are not supported. If validation rules should be defined for mixins, "
                              + "please ensure to apply the rules to 'ITargetInterface' or 'IIntroducedInterface' instead.",
                              collector.ValidatedType.FullName));
            }
        }
 void IDeserializationCallback.OnDeserialization(object sender)
 {
     Assertion.DebugAssert(!TypeExtensions.CanAscribeTo(typeof(BindableObjectMixin), typeof(Mixin <,>)),
                           "we assume the mixin does not have a base object");
     ((IInitializableMixin)this).Initialize(_wrapper, null, true);
 }
예제 #6
0
 void IDeserializationCallback.OnDeserialization(object sender)
 {
     Assertion.DebugAssert(!TypeExtensions.CanAscribeTo(typeof(BindableObjectWithIdentityBaseImplementation), typeof(Mixin <,>)),
                           "we assume the mixin does not have a base object");
     MixinTargetMockUtility.MockMixinTargetAfterDeserialization(this, _wrapper);
 }
예제 #7
0
 protected BindableObjectBase()
 {
     Assertion.DebugAssert(!TypeExtensions.CanAscribeTo(typeof(BindableObjectMixin), typeof(Mixin <,>)),
                           "we assume the mixin does not have a base object");
     _implementation = BindableObjectBaseImplementation.Create(this);
 }