Exemplo n.º 1
0
        public IType ObtainTypeReference(RuntimeCoreType coreType, IAssembly assembly)
        {
            Dictionary <RuntimeCoreType, IType> currentCache = null;

            lock (lookupCache)
            {
                CheckLUC(assembly);
                if (assembly != null)
                {
                    currentCache = lookupCache[assembly];
                    lock (currentCache)
                    {
                        if (currentCache != null)
                        {
                            IType result;
                            if (currentCache.TryGetValue(coreType, out result))
                            {
                                return(result);
                            }
                        }
                    }
                }
            }
            ICliRuntimeEnvironmentInfo runtimeEnvironmentInfo = this.runtimeEnvironment;

            if (assembly is ICliAssembly)
            {
                ICliAssembly cliAssembly = (ICliAssembly)assembly;
                if (cliAssembly.RuntimeEnvironment.Version != runtimeEnvironmentInfo.Version)
                {
                    runtimeEnvironmentInfo = cliAssembly.RuntimeEnvironment;
                }
            }
            var resultType = this.ObtainTypeReference(runtimeEnvironmentInfo.GetCoreIdentifier(coreType), assembly);

            if (currentCache != null)
            {
                lock (lookupCache)
                    lock (currentCache)
                        currentCache.Add(coreType, resultType);
            }
            return(resultType);
        }
Exemplo n.º 2
0
        internal static bool IsLastParams <TParent, TParameter>(this IParameterParent <TParent, TParameter> parent, ICliAssembly assembly, _ICliManager manager)
            where TParent :
        IParameterParent <TParent, TParameter>
            where TParameter :
        class,
        IParameterMember <TParent>
        {
            var @params   = parent.Parameters;
            var lastParam = @params.Count == 0 ? (TParameter)null : @params[@params.Keys[@params.Count - 1]];

            if (lastParam == null)
            {
                return(false);
            }
            return(lastParam.IsDefined(manager.ObtainTypeReference(assembly.RuntimeEnvironment.ParamArrayMetadatum, assembly)));
        }
Exemplo n.º 3
0
        //#endregion

        public IType ObtainTypeReference(ICliMetadataNativeTypeSignature typeIdentity, ICliAssembly assembly)
        {
            var runtimeEnvironmentInfo = assembly.RuntimeEnvironment;

            switch (typeIdentity.TypeKind)
            {
            case CliMetadataNativeTypes.Boolean:
                return(this.ObtainTypeReference(RuntimeCoreType.Boolean, assembly));

            case CliMetadataNativeTypes.Char:
                return(this.ObtainTypeReference(RuntimeCoreType.Char, assembly));

            case CliMetadataNativeTypes.SByte:
                return(this.ObtainTypeReference(RuntimeCoreType.SByte, assembly));

            case CliMetadataNativeTypes.Byte:
                return(this.ObtainTypeReference(RuntimeCoreType.Byte, assembly));

            case CliMetadataNativeTypes.Int16:
                return(this.ObtainTypeReference(RuntimeCoreType.Int16, assembly));

            case CliMetadataNativeTypes.UInt16:
                return(this.ObtainTypeReference(RuntimeCoreType.UInt16, assembly));

            case CliMetadataNativeTypes.Int32:
                return(this.ObtainTypeReference(RuntimeCoreType.Int32, assembly));

            case CliMetadataNativeTypes.UInt32:
                return(this.ObtainTypeReference(RuntimeCoreType.UInt32, assembly));

            case CliMetadataNativeTypes.Int64:
                return(this.ObtainTypeReference(RuntimeCoreType.Int64, assembly));

            case CliMetadataNativeTypes.UInt64:
                return(this.ObtainTypeReference(RuntimeCoreType.UInt64, assembly));

            case CliMetadataNativeTypes.Single:
                return(this.ObtainTypeReference(RuntimeCoreType.Single, assembly));

            case CliMetadataNativeTypes.Double:
                return(this.ObtainTypeReference(RuntimeCoreType.Double, assembly));

            case CliMetadataNativeTypes.String:
                return(this.ObtainTypeReference(RuntimeCoreType.String, assembly));

            case CliMetadataNativeTypes.Void:
                return(this.ObtainTypeReference(RuntimeCoreType.VoidType, assembly));

            case CliMetadataNativeTypes.TypedByReference:
                if (this.RuntimeEnvironment.UseCoreLibrary)
                {
                    return(this.ObtainTypeReference(this.RuntimeEnvironment.CoreLibraryIdentifier.GetTypeIdentifier("System", "TypedReference"), assembly));
                }
                else
                {
                    return(this.ObtainTypeReference(TypeSystemIdentifiers.GetTypeIdentifier("System", "TypedReference"), assembly));
                }

            case CliMetadataNativeTypes.NativeInteger:
                if (this.RuntimeEnvironment.UseCoreLibrary)
                {
                    return(this.ObtainTypeReference(this.RuntimeEnvironment.CoreLibraryIdentifier.GetTypeIdentifier("System", "IntPtr"), assembly));
                }
                else
                {
                    return(this.ObtainTypeReference(TypeSystemIdentifiers.GetTypeIdentifier("System", "IntPtr"), assembly));
                }

            case CliMetadataNativeTypes.NativeUnsignedInteger:
                if (this.RuntimeEnvironment.UseCoreLibrary)
                {
                    return(this.ObtainTypeReference(this.RuntimeEnvironment.CoreLibraryIdentifier.GetTypeIdentifier("System", "UIntPtr"), assembly));
                }
                else
                {
                    return(this.ObtainTypeReference(TypeSystemIdentifiers.GetTypeIdentifier("System", "UIntPtr"), assembly));
                }

            case CliMetadataNativeTypes.Object:
                if (this.RuntimeEnvironment.UseCoreLibrary)
                {
                    return(this.ObtainTypeReference(RuntimeCoreType.RootType));
                }
                else
                {
                    return(this.ObtainTypeReference(RuntimeCoreType.RootType, assembly));
                }

            case CliMetadataNativeTypes.Type:
                return(this.ObtainTypeReference(RuntimeCoreType.Type, assembly));

            default:
                throw new NotSupportedException("Native type not supported.");
            }
            throw new NotSupportedException();
        }
Exemplo n.º 4
0
 public IType ObtainTypeReference(CliRuntimeCoreType coreType, ICliAssembly assembly)
 {
     return(this.ObtainTypeReference(this.RuntimeEnvironment.GetCoreIdentifier(coreType, assembly), assembly));
 }