Example #1
0
        //
        // Returns the native layout info reader
        //
        internal static unsafe NativeReader GetNativeLayoutInfoReader(TypeManagerHandle moduleHandle)
        {
            Debug.Assert(!moduleHandle.IsNull);

            if (t_moduleNativeReaders == null)
            {
                t_moduleNativeReaders = new LowLevelDictionary <TypeManagerHandle, NativeReader>();
            }

            NativeReader result;

            if (t_moduleNativeReaders.TryGetValue(moduleHandle, out result))
            {
                return(result);
            }

            byte *pBlob;
            uint  cbBlob;

            if (RuntimeAugments.FindBlob(moduleHandle, (int)ReflectionMapBlob.NativeLayoutInfo, new IntPtr(&pBlob), new IntPtr(&cbBlob)))
            {
                result = new NativeReader(pBlob, cbBlob);
            }

            t_moduleNativeReaders.Add(moduleHandle, result);
            return(result);
        }
        /// <summary>
        /// Get a DefType that is the generic instantiation of an open generic type over instantiation arguments
        /// This looks like a rename of GetInstantiatedType, but isn't because the corert GetInstantiatedType
        /// relies on typeDef being a MetadataType, whereas this permits non-metadata types.
        /// </summary>
        public DefType ResolveGenericInstantiation(DefType typeDef, Instantiation arguments)
        {
            Debug.Assert(typeDef.Instantiation.IsNull || typeDef.Instantiation.Length == arguments.Length);

            MetadataType typeAsMetadataType = typeDef as MetadataType;

            if (typeAsMetadataType != null)
            {
                return(GetInstantiatedType(typeAsMetadataType, arguments));
            }

            if (_genericTypeInstances == null)
            {
                _genericTypeInstances = new LowLevelDictionary <GenericTypeInstanceKey, DefType>();
            }

            GenericTypeInstanceKey key = new GenericTypeInstanceKey(typeDef, arguments);

            DefType result;

            if (!_genericTypeInstances.TryGetValue(key, out result))
            {
                NoMetadataType nmTypeDef = (NoMetadataType)typeDef;
                Debug.Assert(RuntimeAugments.IsGenericTypeDefinition(nmTypeDef.RuntimeTypeHandle));
                result = new NoMetadataType(this, nmTypeDef.RuntimeTypeHandle, nmTypeDef, arguments, key.GetHashCode());

                _genericTypeInstances.Add(key, result);
            }

            return(result.WithDebugName());
        }
Example #3
0
 // Eager initialization called from LibraryInitializer for the assembly.
 internal static void Initialize()
 {
     Instance = new TypeLoaderEnvironment();
     RuntimeAugments.InitializeLookups(new Callbacks());
     s_nativeFormatStrings = new LowLevelDictionary<string, IntPtr>();
     NoStaticsData = (IntPtr)1;
 }
Example #4
0
        //schemeStr must be in lower case!
        internal static UriParser FindOrFetchAsUnknownV1Syntax(string lwrCaseScheme)
        {
            // check may be other thread just added one
            UriParser syntax = null;

            s_table.TryGetValue(lwrCaseScheme, out syntax);
            if (syntax != null)
            {
                return(syntax);
            }
            s_tempTable.TryGetValue(lwrCaseScheme, out syntax);
            if (syntax != null)
            {
                return(syntax);
            }
            lock (s_table)
            {
                if (s_tempTable.Count >= c_MaxCapacity)
                {
                    s_tempTable = new LowLevelDictionary <string, UriParser>(c_InitialTableSize);
                }
                syntax = new BuiltInUriParser(lwrCaseScheme, NoDefaultPort, UnknownV1SyntaxFlags);
                s_tempTable[lwrCaseScheme] = syntax;
                return(syntax);
            }
        }
        public void RegisterDynamicThreadStaticsInfo(RuntimeTypeHandle runtimeTypeHandle, uint offsetValue, IntPtr gcDesc)
        {
            bool registered = false;

            Debug.Assert(offsetValue != 0 && runtimeTypeHandle.IsDynamicType());

            IntPtr typeManager = runtimeTypeHandle.GetTypeManager().GetIntPtrUNSAFE();

            _threadStaticsLock.Acquire();
            try
            {
                if (!_dynamicGenericsThreadStaticDescs.TryGetValue(typeManager, out LowLevelDictionary <uint, IntPtr> gcDescs))
                {
                    _dynamicGenericsThreadStaticDescs.Add(typeManager, gcDescs = new LowLevelDictionary <uint, IntPtr>());
                }
                gcDescs.Add(offsetValue, gcDesc);
                registered = true;
            }
            finally
            {
                if (!registered)
                {
                    if (_dynamicGenericsThreadStaticDescs.TryGetValue(typeManager, out LowLevelDictionary <uint, IntPtr> gcDescs))
                    {
                        gcDescs.Remove(offsetValue);
                    }
                }

                _threadStaticsLock.Release();
            }
        }
Example #6
0
        static UriParser()
        {
            s_table     = new LowLevelDictionary <string, UriParser>(c_InitialTableSize);
            s_tempTable = new LowLevelDictionary <string, UriParser>(c_InitialTableSize);

            //Now we will call for the instance constructors that will interrupt this static one.

            // Below we simulate calls into FetchSyntax() but avoid using lock() and other things redundant for a .cctor

            HttpUri = new BuiltInUriParser("http", 80, HttpSyntaxFlags);
            s_table[HttpUri.SchemeName] = HttpUri;                   //HTTP

            HttpsUri = new BuiltInUriParser("https", 443, HttpUri._flags);
            s_table[HttpsUri.SchemeName] = HttpsUri;                  //HTTPS cloned from HTTP

            WsUri = new BuiltInUriParser("ws", 80, HttpSyntaxFlags);
            s_table[WsUri.SchemeName] = WsUri;                   // WebSockets

            WssUri = new BuiltInUriParser("wss", 443, HttpSyntaxFlags);
            s_table[WssUri.SchemeName] = WssUri;                  // Secure WebSockets

            FtpUri = new BuiltInUriParser("ftp", 21, FtpSyntaxFlags);
            s_table[FtpUri.SchemeName] = FtpUri;                    //FTP

            FileUri     = new BuiltInUriParser("file", NoDefaultPort, s_fileSyntaxFlags);
            UnixFileUri = new BuiltInUriParser("file", NoDefaultPort, s_unixFileSyntaxFlags);
            s_table[FileUri.SchemeName] = FileUri;                   //FILE

            GopherUri = new BuiltInUriParser("gopher", 70, GopherSyntaxFlags);
            s_table[GopherUri.SchemeName] = GopherUri;                 //GOPHER

            NntpUri = new BuiltInUriParser("nntp", 119, NntpSyntaxFlags);
            s_table[NntpUri.SchemeName] = NntpUri;                   //NNTP

            NewsUri = new BuiltInUriParser("news", NoDefaultPort, NewsSyntaxFlags);
            s_table[NewsUri.SchemeName] = NewsUri;                   //NEWS

            MailToUri = new BuiltInUriParser("mailto", 25, MailtoSyntaxFlags);
            s_table[MailToUri.SchemeName] = MailToUri;                 //MAILTO

            UuidUri = new BuiltInUriParser("uuid", NoDefaultPort, NewsUri._flags);
            s_table[UuidUri.SchemeName] = UuidUri;                   //UUID cloned from NEWS

            TelnetUri = new BuiltInUriParser("telnet", 23, TelnetSyntaxFlags);
            s_table[TelnetUri.SchemeName] = TelnetUri;                 //TELNET

            LdapUri = new BuiltInUriParser("ldap", 389, LdapSyntaxFlags);
            s_table[LdapUri.SchemeName] = LdapUri;                   //LDAP

            NetTcpUri = new BuiltInUriParser("net.tcp", 808, NetTcpSyntaxFlags);
            s_table[NetTcpUri.SchemeName] = NetTcpUri;

            NetPipeUri = new BuiltInUriParser("net.pipe", NoDefaultPort, NetPipeSyntaxFlags);
            s_table[NetPipeUri.SchemeName] = NetPipeUri;

            VsMacrosUri = new BuiltInUriParser("vsmacros", NoDefaultPort, VsmacrosSyntaxFlags);
            s_table[VsMacrosUri.SchemeName] = VsMacrosUri;               //VSMACROS
        }
Example #7
0
 internal ModuleMap(ModuleInfo[] modules)
 {
     Modules             = modules;
     HandleToModuleIndex = new LowLevelDictionary <IntPtr, int>();
     for (int moduleIndex = 0; moduleIndex < Modules.Length; moduleIndex++)
     {
         HandleToModuleIndex.Add(Modules[moduleIndex].Handle, moduleIndex);
     }
 }
Example #8
0
        private static IDictionary GetEnvironmentVariablesCore()
        {
            // Format for GetEnvironmentStrings is:
            // (=HiddenVar=value\0 | Variable=value\0)* \0
            // See the description of Environment Blocks in MSDN's
            // CreateProcess page (null-terminated array of null-terminated strings).
            // Note the =HiddenVar's aren't always at the beginning.

            // Copy strings out, parsing into pairs and inserting into the table.
            // The first few environment variable entries start with an '='.
            // The current working directory of every drive (except for those drives
            // you haven't cd'ed into in your DOS window) are stored in the
            // environment block (as =C:=pwd) and the program's exit code is
            // as well (=ExitCode=00000000).

            var results = new LowLevelDictionary <string, string>();

            char[] block = GetEnvironmentCharArray();
            for (int i = 0; i < block.Length; i++)
            {
                int startKey = i;

                // Skip to key. On some old OS, the environment block can be corrupted.
                // Some will not have '=', so we need to check for '\0'.
                while (block[i] != '=' && block[i] != '\0')
                {
                    i++;
                }
                if (block[i] == '\0')
                {
                    continue;
                }

                // Skip over environment variables starting with '='
                if (i - startKey == 0)
                {
                    while (block[i] != 0)
                    {
                        i++;
                    }
                    continue;
                }

                string key = new string(block, startKey, i - startKey);
                i++;  // skip over '='

                int startValue = i;
                while (block[i] != 0)
                {
                    i++;                                                      // Read to end of this entry
                }
                string value = new string(block, startValue, i - startValue); // skip over 0 handled by for loop's i++

                results[key] = value;
            }
            return(results);
        }
        private LowLevelDictionary <string, QHandle> CreateCaseInsensitiveTypeDictionary()
        {
            //
            // Collect all of the *non-nested* types and type-forwards.
            //
            //   The keys are full typenames in lower-cased form.
            //   The value is a tuple containing either a TypeDefinitionHandle or TypeForwarderHandle and the associated Reader
            //      for that handle.
            //
            // We do not store nested types here. The container type is resolved and chosen first, then the nested type chosen from
            // that. If we chose the wrong container type and fail the match as a result, that's too bad. (The desktop CLR has the
            // same issue.)
            //

            LowLevelDictionary <string, QHandle> dict = new LowLevelDictionary <string, QHandle>();

            foreach (QScopeDefinition scope in AllScopes)
            {
                MetadataReader  reader          = scope.Reader;
                ScopeDefinition scopeDefinition = scope.ScopeDefinition;
                IEnumerable <NamespaceDefinitionHandle> topLevelNamespaceHandles = new NamespaceDefinitionHandle[] { scopeDefinition.RootNamespaceDefinition };
                IEnumerable <NamespaceDefinitionHandle> allNamespaceHandles      = reader.GetTransitiveNamespaces(topLevelNamespaceHandles);
                foreach (NamespaceDefinitionHandle namespaceHandle in allNamespaceHandles)
                {
                    string ns = namespaceHandle.ToNamespaceName(reader);
                    if (ns.Length != 0)
                    {
                        ns = ns + ".";
                    }
                    ns = ns.ToLowerInvariant();

                    NamespaceDefinition namespaceDefinition = namespaceHandle.GetNamespaceDefinition(reader);
                    foreach (TypeDefinitionHandle typeDefinitionHandle in namespaceDefinition.TypeDefinitions)
                    {
                        string  fullName = ns + typeDefinitionHandle.GetTypeDefinition(reader).Name.GetString(reader).ToLowerInvariant();
                        QHandle existingValue;
                        if (!dict.TryGetValue(fullName, out existingValue))
                        {
                            dict.Add(fullName, new QHandle(reader, typeDefinitionHandle));
                        }
                    }

                    foreach (TypeForwarderHandle typeForwarderHandle in namespaceDefinition.TypeForwarders)
                    {
                        string  fullName = ns + typeForwarderHandle.GetTypeForwarder(reader).Name.GetString(reader).ToLowerInvariant();
                        QHandle existingValue;
                        if (!dict.TryGetValue(fullName, out existingValue))
                        {
                            dict.Add(fullName, new QHandle(reader, typeForwarderHandle));
                        }
                    }
                }
            }

            return(dict);
        }
        private LowLevelDictionary<string, QHandle> CreateCaseInsensitiveTypeDictionary()
        {
            //
            // Collect all of the *non-nested* types and type-forwards.
            //
            //   The keys are full typenames in lower-cased form.
            //   The value is a tuple containing either a TypeDefinitionHandle or TypeForwarderHandle and the associated Reader
            //      for that handle.
            //
            // We do not store nested types here. The container type is resolved and chosen first, then the nested type chosen from
            // that. If we chose the wrong container type and fail the match as a result, that's too bad. (The desktop CLR has the
            // same issue.)
            //

            LowLevelDictionary<string, QHandle> dict = new LowLevelDictionary<string, QHandle>();

            foreach (QScopeDefinition scope in AllScopes)
            {
                MetadataReader reader = scope.Reader;
                ScopeDefinition scopeDefinition = scope.ScopeDefinition;
                IEnumerable<NamespaceDefinitionHandle> topLevelNamespaceHandles = new NamespaceDefinitionHandle[] { scopeDefinition.RootNamespaceDefinition };
                IEnumerable<NamespaceDefinitionHandle> allNamespaceHandles = reader.GetTransitiveNamespaces(topLevelNamespaceHandles);
                foreach (NamespaceDefinitionHandle namespaceHandle in allNamespaceHandles)
                {
                    string ns = namespaceHandle.ToNamespaceName(reader);
                    if (ns.Length != 0)
                        ns = ns + ".";
                    ns = ns.ToLower();

                    NamespaceDefinition namespaceDefinition = namespaceHandle.GetNamespaceDefinition(reader);
                    foreach (TypeDefinitionHandle typeDefinitionHandle in namespaceDefinition.TypeDefinitions)
                    {
                        string fullName = ns + typeDefinitionHandle.GetTypeDefinition(reader).Name.GetString(reader).ToLower();
                        QHandle existingValue;
                        if (!dict.TryGetValue(fullName, out existingValue))
                        {
                            dict.Add(fullName, new QHandle(reader, typeDefinitionHandle));
                        }
                    }

                    foreach (TypeForwarderHandle typeForwarderHandle in namespaceDefinition.TypeForwarders)
                    {
                        string fullName = ns + typeForwarderHandle.GetTypeForwarder(reader).Name.GetString(reader).ToLower();
                        QHandle existingValue;
                        if (!dict.TryGetValue(fullName, out existingValue))
                        {
                            dict.Add(fullName, new QHandle(reader, typeForwarderHandle));
                        }
                    }
                }
            }

            return dict;
        }
        private LowLevelList <ResourceInfo> GetExtractedResources(Assembly assembly)
        {
            LowLevelDictionary <String, LowLevelList <ResourceInfo> > extractedResourceDictionary = this.ExtractedResourceDictionary;
            String assemblyName = assembly.GetName().FullName;
            LowLevelList <ResourceInfo> resourceInfos;

            if (!extractedResourceDictionary.TryGetValue(assemblyName, out resourceInfos))
            {
                return(new LowLevelList <ResourceInfo>());
            }
            return(resourceInfos);
        }
Example #12
0
        public LowLevelDictionary <TKey, TValue> Clone()
        {
            var result = new LowLevelDictionary <TKey, TValue>(_numEntries);

            for (int bucket = 0; bucket < _buckets.Length; bucket++)
            {
                for (Entry entry = _buckets[bucket]; entry != null; entry = entry._next)
                {
                    result.Add(entry._key, entry._value);
                }
            }
            return(result);
        }
Example #13
0
 internal ModuleMap(ModuleInfo[] modules)
 {
     Modules             = modules;
     HandleToModuleIndex = new LowLevelDictionary <TypeManagerHandle, int>();
     for (int moduleIndex = 0; moduleIndex < Modules.Length; moduleIndex++)
     {
         // Ecma modules don't go in the reverse lookup hash because they share a module index with the system module
         if (Modules[moduleIndex].ModuleType != ModuleType.Ecma)
         {
             HandleToModuleIndex.Add(Modules[moduleIndex].Handle, moduleIndex);
         }
     }
 }
Example #14
0
            private static LowLevelDictionary <string, char> GenerateLookupTable()
            {
                // e[0] is unicode char, e[1] is '-', e[2+] is entity string

                LowLevelDictionary <string, char> lookupTable = new LowLevelDictionary <string, char>(StringComparer.Ordinal);

                foreach (string e in s_entitiesList)
                {
                    lookupTable.Add(e.Substring(2), e[0]);
                }

                return(lookupTable);
            }
Example #15
0
            internal DictionaryEnumerator(LowLevelDictionary <TKey, TValue> dict)
            {
                var entries = new DictionaryEntry[dict._numEntries];
                int dst     = 0;

                for (int bucket = 0; bucket < dict._buckets.Length; bucket++)
                {
                    for (Entry entry = dict._buckets[bucket]; entry != null; entry = entry._next)
                    {
                        entries[dst++] = new DictionaryEntry(entry._key, entry._value);
                    }
                }
                _entries = entries;
            }
        private LowLevelDictionary <string, Handle> CreateCaseInsensitiveTypeDictionary()
        {
            //
            // Collect all of the *non-nested* types and type-forwards.
            //
            //   The keys are full typenames in lower-cased form.
            //   The value is a tuple containing either a TypeDefinitionHandle or TypeForwarderHandle and the associated Reader
            //      for that handle.
            //
            // We do not store nested types here. The container type is resolved and chosen first, then the nested type chosen from
            // that. If we chose the wrong container type and fail the match as a result, that's too bad. (The desktop CLR has the
            // same issue.)
            //

            LowLevelDictionary <string, Handle> dict = new LowLevelDictionary <string, Handle>();

            foreach (TypeDefinitionHandle typeDefinitionHandle in MetadataReader.TypeDefinitions)
            {
                TypeDefinition typeDefinition = MetadataReader.GetTypeDefinition(typeDefinitionHandle);
                string         typeName       = MetadataReader.GetString(typeDefinition.Name);
                string         typeNamespace  = MetadataReader.GetString(typeDefinition.NamespaceDefinition);
                string         fullName       = typeName;
                if (!String.IsNullOrEmpty(typeNamespace))
                {
                    fullName = typeNamespace + "." + typeName;
                }
                Handle existingValue;
                if (!dict.TryGetValue(fullName, out existingValue))
                {
                    dict.Add(fullName, typeDefinitionHandle);
                }
            }

            // TODO! Implement type forwarding logic.

            /*
             *      foreach (TypeForwarderHandle typeForwarderHandle in namespaceDefinition.TypeForwarders)
             *      {
             *          string fullName = ns + typeForwarderHandle.GetTypeForwarder(reader).Name.GetString(reader).ToLowerInvariant();
             *          QHandle existingValue;
             *          if (!dict.TryGetValue(fullName, out existingValue))
             *          {
             *              dict.Add(fullName, new QHandle(reader, typeForwarderHandle));
             *          }
             *      }
             *  }*/

            return(dict);
        }
Example #17
0
        private Exception TryResolveCaseInsensitive(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, out RuntimeType result)
        {
            String fullName = this.ToString().ToLower();

            LowLevelDictionary <String, QHandle> dict = GetCaseInsensitiveTypeDictionary(currentAssembly);
            QHandle qualifiedHandle;

            if (!dict.TryGetValue(fullName, out qualifiedHandle))
            {
                result = null;
                return(new TypeLoadException(SR.Format(SR.TypeLoad_TypeNotFound, this.ToString(), currentAssembly.FullName)));
            }

            MetadataReader reader = qualifiedHandle.Reader;
            Handle         typeDefOrForwarderHandle = qualifiedHandle.Handle;

            HandleType handleType = typeDefOrForwarderHandle.HandleType;

            switch (handleType)
            {
            case HandleType.TypeDefinition:
            {
                TypeDefinitionHandle typeDefinitionHandle = typeDefOrForwarderHandle.ToTypeDefinitionHandle(reader);
                result = reflectionDomain.ResolveTypeDefinition(reader, typeDefinitionHandle);
                return(null);
            }

            case HandleType.TypeForwarder:
            {
                TypeForwarder        typeForwarder           = typeDefOrForwarderHandle.ToTypeForwarderHandle(reader).GetTypeForwarder(reader);
                ScopeReferenceHandle destinationScope        = typeForwarder.Scope;
                RuntimeAssemblyName  destinationAssemblyName = destinationScope.ToRuntimeAssemblyName(reader);
                RuntimeAssembly      destinationAssembly;
                Exception            exception = RuntimeAssembly.TryGetRuntimeAssembly(reflectionDomain, destinationAssemblyName, out destinationAssembly);
                if (exception != null)
                {
                    result = null;
                    return(exception);
                }
                return(TryResolveCaseInsensitive(reflectionDomain, destinationAssembly, out result));
            }

            default:
                throw new InvalidOperationException();
            }
        }
Example #18
0
        //
        // Returns the native layout info reader
        //
        internal unsafe NativeReader GetNativeLayoutInfoReader(IntPtr moduleHandle)
        {
            Debug.Assert(moduleHandle != IntPtr.Zero);

            if (t_moduleNativeReaders == null)
                t_moduleNativeReaders = new LowLevelDictionary<IntPtr, NativeReader>();

            NativeReader result = null;
            if (t_moduleNativeReaders.TryGetValue(moduleHandle, out result))
                return result;

            byte* pBlob;
            uint cbBlob;
            if (RuntimeAugments.FindBlob(moduleHandle, (int)ReflectionMapBlob.NativeLayoutInfo, new IntPtr(&pBlob), new IntPtr(&cbBlob)))
                result = new NativeReader(pBlob, cbBlob);

            t_moduleNativeReaders.Add(moduleHandle, result);
            return result;
        }
Example #19
0
 private static LowLevelDictionary<string, TypeFlags> InitPrimitiveTypesDictionary()
 {
     LowLevelDictionary<string, TypeFlags> result = new LowLevelDictionary<string, TypeFlags>();
     result.Add("Void", TypeFlags.Void);
     result.Add("Boolean", TypeFlags.Boolean);
     result.Add("Char", TypeFlags.Char);
     result.Add("SByte", TypeFlags.SByte);
     result.Add("Byte", TypeFlags.Byte);
     result.Add("Int16", TypeFlags.Int16);
     result.Add("UInt16", TypeFlags.UInt16);
     result.Add("Int32", TypeFlags.Int32);
     result.Add("UInt32", TypeFlags.UInt32);
     result.Add("Int64", TypeFlags.Int64);
     result.Add("UInt64", TypeFlags.UInt64);
     result.Add("IntPtr", TypeFlags.IntPtr);
     result.Add("UIntPtr", TypeFlags.UIntPtr);
     result.Add("Single", TypeFlags.Single);
     result.Add("Double", TypeFlags.Double);
     return result;
 }
Example #20
0
        private static LowLevelDictionary <string, TypeFlags> InitPrimitiveTypesDictionary()
        {
            LowLevelDictionary <string, TypeFlags> result = new LowLevelDictionary <string, TypeFlags>();

            result.Add("Void", TypeFlags.Void);
            result.Add("Boolean", TypeFlags.Boolean);
            result.Add("Char", TypeFlags.Char);
            result.Add("SByte", TypeFlags.SByte);
            result.Add("Byte", TypeFlags.Byte);
            result.Add("Int16", TypeFlags.Int16);
            result.Add("UInt16", TypeFlags.UInt16);
            result.Add("Int32", TypeFlags.Int32);
            result.Add("UInt32", TypeFlags.UInt32);
            result.Add("Int64", TypeFlags.Int64);
            result.Add("UInt64", TypeFlags.UInt64);
            result.Add("IntPtr", TypeFlags.IntPtr);
            result.Add("UIntPtr", TypeFlags.UIntPtr);
            result.Add("Single", TypeFlags.Single);
            result.Add("Double", TypeFlags.Double);
            return(result);
        }
        internal sealed override RuntimeTypeInfo GetTypeCoreCaseInsensitive(string fullName)
        {
            LowLevelDictionary <string, Handle> dict = CaseInsensitiveTypeDictionary;
            Handle typeDefOrForwarderHandle;

            if (!dict.TryGetValue(fullName.ToLowerInvariant(), out typeDefOrForwarderHandle))
            {
                return(null);
            }

            MetadataReader reader = MetadataReader;

            HandleKind handleType = typeDefOrForwarderHandle.Kind;

            switch (handleType)
            {
            case HandleKind.TypeDefinition:
            {
                TypeDefinitionHandle typeDefinitionHandle = (TypeDefinitionHandle)typeDefOrForwarderHandle;
                throw new NotImplementedException();
//                        return typeDefinitionHandle.ResolveTypeDefinition(reader);
            }

            case HandleKind.ExportedType:
            {
                throw new NotImplementedException();

                /*TypeForwarder typeForwarder = typeDefOrForwarderHandle.ToTypeForwarderHandle(reader).GetTypeForwarder(reader);
                 * ScopeReferenceHandle destinationScope = typeForwarder.Scope;
                 * RuntimeAssemblyName destinationAssemblyName = destinationScope.ToRuntimeAssemblyName(reader);
                 * RuntimeAssembly destinationAssembly = RuntimeAssembly.GetRuntimeAssemblyIfExists(destinationAssemblyName);
                 * if (destinationAssembly == null)
                 *  return null;
                 * return destinationAssembly.GetTypeCoreCaseInsensitive(fullName);*/
            }

            default:
                throw new InvalidOperationException();
            }
        }
        internal sealed override RuntimeTypeInfo GetTypeCoreCaseInsensitive(string fullName)
        {
            LowLevelDictionary <string, QHandle> dict = CaseInsensitiveTypeDictionary;
            QHandle qualifiedHandle;

            if (!dict.TryGetValue(fullName.ToLowerInvariant(), out qualifiedHandle))
            {
                return(null);
            }

            MetadataReader reader = qualifiedHandle.Reader;
            Handle         typeDefOrForwarderHandle = qualifiedHandle.Handle;

            HandleType handleType = typeDefOrForwarderHandle.HandleType;

            switch (handleType)
            {
            case HandleType.TypeDefinition:
            {
                TypeDefinitionHandle typeDefinitionHandle = typeDefOrForwarderHandle.ToTypeDefinitionHandle(reader);
                return(typeDefinitionHandle.ResolveTypeDefinition(reader));
            }

            case HandleType.TypeForwarder:
            {
                TypeForwarder        typeForwarder           = typeDefOrForwarderHandle.ToTypeForwarderHandle(reader).GetTypeForwarder(reader);
                ScopeReferenceHandle destinationScope        = typeForwarder.Scope;
                RuntimeAssemblyName  destinationAssemblyName = destinationScope.ToRuntimeAssemblyName(reader);
                RuntimeAssemblyInfo  destinationAssembly     = RuntimeAssemblyInfo.GetRuntimeAssemblyIfExists(destinationAssemblyName);
                if (destinationAssembly == null)
                {
                    return(null);
                }
                return(destinationAssembly.GetTypeCoreCaseInsensitive(fullName));
            }

            default:
                throw new InvalidOperationException();
            }
        }
Example #23
0
        private static IDictionary GetEnvironmentVariablesCore(EnvironmentVariableTarget target)
        {
            if (target == EnvironmentVariableTarget.Process)
            {
                return(GetEnvironmentVariablesCore());
            }
            else
            {
                RegistryKey baseKey;
                string      keyName;
                if (target == EnvironmentVariableTarget.Machine)
                {
                    baseKey = Registry.LocalMachine;
                    keyName = @"System\CurrentControlSet\Control\Session Manager\Environment";
                }
                else
                {
                    Debug.Assert(target == EnvironmentVariableTarget.User);
                    baseKey = Registry.CurrentUser;
                    keyName = @"Environment";
                }

                using (RegistryKey environmentKey = baseKey.OpenSubKey(keyName, writable: false))
                {
                    var table = new LowLevelDictionary <string, string>();
                    if (environmentKey != null)
                    {
                        foreach (string name in environmentKey.GetValueNames())
                        {
                            table.Add(name, environmentKey.GetValue(name, "").ToString());
                        }
                    }
                    return(table);
                }
            }
        }
        //
        // Main iterator.
        //
        private IEnumerable <CustomAttributeData> GetMatchingCustomAttributesIterator(E element, Func <Type, bool> rawPassesFilter, bool inherit)
        {
            Func <Type, bool> passesFilter =
                delegate(Type attributeType)
            {
                // Windows prohibits instantiating WinRT custom attributes. Filter them from the search as the desktop CLR does.
                TypeAttributes typeAttributes = attributeType.Attributes;
                if (0 != (typeAttributes & TypeAttributes.WindowsRuntime))
                {
                    return(false);
                }
                return(rawPassesFilter(attributeType));
            };

            LowLevelList <CustomAttributeData> immediateResults = new LowLevelList <CustomAttributeData>();

            foreach (CustomAttributeData cad in GetDeclaredCustomAttributes(element))
            {
                if (passesFilter(cad.AttributeType))
                {
                    yield return(cad);

                    immediateResults.Add(cad);
                }
            }
            if (inherit)
            {
                // Because the "inherit" parameter defaults to "true", we probably get here for a lot of elements that
                // don't actually have any inheritance chains. Try to avoid doing any unnecessary setup for the inheritance walk
                // unless we have to.
                element = GetParent(element);
                if (element != null)
                {
                    // This dictionary serves two purposes:
                    //   - Let us know which attribute types we've encountered at lower levels so we can block them from appearing twice in the results
                    //     if appropriate.
                    //
                    //   - Cache the results of retrieving the usage attribute.
                    //
                    LowLevelDictionary <TypeUnificationKey, AttributeUsageAttribute> encounteredTypes = new LowLevelDictionary <TypeUnificationKey, AttributeUsageAttribute>(11);

                    for (int i = 0; i < immediateResults.Count; i++)
                    {
                        Type attributeType = immediateResults[i].AttributeType;
                        AttributeUsageAttribute usage;
                        TypeUnificationKey      attributeTypeKey = new TypeUnificationKey(attributeType);
                        if (!encounteredTypes.TryGetValue(attributeTypeKey, out usage))
                        {
                            encounteredTypes.Add(attributeTypeKey, null);
                        }
                    }

                    do
                    {
                        foreach (CustomAttributeData cad in GetDeclaredCustomAttributes(element))
                        {
                            Type attributeType = cad.AttributeType;
                            if (!passesFilter(attributeType))
                            {
                                continue;
                            }
                            AttributeUsageAttribute usage;
                            TypeUnificationKey      attributeTypeKey = new TypeUnificationKey(attributeType);
                            if (!encounteredTypes.TryGetValue(attributeTypeKey, out usage))
                            {
                                // Type was not encountered before. Only include it if it is inheritable.
                                usage = GetAttributeUsage(attributeType);
                                encounteredTypes.Add(attributeTypeKey, usage);
                                if (usage.Inherited)
                                {
                                    yield return(cad);
                                }
                            }
                            else
                            {
                                if (usage == null)
                                {
                                    usage = GetAttributeUsage(attributeType);
                                }
                                encounteredTypes[attributeTypeKey] = usage;
                                // Type was encountered at a lower level. Only include it if its inheritable AND allowMultiple.
                                if (usage.Inherited && usage.AllowMultiple)
                                {
                                    yield return(cad);
                                }
                            }
                        }
                    }while ((element = GetParent(element)) != null);
                }
            }
        }
Example #25
0
        internal static CultureData GetCultureData(String cultureName, bool useUserOverride)
        {
            // First do a shortcut for Invariant
            if (String.IsNullOrEmpty(cultureName))
            {
                return CultureData.Invariant;
            }

            // Try the hash table first
            String hashName = AnsiToLower(useUserOverride ? cultureName : cultureName + '*');
            LowLevelDictionary<String, CultureData> tempHashTable = s_cachedCultures;
            if (tempHashTable == null)
            {
                // No table yet, make a new one
                tempHashTable = new LowLevelDictionary<String, CultureData>();
            }
            else
            {
                // Check the hash table
                bool ret;
                CultureData retVal;
                using (LockHolder.Hold(s_lock))
                {
                    ret = tempHashTable.TryGetValue(hashName, out retVal);
                }
                if (ret && retVal != null)
                {
                    return retVal;
                }
            }

            // Not found in the hash table, need to see if we can build one that works for us
            CultureData culture = CreateCultureData(cultureName, useUserOverride);
            if (culture == null)
            {
                return null;
            }

            // Found one, add it to the cache
            using (LockHolder.Hold(s_lock))
            {
                tempHashTable[hashName] = culture;
            }

            // Copy the hashtable to the corresponding member variables.  This will potentially overwrite
            // new tables simultaneously created by a new thread, but maximizes thread safety.
            s_cachedCultures = tempHashTable;

            return culture;
        }
Example #26
0
        internal static CultureData GetCultureDataForRegion(String cultureName, bool useUserOverride)
        {
            // First do a shortcut for Invariant
            if (String.IsNullOrEmpty(cultureName))
            {
                return CultureData.Invariant;
            }

            //
            // First check if GetCultureData() can find it (ie: its a real culture)
            //
            CultureData retVal = GetCultureData(cultureName, useUserOverride);
            if (retVal != null && (retVal.IsNeutralCulture == false)) return retVal;

            //
            // Not a specific culture, perhaps it's region-only name
            // (Remember this isn't a core clr path where that's not supported)
            //

            // If it was neutral remember that so that RegionInfo() can throw the right exception
            CultureData neutral = retVal;

            // Try the hash table next
            String hashName = AnsiToLower(useUserOverride ? cultureName : cultureName + '*');
            LowLevelDictionary<String, CultureData> tempHashTable = s_cachedRegions;
            if (tempHashTable == null)
            {
                // No table yet, make a new one
                tempHashTable = new LowLevelDictionary<String, CultureData>();
            }
            else
            {
                // Check the hash table
                using (LockHolder.Hold(s_lock))
                {
                    tempHashTable.TryGetValue(hashName, out retVal);
                }
                if (retVal != null)
                {
                    return retVal;
                }
            }

            //
            // Not found in the hash table, look it up the hard way
            //

            // If not a valid mapping from the registry we'll have to try the hard coded table
            if (retVal == null || (retVal.IsNeutralCulture == true))
            {
                // Not a valid mapping, try the hard coded table
                string name;
                if (RegionNames.TryGetValue(cultureName, out name))
                {
                    // Make sure we can get culture data for it
                    retVal = GetCultureData(name, useUserOverride);
                }
            }

            // If not found in the hard coded table we'll have to find a culture that works for us
            if (retVal == null || (retVal.IsNeutralCulture == true))
            {
                retVal = GetCultureDataFromRegionName(cultureName);
            }

            // If we found one we can use, then cache it for next time
            if (retVal != null && (retVal.IsNeutralCulture == false))
            {
                // first add it to the cache
                using (LockHolder.Hold(s_lock))
                {
                    tempHashTable[hashName] = retVal;
                }

                // Copy the hashtable to the corresponding member variables.  This will potentially overwrite
                // new tables simultaneously created by a new thread, but maximizes thread safety.
                s_cachedRegions = tempHashTable;
            }
            else
            {
                // Unable to find a matching culture/region, return null or neutral
                // (regionInfo throws a more specific exception on neutrals)
                retVal = neutral;
            }

            // Return the found culture to use, null, or the neutral culture.
            return retVal;
        }
Example #27
0
 internal ModuleMap(ModuleInfo[] modules)
 {
     Modules = modules;
     HandleToModuleIndex = new LowLevelDictionary<IntPtr, int>();
     for (int moduleIndex = 0; moduleIndex < Modules.Length; moduleIndex++)
     {
         HandleToModuleIndex.Add(Modules[moduleIndex].Handle, moduleIndex);
     }
 }
Example #28
0
        private static IDictionary GetEnvironmentVariablesCore(EnvironmentVariableTarget target)
        {
            if (target == EnvironmentVariableTarget.Process)
            {
                return GetEnvironmentVariablesCore();
            }
            else
            {
                RegistryKey baseKey;
                string keyName;
                if (target == EnvironmentVariableTarget.Machine)
                {
                    baseKey = Registry.LocalMachine;
                    keyName = @"System\CurrentControlSet\Control\Session Manager\Environment";
                }
                else
                {
                    Debug.Assert(target == EnvironmentVariableTarget.User);
                    baseKey = Registry.CurrentUser;
                    keyName = @"Environment";
                }

                using (RegistryKey environmentKey = baseKey.OpenSubKey(keyName, writable: false))
                {
                    var table = new LowLevelDictionary<string, string>();
                    if (environmentKey != null)
                    {
                        foreach (string name in environmentKey.GetValueNames())
                        {
                            table.Add(name, environmentKey.GetValue(name, "").ToString());
                        }
                    }
                    return table;
                }
            }
        }
Example #29
0
        // Helper function both both overloads of GetCachedReadOnlyCulture.  If lcid is 0, we use the name.
        // If lcid is -1, use the altName and create one of those special SQL cultures.
        internal static CultureInfo GetCultureInfoHelper(int lcid, string name, string altName)
        {
            // retval is our return value.
            CultureInfo retval;

            // Temporary hashtable for the names.
            LowLevelDictionary<string, CultureInfo> tempNameHT = s_NameCachedCultures;

            if (name != null)
            {
                name = CultureData.AnsiToLower(name);
            }
            
            if (altName != null)
            {
                altName = CultureData.AnsiToLower(altName);
            }

            // We expect the same result for both hashtables, but will test individually for added safety.
            if (tempNameHT == null)
            {
                tempNameHT = new LowLevelDictionary<string, CultureInfo>();
            }
            else
            {
                // If we are called by name, check if the object exists in the hashtable.  If so, return it.
                if (lcid == -1 || lcid == 0)
                {
                    bool ret;
                    using (LockHolder.Hold(s_lock))
                    {
                        ret = tempNameHT.TryGetValue(lcid == 0 ? name : name + '\xfffd' + altName, out retval);
                    }

                    if (ret && retval != null)
                    {
                        return retval;
                    }
                }
            }

            // Next, the Lcid table.
            LowLevelDictionary<int, CultureInfo> tempLcidHT = s_LcidCachedCultures;

            if (tempLcidHT == null)
            {
                // Case insensitive is not an issue here, save the constructor call.
                tempLcidHT = new LowLevelDictionary<int, CultureInfo>();
            }
            else
            {
                // If we were called by Lcid, check if the object exists in the table.  If so, return it.
                if (lcid > 0)
                {
                    bool ret;
                    using (LockHolder.Hold(s_lock))
                    {
                        ret = tempLcidHT.TryGetValue(lcid, out retval);
                    }
                    if (ret && retval != null)
                    {
                        return retval;
                    }
                }
            }

            // We now have two temporary hashtables and the desired object was not found.
            // We'll construct it.  We catch any exceptions from the constructor call and return null.
            try
            {
                switch (lcid)
                {
                    case -1:
                        // call the private constructor
                        retval = new CultureInfo(name, altName);
                        break;

                    case 0:
                        retval = new CultureInfo(name, false);
                        break;

                    default:
                        retval = new CultureInfo(lcid, false);
                        break;
                }
            }
            catch (ArgumentException)
            {
                return null;
            }

            // Set it to read-only
            retval._isReadOnly = true;

            if (lcid == -1)
            {
                using (LockHolder.Hold(s_lock))
                {
                    // This new culture will be added only to the name hash table.
                    tempNameHT[name + '\xfffd' + altName] = retval;
                }
                // when lcid == -1 then TextInfo object is already get created and we need to set it as read only.
                retval.TextInfo.SetReadOnlyState(true);
            }
            else if (lcid == 0)
            {
                // Remember our name (as constructed).  Do NOT use alternate sort name versions because
                // we have internal state representing the sort.  (So someone would get the wrong cached version)
                string newName = CultureData.AnsiToLower(retval.m_name);
                
                // We add this new culture info object to both tables.
                using (LockHolder.Hold(s_lock))
                {
                    tempNameHT[newName] = retval;
                }
            } 
            else
            {
                using (LockHolder.Hold(s_lock))
                {
                    tempLcidHT[lcid] = retval;
                }
            }

            // Copy the two hashtables to the corresponding member variables.  This will potentially overwrite
            // new tables simultaneously created by a new thread, but maximizes thread safety.
            if (-1 != lcid)
            {
                // Only when we modify the lcid hash table, is there a need to overwrite.
                s_LcidCachedCultures = tempLcidHT;
            }

            s_NameCachedCultures = tempNameHT;

            // Finally, return our new CultureInfo object.
            return retval;
        }
Example #30
0
        public void ClearCachedData()
        {
            s_userDefaultCulture = null;

            RegionInfo.s_currentRegionInfo = null;
            #pragma warning disable 0618 // disable the obsolete warning 
            //TimeZone.ResetTimeZone();
            #pragma warning restore 0618
            TimeZoneInfo.ClearCachedData();
            s_LcidCachedCultures = null;
            s_NameCachedCultures = null;

            CultureData.ClearCachedData();
        }
Example #31
0
 //schemeStr must be in lower case!
 internal static UriParser FindOrFetchAsUnknownV1Syntax(string lwrCaseScheme)
 {
     // check may be other thread just added one
     UriParser syntax = null;
     s_table.TryGetValue(lwrCaseScheme, out syntax);
     if (syntax != null)
     {
         return syntax;
     }
     s_tempTable.TryGetValue(lwrCaseScheme, out syntax);
     if (syntax != null)
     {
         return syntax;
     }
     lock (s_table)
     {
         if (s_tempTable.Count >= c_MaxCapacity)
         {
             s_tempTable = new LowLevelDictionary<string, UriParser>(c_InitialTableSize);
         }
         syntax = new BuiltInUriParser(lwrCaseScheme, NoDefaultPort, UnknownV1SyntaxFlags);
         s_tempTable[lwrCaseScheme] = syntax;
         return syntax;
     }
 }
Example #32
0
            public static unsafe IntPtr Get(RuntimeTypeHandle constraintType, RuntimeTypeHandle constrainedMethodType, int constrainedMethodSlot, bool directConstrainedCall = false)
            {
                LowLevelDictionary <RuntimeTypeHandle, LowLevelList <IntPtr> > nonGenericConstrainedCallDescsDirect = directConstrainedCall ? s_nonGenericConstrainedCallDescsDirect : s_nonGenericConstrainedCallDescs;

                lock (nonGenericConstrainedCallDescsDirect)
                {
                    // Get list of constrained call descs associated with a given type
                    LowLevelList <IntPtr> associatedCallDescs;
                    if (!nonGenericConstrainedCallDescsDirect.TryGetValue(constraintType, out associatedCallDescs))
                    {
                        associatedCallDescs = new LowLevelList <IntPtr>();
                        nonGenericConstrainedCallDescsDirect.Add(constraintType, associatedCallDescs);
                    }

                    // Perform linear scan of associated call descs to see if one matches
                    for (int i = 0; i < associatedCallDescs.Count; i++)
                    {
                        NonGenericConstrainedCallDesc *callDesc = (NonGenericConstrainedCallDesc *)associatedCallDescs[i];

                        Debug.Assert(constraintType.Equals(callDesc->_constraintType));

                        if (callDesc->_constrainedMethodSlot != constrainedMethodSlot)
                        {
                            continue;
                        }

                        if (!callDesc->_constrainedMethodType.Equals(constrainedMethodType))
                        {
                            continue;
                        }

                        // Found matching entry.
                        return(associatedCallDescs[i]);
                    }

                    // Did not find match, allocate a new one and add it to the lookup list
                    IntPtr newCallDescPtr = MemoryHelpers.AllocateMemory(sizeof(NonGenericConstrainedCallDesc));
                    NonGenericConstrainedCallDesc *newCallDesc = (NonGenericConstrainedCallDesc *)newCallDescPtr;
                    newCallDesc->_exactTarget = IntPtr.Zero;
                    if (directConstrainedCall)
                    {
                        newCallDesc->_lookupFunc = RuntimeAugments.GetUniversalTransitionThunk();
                    }
                    else
                    {
                        if (RuntimeAugments.IsValueType(constraintType))
                        {
                            newCallDesc->_lookupFunc = s_resolveCallOnValueTypeFuncPtr;
                        }
                        else
                        {
                            newCallDesc->_lookupFunc = s_resolveCallOnReferenceTypeFuncPtr;
                        }
                    }


                    newCallDesc->_constraintType        = constraintType;
                    newCallDesc->_constrainedMethodSlot = constrainedMethodSlot;
                    newCallDesc->_constrainedMethodType = constrainedMethodType;

                    associatedCallDescs.Add(newCallDescPtr);

                    return(newCallDescPtr);
                }
            }
Example #33
0
        //
        // Returns the native layout info reader
        //
        internal unsafe NativeReader GetNativeLayoutInfoReader(IntPtr moduleHandle)
        {
            Debug.Assert(moduleHandle != IntPtr.Zero);

            if (t_moduleNativeReaders == null)
                t_moduleNativeReaders = new LowLevelDictionary<IntPtr, NativeReader>();

            NativeReader result = null;
            if (t_moduleNativeReaders.TryGetValue(moduleHandle, out result))
                return result;

            byte* pBlob;
            uint cbBlob;
            if (RuntimeAugments.FindBlob(moduleHandle, (int)ReflectionMapBlob.NativeLayoutInfo, new IntPtr(&pBlob), new IntPtr(&cbBlob)))
                result = new NativeReader(pBlob, cbBlob);

            t_moduleNativeReaders.Add(moduleHandle, result);
            return result;
        }
Example #34
0
            private static LowLevelDictionary<string, char> GenerateLookupTable()
            {
                // e[0] is unicode char, e[1] is '-', e[2+] is entity string

                LowLevelDictionary<string, char> lookupTable = new LowLevelDictionary<string, char>(StringComparer.Ordinal);
                foreach (string e in s_entitiesList)
                {
                    lookupTable.Add(e.Substring(2), e[0]);
                }

                return lookupTable;
            }
Example #35
0
        // Helper function both both overloads of GetCachedReadOnlyCulture.
        internal static CultureInfo GetCultureInfoHelper(string name)
        {
            // There is a race condition in this code with the side effect that the second thread's value
            // clobbers the first in the dictionary. This is an acceptable race since the CultureInfo objects
            // are content equal (but not reference equal). Since we make no guarantees there, this race is
            // acceptable.

            // retval is our return value.
            CultureInfo retval;

            if (name == null)
            {
                return null;
            }

            // Temporary hashtable for the names.
            LowLevelDictionary<string, CultureInfo> tempNameHT = s_NameCachedCultures;

            name = CultureData.AnsiToLower(name);

            // We expect the same result for both hashtables, but will test individually for added safety.
            if (tempNameHT == null)
            {
                tempNameHT = new LowLevelDictionary<string, CultureInfo>();
            }
            else
            {
                bool ret;
                using (LockHolder.Hold(s_lock))
                {
                    ret = tempNameHT.TryGetValue(name, out retval);
                }

                if (ret && retval != null)
                {
                    return retval;
                }
            }
            try
            {
                retval = new CultureInfo(name, false);
            }
            catch (ArgumentException)
            {
                return null;
            }

            // Set it to read-only
            retval._isReadOnly = true;

            // Remember our name (as constructed).  Do NOT use alternate sort name versions because
            // we have internal state representing the sort.  (So someone would get the wrong cached version)
            string newName = CultureData.AnsiToLower(retval.m_name);

            // We add this new culture info object to both tables.
            using (LockHolder.Hold(s_lock))
            {
                tempNameHT[newName] = retval;
            }

            s_NameCachedCultures = tempNameHT;

            // Finally, return our new CultureInfo object.
            return retval;
        }
Example #36
0
        // Helper function both both overloads of GetCachedReadOnlyCulture.
        internal static CultureInfo GetCultureInfoHelper(string name)
        {
            // There is a race condition in this code with the side effect that the second thread's value
            // clobbers the first in the dictionary. This is an acceptable race since the CultureInfo objects
            // are content equal (but not reference equal). Since we make no guarantees there, this race is
            // acceptable.

            // retval is our return value.
            CultureInfo retval;

            if (name == null)
            {
                return(null);
            }

            // Temporary hashtable for the names.
            LowLevelDictionary <string, CultureInfo> tempNameHT = s_NameCachedCultures;

            name = CultureData.AnsiToLower(name);

            // We expect the same result for both hashtables, but will test individually for added safety.
            if (tempNameHT == null)
            {
                tempNameHT = new LowLevelDictionary <string, CultureInfo>();
            }
            else
            {
                bool ret;
                lock (s_lock)
                {
                    ret = tempNameHT.TryGetValue(name, out retval);
                }

                if (ret && retval != null)
                {
                    return(retval);
                }
            }
            try
            {
                retval = new CultureInfo(name, false);
            }
            catch (ArgumentException)
            {
                return(null);
            }

            // Set it to read-only
            retval._isReadOnly = true;

            // Remember our name (as constructed).  Do NOT use alternate sort name versions because
            // we have internal state representing the sort.  (So someone would get the wrong cached version)
            string newName = CultureData.AnsiToLower(retval.m_name);

            // We add this new culture info object to both tables.
            lock (s_lock)
            {
                tempNameHT[newName] = retval;
            }

            s_NameCachedCultures = tempNameHT;

            // Finally, return our new CultureInfo object.
            return(retval);
        }
Example #37
0
 // Clear our internal caches
 internal static void ClearCachedData()
 {
     s_cachedCultures = null;
     s_cachedRegions = null;
 }
Example #38
0
        private static IDictionary GetEnvironmentVariablesCore()
        {
            // Format for GetEnvironmentStrings is:
            // (=HiddenVar=value\0 | Variable=value\0)* \0
            // See the description of Environment Blocks in MSDN's
            // CreateProcess page (null-terminated array of null-terminated strings).
            // Note the =HiddenVar's aren't always at the beginning.

            // Copy strings out, parsing into pairs and inserting into the table.
            // The first few environment variable entries start with an '='.
            // The current working directory of every drive (except for those drives
            // you haven't cd'ed into in your DOS window) are stored in the 
            // environment block (as =C:=pwd) and the program's exit code is 
            // as well (=ExitCode=00000000).

            var results = new LowLevelDictionary<string, string>();
            char[] block = GetEnvironmentCharArray();
            for (int i = 0; i < block.Length; i++)
            {
                int startKey = i;

                // Skip to key. On some old OS, the environment block can be corrupted. 
                // Some will not have '=', so we need to check for '\0'. 
                while (block[i] != '=' && block[i] != '\0') i++;
                if (block[i] == '\0') continue;

                // Skip over environment variables starting with '='
                if (i - startKey == 0)
                {
                    while (block[i] != 0) i++;
                    continue;
                }

                string key = new string(block, startKey, i - startKey);
                i++;  // skip over '='

                int startValue = i;
                while (block[i] != 0) i++; // Read to end of this entry 
                string value = new string(block, startValue, i - startValue); // skip over 0 handled by for loop's i++

                results[key] = value;
            }
            return results;
        }
Example #39
0
        static UriParser()
        {
            s_table = new LowLevelDictionary<string, UriParser>(c_InitialTableSize);
            s_tempTable = new LowLevelDictionary<string, UriParser>(c_InitialTableSize);

            //Now we will call for the instance constructors that will interrupt this static one.

            // Below we simulate calls into FetchSyntax() but avoid using lock() and other things redundant for a .cctor

            HttpUri = new BuiltInUriParser("http", 80, HttpSyntaxFlags);
            s_table[HttpUri.SchemeName] = HttpUri;                   //HTTP

            HttpsUri = new BuiltInUriParser("https", 443, HttpUri._flags);
            s_table[HttpsUri.SchemeName] = HttpsUri;                  //HTTPS cloned from HTTP

            WsUri = new BuiltInUriParser("ws", 80, HttpSyntaxFlags);
            s_table[WsUri.SchemeName] = WsUri;                   // WebSockets

            WssUri = new BuiltInUriParser("wss", 443, HttpSyntaxFlags);
            s_table[WssUri.SchemeName] = WssUri;                  // Secure WebSockets

            FtpUri = new BuiltInUriParser("ftp", 21, FtpSyntaxFlags);
            s_table[FtpUri.SchemeName] = FtpUri;                    //FTP

            FileUri = new BuiltInUriParser("file", NoDefaultPort, s_fileSyntaxFlags);
            s_table[FileUri.SchemeName] = FileUri;                   //FILE

            GopherUri = new BuiltInUriParser("gopher", 70, GopherSyntaxFlags);
            s_table[GopherUri.SchemeName] = GopherUri;                 //GOPHER

            NntpUri = new BuiltInUriParser("nntp", 119, NntpSyntaxFlags);
            s_table[NntpUri.SchemeName] = NntpUri;                   //NNTP

            NewsUri = new BuiltInUriParser("news", NoDefaultPort, NewsSyntaxFlags);
            s_table[NewsUri.SchemeName] = NewsUri;                   //NEWS

            MailToUri = new BuiltInUriParser("mailto", 25, MailtoSyntaxFlags);
            s_table[MailToUri.SchemeName] = MailToUri;                 //MAILTO

            UuidUri = new BuiltInUriParser("uuid", NoDefaultPort, NewsUri._flags);
            s_table[UuidUri.SchemeName] = UuidUri;                   //UUID cloned from NEWS

            TelnetUri = new BuiltInUriParser("telnet", 23, TelnetSyntaxFlags);
            s_table[TelnetUri.SchemeName] = TelnetUri;                 //TELNET

            LdapUri = new BuiltInUriParser("ldap", 389, LdapSyntaxFlags);
            s_table[LdapUri.SchemeName] = LdapUri;                   //LDAP

            NetTcpUri = new BuiltInUriParser("net.tcp", 808, NetTcpSyntaxFlags);
            s_table[NetTcpUri.SchemeName] = NetTcpUri;

            NetPipeUri = new BuiltInUriParser("net.pipe", NoDefaultPort, NetPipeSyntaxFlags);
            s_table[NetPipeUri.SchemeName] = NetPipeUri;

            VsMacrosUri = new BuiltInUriParser("vsmacros", NoDefaultPort, VsmacrosSyntaxFlags);
            s_table[VsMacrosUri.SchemeName] = VsMacrosUri;               //VSMACROS
        }