当前位置: 首页>>代码示例>>C#>>正文


C# Type.GetFields方法代码示例

本文整理汇总了C#中Type.GetFields方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetFields方法的具体用法?C# Type.GetFields怎么用?C# Type.GetFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Type的用法示例。


在下文中一共展示了Type.GetFields方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetEnumList

    public static List<ListItem> GetEnumList(Type enumType, bool allAllOption)
    {
        if (enumType.IsEnum == false)
        {
            return null;
        }
        List<ListItem> list = new List<ListItem>();
        if (allAllOption == true)
        {
            list.Add(new ListItem("全部", string.Empty));
        }

        Type typeDescription = typeof(DescriptionAttribute);
        System.Reflection.FieldInfo[] fields = enumType.GetFields();
        string strText = string.Empty;
        string strValue = string.Empty;
        foreach (FieldInfo field in fields)
        {
            if (field.IsSpecialName) continue;
            strValue = field.GetRawConstantValue().ToString();
            object[] arr = field.GetCustomAttributes(typeDescription, true);
            if (arr.Length > 0)
            {
                strText = (arr[0] as DescriptionAttribute).Description;
            }
            else
            {
                strText = field.Name;
            }

            list.Add(new ListItem(strText, strValue));
        }

        return list;
    }
开发者ID:0jpq0,项目名称:Scut,代码行数:35,代码来源:Extensions.cs

示例2: TreatAsReferenceHolder

 public static bool TreatAsReferenceHolder(Type type)
 {
     bool flag;
     if (!ReferenceTypeHelper.cache.TryGetValue(type, out flag))
     {
         if (type.IsByRef)
         {
             flag = true;
         }
         else if (!type.IsEnum)
         {
             FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
             int num = 0;
             while (num < (int)fields.Length)
             {
                 Type fieldType = fields[num].FieldType;
                 if (fieldType.IsByRef || !ReferenceTypeHelper.TreatAsReferenceHolder(fieldType))
                 {
                     flag = false;
                     break;
                 }
                 else
                 {
                     num++;
                 }
             }
         }
         else
         {
             flag = false;
         }
         ReferenceTypeHelper.cache[type] = flag;
     }
     return flag;
 }
开发者ID:HexHash,项目名称:LegacyRust,代码行数:35,代码来源:ReferenceTypeHelper.cs

示例3: ProcessStaticDataEntity

 static void ProcessStaticDataEntity(Type tp)
 {
     FieldInfo[] fields = tp.GetFields();
     if (fields != null && fields.Length > 0)
     {
         foreach (var field in fields)
         {
             if (field.IsStatic)
             {
                 object[] objs = field.GetCustomAttributes(typeof(DataEntry), true);
                 if (objs != null && objs.Length > 0)
                 {
                     AData data = (AData)field.GetValue(null);
                     if (data == null)
                     {
                         string warnstr = string.Format("Warning : DataEntity({0}.{1}) is null when scan type!", tp.Name, field.Name);
                         ALog.warning(warnstr);
                     }
                     else
                     {
                         data.dataType = ((DataEntry)objs[0]).dataType;
                     }
                 }
             }
         }
     }
 }
开发者ID:nnoldman,项目名称:d2map,代码行数:27,代码来源:DataCenter.cs

示例4: ListFields

 static void ListFields(Type t)
 {
     Console.WriteLine("***** Fields *****");
     var fieldNames = from f in t.GetFields() select f.Name;
     foreach (var name in fieldNames) {
         Console.WriteLine("->{0}", name);
     }
 }
开发者ID:walrus7521,项目名称:code,代码行数:8,代码来源:Reflection.cs

示例5: CreateSerializableJsonProperties

 private IEnumerable<JsonProperty> CreateSerializableJsonProperties(Type type)
 {
     return type.GetFields(AllInstanceMemberFlag)
         .Where(field => !field.IsNotSerialized)
         .Select(field =>
         {
             JsonProperty property = PrivateMemberContractResolver.Instance.CreatePrivateProperty(field, MemberSerialization.OptOut);
             ConfigureProperty(field, property);
             return property;
         });
 }
开发者ID:anurse,项目名称:ReviewR,代码行数:11,代码来源:JsonContractResolver.cs

示例6: showInfo

    private void showInfo(Type type)
    {
        Console.WriteLine ("type={0}", type.Name);
        PropertyInfo[] properties = type.GetProperties ();
        foreach (PropertyInfo property in properties)
            Console.WriteLine ("property.Name={0, -20} property.PropertyType={1}", property.Name, property.PropertyType);

        FieldInfo[] fields = type.GetFields (BindingFlags.Instance | BindingFlags.NonPublic);
        foreach (FieldInfo field in fields)
            //if (field.IsDefined(typeof(IdAttribute), true))
            Console.WriteLine ("field.Name={0, -30} field.FieldType={1}", field.Name, field.FieldType);
    }
开发者ID:rubenramos,项目名称:adRuben,代码行数:12,代码来源:MainWindow.cs

示例7: showInfo

    private void showInfo(Type type)
    {
        Console.WriteLine (type.Name);
        foreach (PropertyInfo pi in type.GetProperties ())
            Console.WriteLine ("PropertyType of {0} > {1}", pi.Name, pi.PropertyType);

        Console.WriteLine ("");
        foreach (FieldInfo fi in type.GetFields (BindingFlags.Instance | BindingFlags.NonPublic))
            //if (fi.IsDefined(typeof(IdAttribute), true))
            Console.WriteLine ("FieldType of {0} > {1}", fi.Name, fi.FieldType);

        Console.WriteLine ("\n");
    }
开发者ID:juankza,项目名称:ad,代码行数:13,代码来源:MainWindow.cs

示例8: getFieldsOfType

 private static FieldInfo[] getFieldsOfType(Type from, Type fieldType)
 {
     List<FieldInfo> fields = new List<FieldInfo>();
     FieldInfo[] fromFields = from.GetFields();
     for (int i = 0; i < fromFields.Length; i++ )
     {
         FieldInfo fi = fromFields[i];
         try
         {
             if (fi.FieldType == fieldType)
             {
                 fields.Add(fi);
             }
         }
         catch
         { }
     }
     return fields.ToArray();
 }
开发者ID:Redmancometh,项目名称:RedmanInject,代码行数:19,代码来源:Deobfuscator.cs

示例9: Calculate

 public static long Calculate(Type t)
 {
     MemoryStream ms = new MemoryStream();
     BinaryWriter bw = new BinaryWriter(ms);
     bw.Write(t.FullName);
     bw.Write((int)t.Attributes);
     foreach(FieldInfo fi in t.GetFields(BindingFlags.Public |
                                         BindingFlags.NonPublic | BindingFlags.Instance).OrderBy(f => f.Name))
     {
         bw.Write(fi.Name);
         bw.Write((int)fi.Attributes);
     }
     foreach(PropertyInfo pi in
             t.GetProperties(BindingFlags.Public | BindingFlags.Instance).OrderBy(p
                                                                          => p.Name))
     {
         bw.Write(pi.Name);
         bw.Write((int)pi.Attributes);
     }
     foreach(ConstructorInfo ci in
             t.GetConstructors(BindingFlags.Public | BindingFlags.Instance).OrderBy(c
                                                                            => Signature(c.Name, c.GetParameters())))
     {
         bw.Write(Signature(ci.Name, ci.GetParameters()));
         bw.Write((int)ci.Attributes);
     }
     foreach(MethodInfo mi in t.GetMethods(BindingFlags.Public |
                                           BindingFlags.Instance | BindingFlags.Static).OrderBy(m =>
                                                          Signature(m.Name, m.GetParameters())))
     {
         bw.Write(Signature(mi.Name, mi.GetParameters()));
         bw.Write((int)mi.Attributes);
     }
     bw.Close();
     ms.Close();
     byte[] b = ms.ToArray();
     byte[] hash = sha.TransformFinalBlock(b, 0, b.Length);
     return (((long)hash[0]) << 56) | (((long)hash[1]) << 48) |
         (((long)hash[2]) << 40) | (((long)hash[3]) << 32)
             | (((long)hash[4]) << 24) | (((long)hash[5]) << 16) |
             (((long)hash[6]) <<  8) | (((long)hash[7]) <<  0);
 }
开发者ID:sailesh341,项目名称:JavApi,代码行数:42,代码来源:SerialUIDCalculator.cs

示例10: AddTypeInfo

    public static int AddTypeInfo(Type type, out ATypeInfo tiOut)
    {
        ATypeInfo ti = new ATypeInfo();
        ti.fields = type.GetFields(JSMgr.BindingFlagsField);
        ti.properties = type.GetProperties(JSMgr.BindingFlagsProperty);
        ti.methods = type.GetMethods(JSMgr.BindingFlagsMethod);
        ti.constructors = type.GetConstructors();
        if (JSBindingSettings.NeedGenDefaultConstructor(type))
        {
            // null means it's default constructor
            var l = new List<ConstructorInfo>();
            l.Add(null);
            l.AddRange(ti.constructors);
            ti.constructors = l.ToArray();
        }
        ti.howmanyConstructors = ti.constructors.Length;

        FilterTypeInfo(type, ti);

        int slot = allTypeInfo.Count;
        allTypeInfo.Add(ti);
        tiOut = ti;
        return slot;
    }
开发者ID:wang10998588,项目名称:qjsbunitynew,代码行数:24,代码来源:GeneratorHelp.cs

示例11: PatternMatcher

		public PatternMatcher (Type type) 
		{
			_returnType = type;
			
			FieldInfo[] fields = type.GetFields ();
			ArrayList matchInfos = new ArrayList ();
			
			foreach (FieldInfo field in fields)
			{
				object[] ats = field.GetCustomAttributes (typeof(MatchAttribute), true);
				if (ats.Length == 0) continue;
				
				MatchInfo mi = new MatchInfo ();
				mi.Field = field;
				mi.Match = (MatchAttribute) ats[0];
				
				RegexOptions opts = RegexOptions.Multiline;
				if (mi.Match.IgnoreCase) opts |= RegexOptions.IgnoreCase;
				mi.Regex = new Regex (mi.Match.Pattern, opts);
				
				matchInfos.Add (mi);
			}
			_matchInfos = (MatchInfo[]) matchInfos.ToArray (typeof(MatchInfo));
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:24,代码来源:PatternMatcher.cs

示例12: TraverseType

    static void TraverseType(Type inType, Stack<object> inStack, List<ValidationRecord> inRecords, HashSet<UObject> inVisitedObjects = null)
    {
        if(inVisitedObjects == null)
            inVisitedObjects = new HashSet<UObject>();

        if(inStack != null && inRecords != null)
        {
            if(inType == typeof(GameObject))
            {
                var gameObject = inStack.Peek() as GameObject;
                if(!inVisitedObjects.Contains(gameObject))
                {
                    inVisitedObjects.Add(gameObject);

                    // Traverse all components.
                    var components = gameObject.GetComponents<Component>();
                    foreach(var component in components)
                    {
                        if(component && component.GetType() != null && component.GetType().Assembly != null && component.GetType().Assembly.GetName() != null)
                        {
                            var containingAssemblyName = component.GetType().Assembly.GetName().Name;
                            if(kWhitelistedAssemblyNames.Contains(containingAssemblyName))
                            {
                                inVisitedObjects.Add(component);

                                inStack.Push(component);
                                TraverseType(component.GetType(), inStack, inRecords, inVisitedObjects);
                                var popped = inStack.Pop();
                                Assert(popped == component);
                            }
                        }
                    }

                    // Traverse into children.
                    foreach(Transform childTransform in gameObject.transform)
                    {
                        var childGameObject = childTransform.gameObject;

                        inStack.Push(childGameObject);
                        TraverseType(childGameObject.GetType(), inStack, inRecords, inVisitedObjects);
                        var popped = inStack.Pop();
                        Assert(popped == childGameObject);
                    }
                }
            }
            else
            {
                var fields = inType.GetFields(
                    (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                );

                foreach(var field in fields)
                {
                    var actualObject = inStack.Peek();
                    var fieldValue = field.GetValue(actualObject);

                    // Check for attributes.
                    var attributes = field.GetCustomAttributes(typeof(MustNotBeNull), true);
                    if(attributes.Length > 0)
                    {
                        if(fieldValue == null || (fieldValue is UObject && IsNull(fieldValue as UObject)))
                        {
                            inRecords.Add(
                                new ValidationRecord()
                                {
                                    Object = actualObject,
                                    Field = field,
                                    Component = GetComponent(inStack),
                                    Path = GetPath(inStack, field),
                                    PassInfo = _activeStep == null ? string.Empty : _activeStep.PassInfo
                                }
                            );
                        }
                    }

                    // Check for entering in to the type of this current field. We only enter into types loaded from our own Assemblies
                    // (meaning they are classes or structs we've declared).
                    var assemblyString = field.FieldType.Assembly.GetName().Name;
                    if(fieldValue != null && kWhitelistedAssemblyNames.Contains(assemblyString))
                    {
                        bool shouldTraverse = true;
                        if(fieldValue is UObject && fieldValue != null)
                        {
                            if(!inVisitedObjects.Contains(fieldValue as UObject))
                                inVisitedObjects.Add(fieldValue as UObject);
                            else
                                shouldTraverse = false;
                        }

                        if(shouldTraverse)
                        {
                            inStack.Push(fieldValue);
                            TraverseType(field.FieldType, inStack, inRecords, inVisitedObjects);
                            var popped = inStack.Pop();
                            Assert(popped == fieldValue);
                        }
                    }
                }
            }
        }
//.........这里部分代码省略.........
开发者ID:TrinketBen,项目名称:Validator,代码行数:101,代码来源:ValidatorEditor.cs

示例13: getMembers

    static TypeMembers getMembers(Type type)
    {
        TypeMembers tm;
        if (dict.TryGetValue(type, out tm))
        {
            return tm;
        }
        tm = new TypeMembers();
        tm.cons = type.GetConstructors();
        tm.fields = type.GetFields(GenericTypeCache.BindingFlagsField);
        tm.properties = type.GetProperties(GenericTypeCache.BindingFlagsProperty);
        tm.methods = type.GetMethods(GenericTypeCache.BindingFlagsMethod);

        dict.Add(type, tm);
        return tm;
    }
开发者ID:wang10998588,项目名称:qjsbunitynew,代码行数:16,代码来源:GenericTypeCache.cs

示例14: ListTypeInfo

 // private void ListTypeInfo(Type type) {{{2
 private void ListTypeInfo(Type type)
 {
     Info.AppendFormat("Type: {0}\n", type); // Type name
     bool list = false;
     // List only public types {{{3
     if (OTIsPublic) {
         if (type.IsPublic)
             list = true;
     }
     else // List not only public types {{{3
         list = true;
     // If not list then exit {{{3
     if (!list)
         return;
     // Various statistics about the type {{{3
     if (OTTypeStats || OTAll) {
         Info.AppendFormat("\tBase class: {0}\n", type.BaseType);
         Info.AppendFormat("\tpublic: {0}\n", type.IsPublic);
         Info.AppendFormat("\tabstract: {0}\n", type.IsAbstract);
         Info.AppendFormat("\tsealed: {0}\n", type.IsSealed);
         Info.AppendFormat("\tgeneric: {0}\n", type.IsGenericTypeDefinition);
         Info.AppendFormat("\tclass type: {0}\n", type.IsClass);
     }
     // Fields {{{3
     if (OTFields || OTAll)
         foreach(FieldInfo i in type.GetFields()) Info.AppendFormat("\t[FI] {0}\n", i.ToString());
     // Properties {{{3
     if (OTProperties || OTAll)
         foreach(PropertyInfo i in type.GetProperties()) Info.AppendFormat("\t[PR] {0}\n", i.ToString());
     // Methods {{{3
     if (OTMethods || OTAll) {
        foreach(MethodInfo i in type.GetMethods()) {
             string retVal = i.ReturnType.FullName;
             StringBuilder paramInfo = new StringBuilder("(");
             // Get parameters
             foreach (ParameterInfo pi in i.GetParameters()) {
                  paramInfo.AppendFormat("{0} {1}, ", pi.ParameterType, pi.Name);
            }
            if (paramInfo.Length > 2)
                paramInfo.Remove(paramInfo.Length - 2, 2); // Remove trailing ", "
            paramInfo.Append(")");
            Info.AppendFormat("\t[ME] {0} {1}{2}\n", retVal, i.Name, paramInfo.ToString());
        }
     }
     // Interfaces {{{3
     if (OTInterfaces || OTAll)
         foreach(Type i in type.GetInterfaces()) Info.AppendFormat("\t[IN] {0}\n", i.ToString());
     // Events {{{3
     if (OTEvents || OTAll)
         foreach(EventInfo i in type.GetEvents()) Info.AppendFormat("\t[EV] {0}\n", i.ToString());
 }
开发者ID:viaa,项目名称:ObjectBrowser,代码行数:52,代码来源:ObjectBrowser.cs

示例15: FieldsFor

	public static FieldInfo[] FieldsFor( Type pType )
	{
		return pType.GetFields( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic );
	}
开发者ID:tetuyoko,项目名称:snipets,代码行数:4,代码来源:TeneDropTarget.cs


注:本文中的Type.GetFields方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。