示例#1
0
                private void AddMethod(MethodBase _method)
                {
                    var _neptuneMethodIndex = NeptuneMethodIndexUninitialized;

                    WeaverBase.GetNeptuneMethodIndex(_method, ref _neptuneMethodIndex);
                    if (_neptuneMethodIndex != NeptuneMethodIndexMissing)
                    {
                        Methods[_neptuneMethodIndex] = _method;
                    }
                }
示例#2
0
            /// <summary>
            /// Not thread safe
            /// </summary>
            static public void Add(WeaverBase weaver)
            {
                if (m_Adding)
                {
                    // might break order of weaving, but probably otherwise safe
                    throw new NotImplementedException("Weaving aspects on closed generics can not be done recursively");
                }

                m_Adding = true;
                m_ReadWriteLock.EnterUpgradeableReadLock();
                try
                {
                    int _index = 0;
                    for (; _index < m_ConstructedGenerics.Count; _index++)
                    {
                        var _constructedGeneric = m_ConstructedGenerics[_index];
                        _constructedGeneric.Weave(weaver);
                    }
                    //m_ReadWriteLock.EnterWriteLock();
                    m_ReadWriteLock.EnterWriteLock();
                    try
                    {
                        for (; _index < m_ConstructedGenerics.Count; _index++)
                        {
                            var _constructedGeneric = m_ConstructedGenerics[_index];
                            _constructedGeneric.Weave(weaver);
                        }

                        Extend(ref m_ClosedWeavers, weaver);
                    }
                    finally
                    {
                        m_ReadWriteLock.ExitWriteLock();
                    }
                }
                finally
                {
                    m_ReadWriteLock.EnterUpgradeableReadLock();
                    m_Adding = false;
                }
            }
示例#3
0
 public override void Weave(WeaverBase weaver)
 {
     weaver.WeaveConstructedGenericType(this);
 }
示例#4
0
 public override void Weave(WeaverBase weaver)
 {
     weaver.WeaveConstructedGenericMethod(m_method, m_neptuneMethodIndex);
 }
示例#5
0
 public override void Weave(WeaverBase weaver)
 {
     weaver.WeaveMethodInConstructedType(m_method, m_neptuneMethodIndex);
 }
示例#6
0
 public abstract void Weave(WeaverBase weaver);
示例#7
0
 public StopwatchLog(WeaverBase weaver, string text)
 {
     this.weaver    = weaver;
     this.stopwatch = Stopwatch.StartNew();
     this.text      = text;
 }
示例#8
0
                public void Initialize()
                {
                    lock (m_Handle)
                    {
                        if (!NeedInitialization)
                        {
                            return;
                        }
                        WeaverBase.GetNeptuneMethodIndex(this.Method, ref m_neptuneMethodIndex);
                        if (Type.IsGenericTypeDefinition)
                        {
                            // do the remaining outside the lock
                            NeedInitialization = false;
                            goto FinalizeGenericTypeDefinition;
                        }
                        else
                        {
                            if (Method.IsGenericMethodDefinition)
                            {
                                if (Type.IsGenericType)
                                {
                                    AddToDefinition(GenericWeavers.GetTypeDefinitionItem(Type.GetGenericTypeDefinition()));
                                }
                            }
                            else
                            {
                                if (Method.IsGenericMethod)
                                {
                                    AddToDefinition(GenericWeavers.GetTypeItem(Type));
                                }
                                else
                                {
                                    AddToDefinition(GenericWeavers.GetTypeDefinitionItem(Type.GetGenericTypeDefinition()));
                                }
                            }
                            // do the remaining outside the lock
                        }
                        NeedInitialization = false;
                    }

                    // since we are outside the lock a competing thread may have done any of the following but none of it
                    // should have problem with that, but they all may take lock on parent and we cannot allow that while child locked
                    // due to risk od dead lock (we should always lock parent before child to avoid dead lock)

                    if (this.GenericDefinition != null)
                    {
                        if (this.GenericDefinition.NeedInitialization)
                        {
                            this.GenericDefinition.Initialize();
                        }
                        GenericDefinition.InstantiateChild(this);
                    }

                    if (Method.IsGenericMethodDefinition)
                    {
                        foreach (var _method in GenericWeavers.GetGenericMethodDefinitionItem(Method).ConstructedMethods)
                        {
                            // just need to create the entry it will add it self to this.GenericInstances
                            Obtain(_method, m_neptuneMethodIndex);
                        }
                    }
                    return;

FinalizeGenericTypeDefinition:
                    foreach (var _typeItem in GenericWeavers.GetTypeDefinitionItem(Type).ConstructedTypes.Values)
                    {
                        // todo Jens write a unittest that verify the claim below
                        // we could do it now but then we might trigger type loading earlier than if not used
                        // also the side effect unit tests assume it happens on first invoke
                        if (_typeItem.InvokedMethods[m_neptuneMethodIndex])
                        {
                            // just need to create the entry it will add it self to this.GenericInstances
                            Obtain(_typeItem.Methods[m_neptuneMethodIndex]);
                        }
                    }
                    return;
                }