C#의 메타데이터

WBOY
풀어 주다: 2024-09-03 15:30:18
원래의
430명이 탐색했습니다.

메타데이터의 C#은 프로그램을 설명하는 바이너리 정보로 정의되며 이 정보는 공용 언어 런타임 이식 가능한 실행 파일이나 메모리에 저장됩니다. 이식 가능한 실행 파일에서 코드를 컴파일하면 메타데이터가 파일의 또 다른 영역 부분에 삽입되고 이 모든 코드는 이제 MSIL 형식(Microsoft Intermediate Language)으로 변환된 다음 코드가 파일의 다른 파티션 부분으로 이동됩니다. 어셈블리에서 정의되고 참조되는 모든 데이터 형식과 데이터 멤버는 메타데이터 내에 저장됩니다. 런타임에 C# 코드를 실행하는 동안 메모리에서 메타데이터가 로드됩니다. C# 메타데이터의 주요 목적은 클래스, 데이터 멤버, 상속 및 클래스의 데이터 유형 등에 대한 정보를 아는 것입니다. 파일의 메타데이터는 테이블과 힙 데이터 구조로 구성됩니다.

메타데이터 활용

메타데이터의 용도는 다음과 같습니다.

  • 이름, 가시성, 기본 클래스, 인터페이스 등과 같은 어셈블리 데이터 유형에 대한 설명을 제공합니다.
  • 메서드, 필드, 속성, 이벤트 및 중첩 유형과 같은 데이터 멤버를 제공합니다.
  • 타입과 멤버를 수정하는 요소에 대한 추가 설명도 제공합니다.
  • 이름, 버전, 공개 키 등과 같은 ID가 있습니다.
  • 간단한 프로그래밍 모델의 핵심이며 IDL(인터페이스 정의 언어) 파일, 헤더 파일이 필요하지 않게 됩니다.

메타데이터 유형

다음은 메타데이터 유형의 그림입니다.

C#의 메타데이터

메타데이터의 역할

메타데이터의 역할은 다음과 같습니다.

C#의 메타데이터

C#에서 메타데이터는 어떻게 작동하나요?

C# 메타데이터는 데이터에 대한 정보를 알고 작업했습니다.

구문:

using packageName;//used for insert the packages in C#
public class MyApp
{
public static int Main()
{
//data types
Console.WriteLine("Required Message");
}
//user defined methods for other logics
}
로그인 후 복사

C#의 메타데이터 예

다음은 C#의 메타데이터 예입니다.

예시 #1

3개의 숫자 곱셈

코드: Multiplication.cs

using System; //Used for declaring the package or used for importing existed packege
public class Multiplication//declaring the class
{
public static int Main ()// main method for displaying the output
{
//declaring and defining the varaiables
int x = 50;
int y = 20;
int z=30;
//Printing the output of the multiplication of 2 numbers
Console.WriteLine ("Multiplication of {0},{1} and {2} is {3}",x,y,z,multiplication(x,y,z));
return 0;
}
public static int multiplication(int x, int y, int z)// multiplication() method implemention
{
return (x * y*z);// return multiplication of 3 numbers
}
}
로그인 후 복사

출력:

C#의 메타데이터

설명:

  • 약식에서 볼 수 있듯이 실제 데이터를 볼 수 있습니다. 메타데이터나 바이너리 데이터를 원할 경우 기계 생성 코드 내부의 컴파일러를 볼 수 있습니다. 이는 항상 암호화되어 인간이 이해할 수 없습니다.

예시 #2

광장 면적

코드: SquareOfArea.cs

using System; //Used for declaring the package or used for importing existed packege
public class SquareArea//declaring the class
{
public static int Main ()// main method for displaying the output
{
//declaring and defining the varaiables
int x = 50;
//Printing the output of the areaOfSquare
Console.WriteLine ("Area of Square is {0}",areaOfSquare(x));
return 0;
}
public static int areaOfSquare(int x)// multiplication() method implemention
{
return (x*x);// return area Of Square
}
}
로그인 후 복사

출력:

C#의 메타데이터

설명:

  • 약식에서 볼 수 있듯이 실제 데이터를 볼 수 있습니다. 메타데이터나 바이너리 데이터를 원할 경우 기계 생성 코드 내부의 컴파일러를 볼 수 있습니다. 이는 항상 암호화되어 인간이 이해할 수 없습니다.

예시 #3

데이터를 사용한 다중 클래스

코드: MultiData.net

using System; //Used for declaring the package or used for importing existed packege
using System.Collections.Generic; //Used for declaring the package or used for importing existed packege
public class Entity {//declaring the class
//setters and getters for set and get the data
public string Name {get;set;}
public string Uses {get;set;}
//toString method to overide predefined String data
public override string ToString() {
string output1=string.Format("My Name is {0}", Name);
string output2=string.Format(" He is: {0}", Uses);
return output1+output2;
}
}
//declaring interface with reference class extention
public interface IMeta<T> where T: class {
//setters and getter for set and get the data
T Inner {get;set;}
stringMetaData {get;set;}
}
//declaring interface with reference class extention
public interface IStorage<T> where T: class {
//method definition for save the data
T Save();
}
//declaring the class by extending Imeta and IStorage interfaces
public class Meta<T> : IMeta<T>, IStorage<T>
where T: class
{
//creating a generic dictionary variable
private static Dictionary<T, Meta<T>> _stash = new Dictionary<T, Meta<T>>();
//constructor for the class
public Meta(T item) {
Inner = item;
}
//setters and getters for set and get the data
public T Inner {get;set;}
public string MetaData {get;set;}
//method implementation for operator
public static implicit operator T(Meta<T> meta) {
if (! _stash.ContainsKey(meta.Inner))
_stash.Add(meta.Inner, meta);
returnmeta.Inner;
}
public static implicit operator Meta<T>(T item) {
try {
return _stash[item];
} catch {
return null;
}
}
//save the data to repository
public T Save() {
return this;
}
}
//declaring the class
public static class MetaHelper {
//method definition for return the data
public static IMeta<T>GetMeta<T>(T item) where T: class {
return (Meta<T>)item;
}
//method definition for store the data
public static IStorage<T>GetStorage<T>(T item) where T: class {
return (Meta<T>)item;
}
}
//declaring the class
public class Program
{
//Entity type for createEntity method definition with 2 arguments
public static Entity CreateEntity(string name, string uses) {
//creating a variable
var result = new Meta<Entity>(new Entity(){ Name = name, Uses = uses });
//adding data to the variable that is metadata
result.MetaData = "Paramesh";
return  result;
}
//test method to test the data
public static void Main()
{
//Passing the values to createEntity method
varent = CreateEntity("Amardeep", "Good Person");
//types casting ent into Meta class
Meta<Entity> meta = (Meta<Entity>)ent;
//creating variables
varimeta = MetaHelper.GetMeta<Entity>(ent);
varistore = MetaHelper.GetStorage<Entity>(ent);
var stored = istore.Save();
//Displaying output
Console.WriteLine("MetaData: {0} {1} {2} {3}", imeta.MetaData, imeta.Inner.Name, stored.Name, stored.Uses);
Console.WriteLine(ent);
if (meta != null) Console.WriteLine(meta.MetaData);
elseConsole.WriteLine("This is not a meta type");
}
}
로그인 후 복사

출력:

C#의 메타데이터

설명:

  • 약식에서 볼 수 있듯이 실제 데이터를 볼 수 있습니다. 메타데이터나 바이너리 데이터를 원할 경우 기계 생성 코드 내부의 컴파일러를 볼 수 있습니다. 이는 항상 암호화되어 인간이 이해할 수 없습니다.

결론

C#의 메타데이터는 데이터에 대한 데이터를 알기 위해 사용됩니다. 이는 모두 바이너리 형식으로 암호화되어 있어 사람이 이해할 수 없으므로 바이너리 코드를 일반 코드로 변환하여 로직을 분석합니다.

위 내용은 C#의 메타데이터의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!