Computer >> 컴퓨터 >  >> 프로그램 작성 >> C#

C#의 Type.GetProperties() 메서드

<시간/>

C#의 Type.GetProperties() 메서드는 현재 Type의 속성을 가져오는 데 사용됩니다.

구문

다음은 구문입니다 -

public System.Reflection.PropertyInfo[] GetProperties ();
public abstract System.Reflection.PropertyInfo[] GetProperties (System.Reflection.BindingFlags bindingAttr);

위의 bindingAttr은 검색 수행 방법을 지정하는 열거형 값의 비트 조합입니다.

예시

using System;
using System.Reflection;
public class Demo {
   public static void Main(){
      Type type = typeof(System.Type);
      PropertyInfo[] info = type.GetProperties();
      Console.WriteLine("Properties... ");
      for (int i = 0; i < info.Length; i++)
         Console.WriteLine(" {0}", info[i].ToString());
   }
}

출력

이것은 다음과 같은 출력을 생성합니다 -

Properties...
System.Reflection.MemberTypes MemberType
System.Type DeclaringType
System.Reflection.MethodBase DeclaringMethod
System.Type ReflectedType
System.Runtime.InteropServices.StructLayoutAttribute StructLayoutAttribute
System.Guid GUID
System.Reflection.Binder DefaultBinder
System.Reflection.Module Module
System.Reflection.Assembly Assembly
System.RuntimeTypeHandle TypeHandle
System.String FullName
System.String Namespace
System.String AssemblyQualifiedName
System.Type BaseType
System.Reflection.ConstructorInfo TypeInitializer
Boolean IsNested
System.Reflection.TypeAttributes Attributes
System.Reflection.GenericParameterAttributes GenericParameterAttributes
Boolean IsVisible
Boolean IsNotPublic
Boolean IsPublic
Boolean IsNestedPublic
Boolean IsNestedPrivate
Boolean IsNestedFamily
Boolean IsNestedAssembly
Boolean IsNestedFamANDAssem
Boolean IsNestedFamORAssem
Boolean IsAutoLayout
Boolean IsLayoutSequential
Boolean IsExplicitLayout
Boolean IsClass
Boolean IsInterface
Boolean IsValueType
Boolean IsAbstract
Boolean IsSealed
Boolean IsEnum
Boolean IsSpecialName
Boolean IsImport
Boolean IsSerializable
Boolean IsAnsiClass
Boolean IsUnicodeClass
Boolean IsAutoClass
Boolean IsArray
Boolean IsGenericType
Boolean IsGenericTypeDefinition
Boolean IsConstructedGenericType
Boolean IsGenericParameter
Int32 GenericParameterPosition
Boolean ContainsGenericParameters
Boolean IsByRef
Boolean IsPointer
Boolean IsPrimitive
Boolean IsCOMObject
Boolean HasElementType
Boolean IsContextful
Boolean IsMarshalByRef
System.Type[] GenericTypeArguments
Boolean IsSecurityCritical
Boolean IsSecuritySafeCritical
Boolean IsSecurityTransparent
System.Type UnderlyingSystemType
System.String Name
System.Collections.Generic.IEnumerable`1[System.Reflection.CustomAttributeData] CustomAttributes
Int32 MetadataToken

예시

이제 Type.GetProperties() 메서드를 구현하는 또 다른 예를 살펴보겠습니다. -

using System;
using System.Reflection;
public class Demo {
   public static void Main(){
      Type type = typeof(string);
      PropertyInfo[] info = type.GetProperties();
      Console.WriteLine("Count of Properties = "+info.Length);
      Console.WriteLine("Properties... ");
      for (int i = 0; i < info.Length; i++)
         Console.WriteLine(" {0}", info[i].ToString());
   }
}

출력

이것은 다음과 같은 출력을 생성합니다 -

Count of Properties = 2
Properties...
Char Chars [Int32]
Int32 Length