Ejemplo n.º 1
0
 internal _EnumTypeBase(IEnumType original, IControlledTypeCollection genericParameters)
 {
     if (!(genericParameters is LockedTypeCollection))
         genericParameters = genericParameters.ToLockedCollection();
     this.original = original;
     this.genericParameters = (LockedTypeCollection)genericParameters;
     /* *
      * Allow the original to cache this series of generic
      * parameters to the current instance.
      * */
     if (original is _IGenericClosureRegistrar)
         ((_IGenericClosureRegistrar)(original)).RegisterGenericClosure(this, this.genericParameters);
     foreach (var type in this.genericParameters)
         type.Disposed += new EventHandler(genericParameter_Disposed);
     this.Original = original;
 }
Ejemplo n.º 2
0
 public override void Dispose()
 {
     //if (CliGateway.CompiledTypeCache.Values.Contains(this))
     //    this.RemoveFromCache();
     if (this.IsDisposed)
         return;
     lock (disposeLock)
     {
         this.disposed = true;
         if (Original is _IGenericClosureRegistrar)
             ((_IGenericClosureRegistrar)(Original)).UnregisterGenericClosure(this.genericParameters);
         this.genericParameters = null;
         this.Original = null;
     }
     base.Dispose();
 }
Ejemplo n.º 3
0
 public override void Dispose()
 {
     if (this.IsDisposed)
     {
         return;
     }
     lock (disposeLock)
     {
         this.disposed = true;
         if (original is _IGenericClosureRegistrar)
         {
             ((_IGenericClosureRegistrar)(original)).UnregisterGenericClosure(this.genericParameters);
         }
         this.genericParameters = null;
         this.original          = null;
     }
     base.Dispose();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns a <typeparamref name="TType"/> instance that is the
        /// closed generic form of the current <see cref="IntermediateGenericTypeBase{TTypeIdentifier, TType, TIntermediateType}"/>
        /// using the <paramref name="typeParameters"/> provided.
        /// </summary>
        /// <param name="typeParameters">The <see cref="ILockedTypeCollection"/>
        /// used to fill in the type-parameters.</param>
        /// <returns>A new closed <typeparamref name="TType"/> instance with
        /// the <paramref name="typeParameters"/> provided.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// The current <see cref="IntermediateGenericTypeBase{TTypeIdentifier, TType, TIntermediateType}"/>'s
        /// <seealso cref="IsGenericDefinition"/>
        /// is false.</exception>
        public TType MakeGenericClosure(IControlledTypeCollection typeParameters)
        {
            LockedTypeCollection lockedTypeParameters = typeParameters.ToLockedCollection();
            IGenericType         genericResult;

            lock (this.SyncObject)
                if (this.genericCache != null && genericCache.TryObtainGenericClosure(lockedTypeParameters, out genericResult))
                {
                    return((TType)genericResult);
                }
                else
                {
                    if (this.genericCache == null)
                    {
                        this.genericCache = new GenericTypeCache();
                    }
                    var result = this.OnMakeGenericClosure(lockedTypeParameters);
                    this.genericCache.RegisterGenericType(result, lockedTypeParameters);
                    return(result);
                }
        }
Ejemplo n.º 5
0
        public void PositionalShift(int from, int to)
        {
            if (this.IsDisposed)
            {
                return;
            }
            if (from < 0 || from >= this.genericParameters.Count)
            {
                throw new ArgumentOutOfRangeException("from");
            }
            if (to < 0 || to >= this.genericParameters.Count)
            {
                throw new ArgumentOutOfRangeException("to");
            }
            if (from == to)
            {
                return;
            }
            var  items     = this.genericParameters.ToArray();
            bool backwards = from > to;
            var  item      = items[from];

            if (backwards)
            {
                for (int i = from; i > to; i--)
                {
                    items[i] = items[i - 1];
                }
            }
            else
            {
                for (int i = from; i < to; i++)
                {
                    items[i] = items[i + 1];
                }
            }

            items[to] = item;
            this.genericParameters = new LockedTypeCollection(items);
        }
Ejemplo n.º 6
0
 protected override IDelegateType OnMakeGenericClosure(LockedTypeCollection lockedTypeParameters)
 {
     return(new _DelegateTypeBase(this, lockedTypeParameters));
 }
Ejemplo n.º 7
0
 protected abstract TType OnMakeGenericClosure(LockedTypeCollection lockedTypeParameters);
Ejemplo n.º 8
0
        AddIntermediateMethodByDelegate <
            TSignatureParameter, TIntermediateSignatureParameter, TSignature, TIntermediateSignature, TSignatureParent, TIntermediateSignatureParent>
        (
            string name,
            IDelegateType signature,
            Func <string, TIntermediateSignature> addHelper,
            Func <TypedName, TypedNameSeries, TIntermediateSignature> addHelperAlt
        )
            where TSignatureParameter :
        IMethodSignatureParameterMember <TSignatureParameter, TSignature, TSignatureParent>
            where TIntermediateSignatureParameter :
        IIntermediateMethodSignatureParameterMember <TSignatureParameter, TIntermediateSignatureParameter, TSignature, TIntermediateSignature, TSignatureParent, TIntermediateSignatureParent>,
        TSignatureParameter
            where TSignature :
        IMethodSignatureMember <TSignatureParameter, TSignature, TSignatureParent>
            where TIntermediateSignature :
        IIntermediateMethodSignatureMember <TSignatureParameter, TIntermediateSignatureParameter, TSignature, TIntermediateSignature, TSignatureParent, TIntermediateSignatureParent>,
        TSignature
            where TSignatureParent :
        ISignatureParent <IGeneralGenericSignatureMemberUniqueIdentifier, TSignature, TSignatureParameter, TSignatureParent>
            where TIntermediateSignatureParent :
        IIntermediateSignatureParent <IGeneralGenericSignatureMemberUniqueIdentifier, TSignature, TIntermediateSignature, TSignatureParameter, TIntermediateSignatureParameter, TSignatureParent, TIntermediateSignatureParent>,
        TSignatureParent
        {
            /* *
             * If the method being added wants to mirror the declaration
             * of the delegate, and the delegate is a generic type with
             * no specific type references added: mirror the definition
             * down to the generic parameters.
             * */
            if (signature.IsGenericConstruct && signature.IsGenericDefinition && signature.Parent == null)
            {
                var method                    = addHelper(name);
                var genericParameters         = new IIntermediateGenericParameter[signature.TypeParameters.Count];
                var originalGenericParameters = signature.TypeParameters.Values.ToArray();

                for (int i = 0; i < originalGenericParameters.Length; i++)
                {
                    genericParameters[i] = method.TypeParameters.Add(originalGenericParameters[i].Name);
                }
                var genericParameterCollection = new LockedTypeCollection(genericParameters);

                for (int i = 0; i < originalGenericParameters.Length; i++)
                {
                    var originalGenericParameter = originalGenericParameters[i];
                    var currentGenericParameter  = genericParameters[i];
                    foreach (var constraint in originalGenericParameter.Constraints)
                    {
                        currentGenericParameter.Constraints.Add(constraint.Disambiguify(genericParameterCollection, null, TypeParameterSources.Type));
                    }
                    currentGenericParameter.SpecialConstraint = originalGenericParameter.SpecialConstraint;
                }

                method.Parameters.AddRange((from p in signature.Parameters.Values
                                            let paramType = p.ParameterType.Disambiguify(genericParameterCollection, null, TypeParameterSources.Type)
                                                            select new TypedName(p.Name, paramType)).ToArray());
                method.ReturnType = signature.ReturnType.Disambiguify(genericParameterCollection, null, TypeParameterSources.Type);
                return(method);
            }

            /* *
             * Otherwise, just copy the types defined in the parameters.
             * */
            else if (!(signature.IsGenericConstruct && signature.IsGenericDefinition))
            {
                return(addHelperAlt(new TypedName(name, signature.ReturnType), new TypedNameSeries((from p in signature.Parameters.Values
                                                                                                    select new TypedName(p.Name, p.ParameterType)).ToArray())));
            }
            else
            {
                throw new NotSupportedException("Generic type provided must be a top-level type.");
            }
        }
Ejemplo n.º 9
0
 protected override TType OnMakeGenericClosure(LockedTypeCollection lockedTypeParameters)
 {
     throw new NotImplementedException();
 }