Please, help with advice :)

How can we use MethodInterception aspect with [Field]?

It seems, that our aspect replaces DO.

Aspect:


[Serializable]
    public class SetAsParentAttribute : MethodInterceptionAspect
    {
        public override void  OnInvoke(MethodInterceptionArgs args)
        {
            ((BaseEntity)args.Instance).ParentEntity = (BaseEntity)args.Arguments[0];
        }
    }

Entities:


[Serializable]
    [HierarchyRoot(InheritanceSchema = InheritanceSchema.ConcreteTable)]
    public abstract class BaseEntity : Entity
    {
        [Field, Key]
        public int Id { get; private set; }

    [Field(Nullable = false)]
    public int IdSection { get; private set; }

    [Field]
    public BaseEntity ParentEntity { get; set; }
}

public class NewsPage : BaseEntity { [Field] public string Test { get; set; }

    [Field]
    public EntitySet<OneNewsPage> ChildEntitySetNews { get; set; }

}

public class OneNewsPage : BaseEntity { public OneNewsPage(int idSection) : base(idSection) { }

    [Field]
    public DateTime DateTime { get; set; }

    [Field]
    public string ShortText { get; set; }

    [Field]
    [Association(PairTo = "ChildEntitySetNews", OnOwnerRemove = OnRemoveAction.Clear, OnTargetRemove = OnRemoveAction.Cascade)]

    public NewsPage Parent { get; [SetAsParent] set; }

}

Generated code:


[Field]
    [Association(OnOwnerRemove = OnRemoveAction.Clear, OnTargetRemove = OnRemoveAction.Cascade, PairTo = "ChildEntitySetNews")]
    public NewsPage Parent
    {
      [DebuggerNonUserCode] get
      {
        return this.GetFieldValue<newspage>("Parent");
      }
      [DebuggerNonUserCode] private set
      {
        MethodInterceptionArgsImpl interceptionArgsImpl = new MethodInterceptionArgsImpl((object) this, (Arguments) new Arguments<newspage>()
        {
          Arg0 = value
        });
        interceptionArgsImpl.Method = OneNewsPage.\u003C\u003EzAspects.m5;
        interceptionArgsImpl.TypedBinding = (MethodBinding) OneNewsPage.\u003Cset_Parent\u003EcBinding.singleton;
        OneNewsPage.\u003C\u003Ez__Aspects.a5.OnInvoke((MethodInterceptionArgs) interceptionArgsImpl);
      }
    }

So there is no this.GetFieldValue in Set.

What should we do?

asked Jun 24 '11 at 08:20

Ness's gravatar image

Ness
155232328

edited Jun 24 '11 at 08:43


One Answer:

Ness,

try applying the following attribute on your aspect:

[AspectTypeDependency(AspectDependencyAction.Order, AspectDependencyPosition.After, typeof(ReplaceAutoProperty))]

More info on the subject can be found in the official documentation.

answered Jun 24 '11 at 10:01

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

No effect :(

After decompiling we see our code, but not DO's.

(Jun 29 '11 at 10:26) Ness Ness's gravatar image

I'll try asking Gael about the issue. I suspect that there might be some attributes that are missed in the aspect declaration.

(Jun 29 '11 at 10:32) Dmitri Maximov Dmitri%20Maximov's gravatar image

Gael advised first to investigate Xtensive.Aspects on the subject of compatibility with PostSharp framework abstractions. So we are starting the process soon.

(Jun 30 '11 at 04:01) Dmitri Maximov Dmitri%20Maximov's gravatar image

Thanks in advance :)

(Jun 30 '11 at 13:02) Ness Ness's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA