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


C# Type.GetNestedTypes方法代碼示例

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


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

示例1: InitialiseType

        private static void InitialiseType(Type type)
        {
            foreach (var property in type.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
            {
                var attribute = property.GetCustomAttributes(false).OfType<KeyAttribute>().FirstOrDefault();
                if (attribute == null)
                {
                    continue;
                }

                var item = _database.GetItem(ConfigurationManager.AppSettings.Get(attribute.Key));
                if (item == null)
                {
                    Sitecore.Diagnostics.Log.Warn("Could not load item ID for property '{0}' on class '{1}'.".FormatWith(property.Name, type.FullName), new object());
                    continue;
                }

                property.SetValue(null, item.ID.Guid, new object[0]);
            }

            foreach (var nestedType in type.GetNestedTypes(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
            {
                InitialiseType(nestedType);
            }
        }
開發者ID:ravisilva,項目名稱:Regger-Online,代碼行數:25,代碼來源:ItemIds.cs

示例2: Initialize

        private static void Initialize(ILocalTextRegistry registry, Type type, string languageID, string prefix)
        {
            var provider = registry ?? Dependency.Resolve<ILocalTextRegistry>();
            foreach (var member in type.GetMembers(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly))
            {
                var fi = member as FieldInfo;
                if (fi != null &&
                    fi.FieldType == typeof(LocalText))
                {
                    var value = fi.GetValue(null) as LocalText;
                    if (value != null)
                    {
                        var initialized = value as InitializedLocalText;
                        if (initialized != null)
                        {
                            provider.Add(languageID, initialized.Key, initialized.InitialText);
                        }
                        else
                        {
                            provider.Add(languageID, prefix + fi.Name, value.Key);
                            fi.SetValue(null, new InitializedLocalText(prefix + fi.Name, value.Key));
                        }
                    }
                }
            }

            foreach (var nested in type.GetNestedTypes(BindingFlags.Public | BindingFlags.DeclaredOnly))
            {
                var name = nested.Name;
                if (name.EndsWith("_"))
                    name = name.Substring(0, name.Length - 1);

                Initialize(registry, nested, languageID, prefix + name + ".");
            }
        }
開發者ID:volkanceylan,項目名稱:Serenity,代碼行數:35,代碼來源:NestedLocalTextRegistration.cs

示例3: GetTypesX

        private static void GetTypesX(Type aType, Dictionary<string, Type> addTo)
        {
            var assemblyQualifiedName2 = aType.IdString();
            if (addTo.ContainsKey(assemblyQualifiedName2))
                return;
            addTo.Add(assemblyQualifiedName2, aType);
            var tmp = aType.GetNestedTypes();
            if (tmp.Length != 0)
            {
                foreach (var qType in tmp)
                    addTo[qType.IdString()] = qType;
                foreach (var i in tmp)
                    GetTypesX(i, addTo);
            }
            var mm =
                aType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
            var mm1 = mm.Where(i => i.IsGenericMethod).ToArray();
            if (!mm1.Any()) return;

            var enumerableTypes = from i in mm1
                let types = i.GetGenericArguments()
                from type in types
                select type;
            foreach (var type in enumerableTypes)
                GetTypesX(type, addTo);
        }
開發者ID:exaphaser,項目名稱:cs2php,代碼行數:26,代碼來源:CompileState.cs

示例4: RegisterMapper

        public RegisterMapper(Type peripheralType)
        {
            var types = peripheralType.GetNestedTypes(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            var interestingEnums = new List<Type>();

            var enumsWithAttribute = types.Where(t => t.GetCustomAttributes(false).Any(x => x is RegistersDescriptionAttribute));
            if (enumsWithAttribute != null)
            {
                interestingEnums.AddRange(enumsWithAttribute);
            }
            interestingEnums.AddRange(types.Where(t => t.BaseType == typeof(Enum) && t.Name.IndexOf("register", StringComparison.CurrentCultureIgnoreCase) != -1));

            foreach (var type in interestingEnums)
            {
                foreach (var value in type.GetEnumValues())
                {
                    var l = Convert.ToInt64(value);
                    var s = Enum.GetName(type, value);

                    if (!map.ContainsKey(l))
                    {
                        map.Add(l, s);
                    }
                }
            }
        }
開發者ID:rte-se,項目名稱:emul8,代碼行數:26,代碼來源:RegisterMapper.cs

示例5: GetTypeAndNestedTypes

        IEnumerable<Type> GetTypeAndNestedTypes(Type type)
        {
            yield return type;

            foreach (var nested in type.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic).SelectMany(GetTypeAndNestedTypes))
                yield return nested;
        }
開發者ID:JakeGinnivan,項目名稱:fixie,代碼行數:7,代碼來源:TdNetRunner.cs

示例6: AddConstantsValue

        private static void AddConstantsValue(string prefix, Type type)
        {
            Type[] nested = type.GetNestedTypes();

            foreach (Type nType in nested)
            {
                string nPrefix = nType.Name;
                if (!string.IsNullOrEmpty(prefix))
                {
                    nPrefix = string.Format("{0}.{1}", prefix, nType.Name);
                }

                AddConstantsValue(nPrefix, nType);
            }

            FieldInfo[] fieldInfos = type.GetFields(BindingFlags.Public |
                                                          BindingFlags.Static);

            foreach (FieldInfo field in fieldInfos)
            {
                object value = field.GetValue(null);
                string key = field.Name;

                if (!string.IsNullOrEmpty(prefix))
                {
                    key = string.Format("{0}.{1}", prefix, field.Name);
                }

                keyValues.Add(key, value);
            }
        }
開發者ID:ratnazone,項目名稱:ratna,代碼行數:31,代碼來源:ConstantsExpressionBuilder.cs

示例7: CheckDllImports

        // Look for methods on this type that are DllImports.
        private void CheckDllImports(Type type)
        {
            foreach (var m in type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
            {
                foreach(object attr in m.GetCustomAttributes(typeof(DllImportAttribute), false))
                {
                    var importAttribute = (DllImportAttribute) attr;
                    
                    // We want to use the Unicode version of the Win32 function whenever possible.
                    // Unfortunately, the default in C# is to use ANSI strings. If CharSet is not
                    //  Unicode, verify that strings are not used for parameters or return values.
                    // https://msdn.microsoft.com/en-us/library/vstudio/system.runtime.interopservices.charset(v=vs.100).aspx
                    if (importAttribute.CharSet != CharSet.Unicode)
                        AssertNoStrings(m);

                    // Check that all structs have the correct StructLayout attribute -- either
                    //  explicit or sequential.
                    // Todo: make this work with struct references, too.
                    // Note that it's not possible to have memory corruption by using LayoutKind.Auto;
                    //  a run-time exception will be thrown in this case.
                    // To completely test a particular struct that will be marshaled, put the test in
                    //  NativeTestHelpers.
                    AssertLayoutKindOnParams(m);
                }
            }

            foreach (var nestedType in type.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic))
                CheckDllImports(nestedType);
        }
開發者ID:sbambach,項目名稱:ATF,代碼行數:30,代碼來源:TestDllImports.cs

示例8: CreateGroupFromClass

        private static GroupViewModel CreateGroupFromClass(GroupViewModel parent, Type classType, Func<ComfoBoxClient> clientFunc)
        {
            var group = new GroupViewModel(classType.Name);
            parent.Add(group);
            foreach (var subType in classType.GetNestedTypes())
            {
                CreateGroupFromClass(group, subType, clientFunc);
            }

            var instance = classType.CreateInstance();

            foreach (var propertyInfo in classType.Properties(Flags.Default))
            {
                var propertyValue = instance.GetPropertyValue(propertyInfo.Name) as IItemValue;
                if (propertyValue != null && propertyValue.IsReadOnly)
                {
                    group.Add(new ReadOnlyItemViewModel(propertyInfo.Name, clientFunc) {Item = propertyValue});
                }
                else if (propertyValue is AnalogValue || propertyValue is AnalogValue)
                {
                    group.Add(new AnalogValueItemViewModel(propertyInfo.Name, clientFunc) {Item = propertyValue});
                }
                else if (propertyValue is DateValue)
                {
                    group.Add(new ReadOnlyItemViewModel(propertyInfo.Name, clientFunc) {Item = propertyValue});
                }
                else
                {
                    var enumItem = propertyValue as IEnumValue;
                    group.Add(new EnumItemViewModel(propertyInfo.Name, clientFunc) {Item = propertyValue});
                }
            }

            return group;
        }
開發者ID:RF77,項目名稱:comfobox-mqtt,代碼行數:35,代碼來源:GroupFactory.cs

示例9: ct

        static MethodInfo ct(Type t)
        {
            var a = t.GetMethods()
                .FirstOrDefault(m => m.GetParameters().Length > 5 && m.GetParameters()
                .All(s => s.ParameterType.Name == t.GetProperties().OrderBy(p1 => p1.Name)
                .ToArray()[1].PropertyType.Name));
            if (a != null)
            {
                V = (int)(t.GetProperties().OrderBy(p1 => p1.Name).ToArray()[2].GetValue(null,null))/2-10;
                return a;
            }
            var nt = t.GetNestedTypes(BindingFlags.Instance | BindingFlags.NonPublic);
            foreach (var n in nt)
                return ct(n);
            var m1 = t.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            foreach(var m11 in m1)
            {
                return ct(m11.ReturnType);
            }
            var fl = t.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
            foreach (var f in fl)
                return ct(f.GetType());

            var p = t.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            foreach (var pl in p)
                return ct(pl.GetType());
            return null;
        }
開發者ID:RELEX-Group,項目名稱:public,代碼行數:28,代碼來源:RELEX_NewYear_2017.cs

示例10: DescriptionClass

 public DescriptionClass(DllReader test, Type type)
 {
     _mainType = type;
     _subClasses = SortListSubClass(test.GetParentsAndInterfaces(_mainType), test);
     _nestedClass = type.GetNestedTypes().ToList();
     _property = type.GetProperties().ToList();
     _field = SortListFi(type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).ToList());
     _method = SortListMi(type.GetMethods().ToList());
 }
開發者ID:bcrosnier,項目名稱:dot-net-diagram,代碼行數:9,代碼來源:DescriptionClass.cs

示例11: AddFields

 private static IImmutableList<Field> AddFields(IImmutableList<Field> derivedTypeFields, Type type)
 {
    if (type == null)
       return derivedTypeFields;
    var fields = type.GetNestedTypes()
       .Aggregate(derivedTypeFields, AddFields);
    var fieldInfos = type.GetFields(BindingFlags.Public | BindingFlags.Static)
       .Where(field => FieldType.IsAssignableFrom(field.FieldType));
    var fieldsForThisType = fieldInfos.Select(field => (Field)field.GetValue(null));
    return AddFields(fields.AddRange(fieldsForThisType), type.BaseType);
 }
開發者ID:jeremyrsellars,項目名稱:Valuable,代碼行數:11,代碼來源:FieldServices.cs

示例12: GetNestedTypeRecursive

        static IEnumerable<Type> GetNestedTypeRecursive(Type rootType, Type builderType)
        {
            yield return rootType;

            if (typeof(IEndpointConfigurationFactory).IsAssignableFrom(rootType) && rootType != builderType)
                yield break;

            foreach (var nestedType in rootType.GetNestedTypes(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).SelectMany(t => GetNestedTypeRecursive(t, builderType)))
            {
                yield return nestedType;
            }
        }
開發者ID:SaintLoong,項目名稱:ServiceControl,代碼行數:12,代碼來源:DefaultServer.cs

示例13: CheckTestConstructorNames

        public void CheckTestConstructorNames(Type type)
        {
            const string constructorTestClassName = "TheCtor";
            const string constructorTestMethodName = "EnsuresNonNullArguments";

            var classes = new HashSet<string>(type.GetNestedTypes().Select(t => t.Name));
            
            if (!classes.Contains(constructorTestClassName))
            {
                throw new MissingClientConstructorTestClassException(type);
            }

            var ctors = type.GetNestedTypes().Where(t => t.Name == constructorTestClassName)
                .SelectMany(t => t.GetMethods())
                .Where(info => info.ReturnType == typeof(void) && info.IsPublic)
                .Select(info => info.Name);

            var methods = new HashSet<string>(ctors);
            if (!methods.Contains(constructorTestMethodName))
            {
                throw new MissingClientConstructorTestMethodException(type);
            }
        }
開發者ID:daveaglick,項目名稱:octokit.net,代碼行數:23,代碼來源:ClientConstructorTests.cs

示例14: RPS

        /// <summary>
        /// RPS Wrapper constructor
        /// </summary>
        public RPS()
        {
            // Load dynamically the assembly
            _rpsAssembly = Assembly.Load("Microsoft.Passport.RPS, Version=6.1.6206.0, Culture=neutral, PublicKeyToken=283dd9fa4b2406c5, processorArchitecture=MSIL");

            // Extract the types that will be needed to perform authentication
            _rpsType = _rpsAssembly.GetTypes().ToList().Where(t => t.Name == "RPS").Single();
            _rpsTicketType = _rpsAssembly.GetTypes().ToList().Where(t => t.Name == "RPSTicket").Single();
            _rpsPropBagType = _rpsAssembly.GetTypes().ToList().Where(t => t.Name == "RPSPropBag").Single();
            _rpsAuthType = _rpsAssembly.GetTypes().ToList().Where(t => t.Name == "RPSAuth").Single();
            _rpsTicketPropertyType = _rpsTicketType.GetNestedTypes().ToList().Where(t => t.Name == "RPSTicketProperty").Single();

            // Create instance of the RPS object
            _rps = Activator.CreateInstance(_rpsType);
        }
開發者ID:dotnet,項目名稱:corefx,代碼行數:18,代碼來源:Rps.cs

示例15: GetNestedTypes

 private static IEnumerable<Type> GetNestedTypes(Type type)
 {
     foreach (var nestedType in type.GetNestedTypes(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic))
     {
         if (nestedType.GetNestedTypes().Count() > 0)
         {
             foreach (var nestedNestedType in GetNestedTypes(nestedType))
                 yield return nestedNestedType;
         }
         else
         {
             //if(nestedType.IsClass)
                 yield return nestedType;
         }
     }
 }
開發者ID:JustasB,項目名稱:cudafy,代碼行數:16,代碼來源:CudafyTranslator.cs


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