Search for the fields defined for the current Type, using the specified binding constraints. : FieldInfo « Reflection « C# / C Sharp






Search for the fields defined for the current Type, using the specified binding constraints.

  

using System;
using System.Reflection;

class AttributesSample
{
    public void Mymethod (int int1m, out string str2m, ref string str3m)
    {
        str2m = "in Mymethod";
    }

    public static int Main(string[] args)
    {      
        Console.WriteLine ("Reflection.MethodBase.Attributes Sample");
        Type MyType = Type.GetType("AttributesSample");
        MethodBase Mymethodbase = MyType.GetMethod("Mymethod");
        Console.WriteLine("Mymethodbase = " + Mymethodbase);
        MethodAttributes Myattributes = Mymethodbase.Attributes;
        PrintAttributes(typeof(System.Reflection.MethodAttributes), (int) Myattributes);
        return 0;
    }
    public static void PrintAttributes(Type attribType, int iAttribValue)
    {
        if (!attribType.IsEnum)
        { 
            Console.WriteLine("This type is not an enum."); 
            return; 
        }

        FieldInfo[] fields = attribType.GetFields(BindingFlags.Public | BindingFlags.Static);
        for (int i = 0; i < fields.Length; i++)
        {
            int fieldvalue = (Int32)fields[i].GetValue(null);
            if ((fieldvalue & iAttribValue) == fieldvalue)
            {
                Console.WriteLine(fields[i].Name);
            }
        }
    }
}

   
    
  








Related examples in the same category

1.FieldInfo Class discovers the attributes of a field and provides access to field metadata.
2.FieldInfo.Attributes Property gets the attributes associated with this field.FieldInfo.Attributes Property gets the attributes associated with this field.
3.FieldInfo.FieldHandle Property gets a RuntimeFieldHandle, which is a handle to the internal metadata representation of a field.
4.FieldInfo.FieldType Property gets the type of this field object.
5.FieldInfo.GetFieldFromHandle Method gets a FieldInfo for the field represented by the specified handle.
6.FieldInfo.GetValue Method returns the value of a field supported by a given object.
7.Get field value
8.FieldInfo.IsAssembly Property indicates whether the field is visible at most to other types in the same assembly
9.FieldInfo.IsInitOnly Property indicates whether the field can only be set in the body of the constructor.
10.FieldInfo.IsNotSerialized Property indicates whether this field has the NotSerialized attribute.
11.FieldInfo.IsPinvokeImpl Property indicates whether the PinvokeImpl attribute is set in FieldAttributes.
12.FieldInfo.IsPrivate
13.whether the field is public.
14.Whether the corresponding SpecialName attribute is set in the FieldAttributes enumerator.
15.Whether the field is static.
16.This member is a field.
17.Sets the value of the field supported by the given object.
18.Gets the attributes associated with this field.Gets the attributes associated with this field.
19.Gets a RuntimeFieldHandle, which is a handle to the internal metadata representation of a field.
20.Gets a FieldInfo for the field represented by the specified handle.
21.Gets a FieldInfo for the field represented by the specified handle, for the specified generic type.
22.Represents the case-insensitive member filter used on names. This field is read-only.
23.Searches for the public field with the specified name.
24.Searches for the specified field, using the specified binding constraints.
25.Returns all the public fields of the current Type.
26.Set Non-Pubic Field