private object GetDepthValue(object mixin) { var nextProperty = MixinReflector.GetNextProperty(mixin.GetType()); var baseValue = nextProperty.GetValue(mixin, null); return(PrivateInvoke.GetPublicField(baseValue, "__depth")); }
public void GetOrderedMixinTypes_OpenGenericMixinTypesAreClosed() { var concreteMixedType = MixinTypeUtility.GetConcreteMixedType(typeof(BaseType3)); Assert.That(MixinReflector.GetOrderedMixinTypesFromConcreteType(concreteMixedType), Has.Member(typeof(BT3Mixin3 <BaseType3, IBaseType33>))); }
public void GetOrderedMixinTypes_OrderedMixinTypes() { var concreteMixedType = MixinTypeUtility.GetConcreteMixedType(typeof(BaseType7)); Assert.That( MixinReflector.GetOrderedMixinTypesFromConcreteType(concreteMixedType), Is.EqualTo(BigTestDomainScenarioTest.ExpectedBaseType7OrderedMixinTypesSmall)); }
public void GetMixinNextCallProxyType() { var bt1 = ObjectFactory.Create <BaseType1> (ParamList.Empty); Type bcpt = MixinReflector.GetNextCallProxyType(bt1); Assert.That(bcpt, Is.Not.Null); Assert.That(bcpt, Is.EqualTo(bt1.GetType().GetNestedType("NextCallProxy"))); }
private Expression GetTargetReference() { var targetProperty = MixinReflector.GetTargetProperty(_type.BaseType); if (targetProperty == null) { throw new NotSupportedException( "The code generator does not support mixins with overridden methods or non-public overriders if the mixin doesn't derive from the " + "generic Mixin base classes."); } return(Expression.Property(new ThisExpression(_type), targetProperty)); }
/// <summary> /// Gets the mixin types associated with the given <paramref name="targetOrConcreteType"/>, ordered and closed (if generic) exactly as they are /// held by instances of the concrete type. /// </summary> /// <param name="targetOrConcreteType">The type to check for mixin types.</param> /// <returns>The mixins included in <paramref name="targetOrConcreteType"/> if it is a generated type; otherwise the mixins currently configured for /// <paramref name="targetOrConcreteType"/>.</returns> /// <remarks> /// <para> /// This method returns the mixin types exactly as they are held in the <see cref="IMixinTarget.Mixins"/> property by the concrete type /// corresponding to <paramref name="targetOrConcreteType"/> (or <paramref name="targetOrConcreteType"/> itself if it is a generated concrete /// type). /// </para> /// <para> /// <note type="caution"> /// This method requires the concrete mixed type, so it may invoke the code generation for <paramref name="targetOrConcreteType"/> /// (if it is not already a concrete type) unless code has already been generated for that type. /// This could cause a performance problem when called in a tight loop with types for which no code has been generated so far. /// Consider using <see cref="GetMixinTypes"/> for a faster variant. /// </note> /// </para> /// <para> /// The results of this method are cached. /// </para> /// </remarks> public static ReadOnlyCollection <Type> GetMixinTypesExact(Type targetOrConcreteType) { ArgumentUtility.CheckNotNull("targetOrConcreteType", targetOrConcreteType); var concreteType = GetConcreteMixedType(targetOrConcreteType); return(s_exactMixinTypesCache.GetOrCreateValue( concreteType, t => { var types = MixinReflector.GetOrderedMixinTypesFromConcreteType(concreteType); return Array.AsReadOnly(types ?? Type.EmptyTypes); })); }
public void GeneratedTypeCorrectlySerializesThisAndBase() { ClassOverridingMixinMembers targetInstance = CreateMixedObject <ClassOverridingMixinMembers> (typeof(MixinWithAbstractMembers)); var mixin = Mixin.Get <MixinWithAbstractMembers> (targetInstance); Assert.That(MixinReflector.GetTargetProperty(mixin.GetType()).GetValue(mixin, null), Is.EqualTo(targetInstance)); Assert.That(MixinReflector.GetNextProperty(mixin.GetType()).GetValue(mixin, null).GetType(), Is.EqualTo(MixinReflector.GetNextCallProxyType(targetInstance))); ClassOverridingMixinMembers targetInstanceA = Serializer.SerializeAndDeserialize(targetInstance); var mixinA = Mixin.Get <MixinWithAbstractMembers> (targetInstanceA); Assert.That(MixinReflector.GetTargetProperty(mixinA.GetType()).GetValue(mixinA, null), Is.EqualTo(targetInstanceA)); Assert.That(MixinReflector.GetNextProperty(mixinA.GetType()).GetValue(mixinA, null).GetType(), Is.EqualTo(MixinReflector.GetNextCallProxyType(targetInstanceA))); }
public void GetBaseProperty() { Assert.That(MixinReflector.GetNextProperty(typeof(BT1Mixin1)), Is.Null); Assert.That(MixinReflector.GetNextProperty(typeof(BT3Mixin1)), Is.Not.Null); Assert.That( MixinReflector.GetNextProperty(typeof(BT3Mixin1)), Is.EqualTo( typeof(Mixin <IBaseType31, IBaseType31>).GetProperty("Next", BindingFlags.NonPublic | BindingFlags.Instance))); Assert.That(MixinReflector.GetNextProperty(typeof(BT3Mixin2)), Is.Null); Assert.That(MixinReflector.GetNextProperty(typeof(BT3Mixin3 <BaseType3, IBaseType33>)), Is.Not.Null); Assert.That(MixinReflector.GetNextProperty(typeof(BT3Mixin3 <BaseType3, IBaseType33>)), Is.Not.EqualTo(typeof(Mixin <,>).GetProperty("Next", BindingFlags.NonPublic | BindingFlags.Instance))); Assert.That(MixinReflector.GetNextProperty(typeof(BT3Mixin3 <BaseType3, IBaseType33>)), Is.EqualTo(typeof(Mixin <BaseType3, IBaseType33>).GetProperty("Next", BindingFlags.NonPublic | BindingFlags.Instance))); }
public void GenericMixinsAreSpecialized() { BaseType3 bt3 = CreateMixedObject <BaseType3> (typeof(BT3Mixin3 <,>)); object mixin = Mixin.Get(typeof(BT3Mixin3 <,>), bt3); Assert.That(mixin, Is.Not.Null); PropertyInfo targetProperty = MixinReflector.GetTargetProperty(mixin.GetType()); Assert.That(targetProperty, Is.Not.Null); Assert.That(targetProperty.GetValue(mixin, null), Is.Not.Null); Assert.That(targetProperty.GetValue(mixin, null), Is.SameAs(bt3)); Assert.That(targetProperty.PropertyType, Is.EqualTo(typeof(BaseType3))); PropertyInfo nextProperty = MixinReflector.GetNextProperty(mixin.GetType()); Assert.That(nextProperty, Is.Not.Null); Assert.That(nextProperty.GetValue(mixin, null), Is.Not.Null); Assert.That(nextProperty.GetValue(mixin, null).GetType(), Is.SameAs(bt3.GetType().GetField("__first", BindingFlags.NonPublic | BindingFlags.Instance).FieldType)); Assert.That(nextProperty.PropertyType, Is.EqualTo(typeof(IBaseType33))); }
private void MixinNeedingDerivedTypeMustBeDerivedFromMixinBase(DelegateValidationRule <MixinDefinition> .Args args) { SingleMust(!args.Definition.NeedsDerivedMixinType() || MixinReflector.GetMixinBaseType(args.Definition.Type) != null, args.Log, args.Self); }
public void IsGeneratedByMixinEngine_OnNextCallProxy() { Type nextCallProxy = MixinReflector.GetNextCallProxyType(ObjectFactory.Create <BaseType1> (ParamList.Empty)); Assert.That(MixinTypeUtility.IsGeneratedByMixinEngine(nextCallProxy), Is.True); }
public void IsGeneratedConcreteMixedType_OnNextCallProxy() { Type nextCallProxy = MixinReflector.GetNextCallProxyType(ObjectFactory.Create <BaseType1>(ParamList.Empty)); Assert.That(MixinTypeUtility.IsGeneratedConcreteMixedType(nextCallProxy), Is.False); }
private void OverridingMixinMethodsOnlyPossibleWhenMixinDerivedFromMixinBase(DelegateValidationRule <MethodDefinition> .Args args) { SingleMust(!(args.Definition.DeclaringClass is MixinDefinition) || args.Definition.Overrides.Count == 0 || MixinReflector.GetMixinBaseType(args.Definition.DeclaringClass.Type) != null, args.Log, args.Self); }
public void GetOrderedMixinTypes_NullWhenNoMixedType() { Assert.That(MixinReflector.GetOrderedMixinTypesFromConcreteType(typeof(object)), Is.Null); }
public void GetMixinNextCallProxyTypeThrowsIfWrongType1() { MixinReflector.GetNextCallProxyType(new object()); }