當前位置: 首頁>>代碼示例>>C#>>正文


C# RuleValidation.GetTypeProvider方法代碼示例

本文整理匯總了C#中System.Workflow.Activities.Rules.RuleValidation.GetTypeProvider方法的典型用法代碼示例。如果您正苦於以下問題:C# RuleValidation.GetTypeProvider方法的具體用法?C# RuleValidation.GetTypeProvider怎麽用?C# RuleValidation.GetTypeProvider使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Workflow.Activities.Rules.RuleValidation的用法示例。


在下文中一共展示了RuleValidation.GetTypeProvider方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Parser

        internal Parser(RuleValidation validation)
        {
            this.validation = validation;

            Type[] allTypes = null;

            ITypeProvider provider = validation.GetTypeProvider();
            if (provider == null)
            {
                // No type provider.  The only type we know about is "This".
                //allTypes = new Type[] { validation.ThisType };
                try
                {
                    allTypes = validation.ThisType.Assembly.GetTypes();
                }
                catch (ReflectionTypeLoadException e)
                {
                    // problems loading all the types, take what we can get
                    allTypes = e.Types;
                }
            }
            else
            {
                allTypes = provider.GetTypes();
            }


            // Go through all the known types and gather namespace information.
            // Also note which types are uniquely named; these can be looked up without
            // qualification.

            Dictionary<string, NamespaceSymbol> rootNamespaces = new Dictionary<string, NamespaceSymbol>();
            Dictionary<string, object> duplicateNames = new Dictionary<string, object>();
            NamespaceSymbol nsSym = null;
            Symbol existingSymbol = null;
            NamespaceSymbol globalNS = null; // In case we encounter a type without a namespace

            for (int i = 0; i < allTypes.Length; ++i)
            {
                Type type = allTypes[i];

                // If we got a ReflectionTypeLoadException, some types may be null, so skip them
                if (type == null)
                    continue;

                // Skip types that are not visible.
                // (If type.Assembly == null, we assume it's a design-time type, and let it through.)
                if (type.IsNotPublic && (type.Assembly != null && type.Assembly != validation.ThisType.Assembly))
                    continue;

                // Skip nested types.
                if (type.IsNested)
                    continue;

                // Add the namespaces.
                string typeNamespace = type.Namespace;
                if (string.IsNullOrEmpty(typeNamespace))
                {
                    if (globalNS == null)
                    {
                        globalNS = new NamespaceSymbol();
                        rootNamespaces.Add("", globalNS);
                    }

                    nsSym = globalNS;
                }
                else
                {
                    string[] namespaces = typeNamespace.Split('.');
                    System.Diagnostics.Debug.Assert(namespaces.Length > 0);

                    if (!rootNamespaces.TryGetValue(namespaces[0], out nsSym))
                    {
                        nsSym = new NamespaceSymbol(namespaces[0], null);
                        rootNamespaces.Add(namespaces[0], nsSym);

                        // Also add the root namespace to the global unique symbol dictionary.
                        // Replace anything that was there.  I.e., we had MS.Test.Foo,
                        // and this current one is Test.Bar.  It wins.
                        globalUniqueSymbols[namespaces[0]] = nsSym;
                    }

                    if (namespaces.Length > 1)
                    {
                        for (int j = 1; j < namespaces.Length; ++j)
                        {
                            nsSym = nsSym.AddNamespace(namespaces[j]);

                            if (globalUniqueSymbols.TryGetValue(namespaces[j], out existingSymbol))
                            {
                                // This sub-namespace is already in global unique symbols.

                                // If it's the same one as what's there, no problem.
                                NamespaceSymbol existingNS = existingSymbol as NamespaceSymbol;
                                if (existingNS != null && existingNS.Parent != nsSym.Parent)
                                {
                                    // It was different.  If the levels are the same, it's a duplicate name.
                                    if (existingNS.Level == nsSym.Level)
                                    {
                                        duplicateNames[namespaces[j]] = null;
//.........這裏部分代碼省略.........
開發者ID:iskiselev,項目名稱:JSIL.NetFramework,代碼行數:101,代碼來源:Parser.cs

示例2: Parser

 internal Parser(RuleValidation validation)
 {
     this.validation = validation;
     Type[] types = null;
     ITypeProvider typeProvider = validation.GetTypeProvider();
     if (typeProvider == null)
     {
         try
         {
             types = validation.ThisType.Assembly.GetTypes();
         }
         catch (ReflectionTypeLoadException exception)
         {
             types = exception.Types;
         }
     }
     else
     {
         types = typeProvider.GetTypes();
     }
     Dictionary<string, NamespaceSymbol> dictionary = new Dictionary<string, NamespaceSymbol>();
     Dictionary<string, object> dictionary2 = new Dictionary<string, object>();
     NamespaceSymbol symbol = null;
     Symbol symbol2 = null;
     NamespaceSymbol symbol3 = null;
     for (int i = 0; i < types.Length; i++)
     {
         Type type = types[i];
         if (((type != null) && ((!type.IsNotPublic || (type.Assembly == null)) || (type.Assembly == validation.ThisType.Assembly))) && !type.IsNested)
         {
             string str = type.Namespace;
             if (string.IsNullOrEmpty(str))
             {
                 if (symbol3 == null)
                 {
                     symbol3 = new NamespaceSymbol();
                     dictionary.Add("", symbol3);
                 }
                 symbol = symbol3;
             }
             else
             {
                 string[] strArray = str.Split(new char[] { '.' });
                 if (!dictionary.TryGetValue(strArray[0], out symbol))
                 {
                     symbol = new NamespaceSymbol(strArray[0], null);
                     dictionary.Add(strArray[0], symbol);
                     this.globalUniqueSymbols[strArray[0]] = symbol;
                 }
                 if (strArray.Length > 1)
                 {
                     for (int j = 1; j < strArray.Length; j++)
                     {
                         symbol = symbol.AddNamespace(strArray[j]);
                         if (this.globalUniqueSymbols.TryGetValue(strArray[j], out symbol2))
                         {
                             NamespaceSymbol symbol4 = symbol2 as NamespaceSymbol;
                             if ((symbol4 != null) && (symbol4.Parent != symbol.Parent))
                             {
                                 if (symbol4.Level == symbol.Level)
                                 {
                                     dictionary2[strArray[j]] = null;
                                 }
                                 else if (symbol.Level < symbol4.Level)
                                 {
                                     this.globalUniqueSymbols[strArray[j]] = symbol;
                                 }
                             }
                         }
                         else
                         {
                             this.globalUniqueSymbols.Add(strArray[j], symbol);
                         }
                     }
                 }
             }
             symbol.AddType(type);
         }
     }
     foreach (string str2 in dictionary2.Keys)
     {
         this.globalUniqueSymbols.Remove(str2);
     }
     Queue<NamespaceSymbol> queue = new Queue<NamespaceSymbol>();
     foreach (NamespaceSymbol symbol5 in dictionary.Values)
     {
         queue.Enqueue(symbol5);
     }
     dictionary2.Clear();
     while (queue.Count > 0)
     {
         foreach (Symbol symbol6 in queue.Dequeue().NestedSymbols.Values)
         {
             NamespaceSymbol item = symbol6 as NamespaceSymbol;
             if (item != null)
             {
                 queue.Enqueue(item);
             }
             else
             {
//.........這裏部分代碼省略.........
開發者ID:pritesh-mandowara-sp,項目名稱:DecompliedDotNetLibraries,代碼行數:101,代碼來源:Parser.cs


注:本文中的System.Workflow.Activities.Rules.RuleValidation.GetTypeProvider方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。