KO CSharp Keyword partial member - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki

ะฃะบั€ะฐั—ะฝััŒะบะฐ ยท ะ ัƒััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซ”ไธญๆ–‡ ยท ๆ—ฅๆœฌ่ชž ยท ํ•œ๊ตญ์–ด

C#: partial๋Š” ๋ถ€๋ถ„ ์šฉ์–ด์ž…๋‹ˆ๋‹ค.

ํ•ธ๋“œ๋ถ C# ยท ์‹ค์šฉ ๊ฐ€์ด๋“œ

๋ถ€๋ถ„ ๋ฉค๋ฒ„์—๋Š” ๋ถ€๋ถ„ ์œ ํ˜• ๋‚ด์— ๋ณ„๋„์˜ ์„ ์–ธ๊ณผ ๊ตฌํ˜„์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ง€์ •๋œ ๊ณต์šฉ ๋ฉ”์„œ๋“œ ๋ฐ ์†์„ฑ์— ๋Œ€ํ•œ ๊ตฌํ˜„์€ ํ•„์ˆ˜์ž…๋‹ˆ๋‹ค. ๊ทธ๋…€์˜ ์„œ๋ช…์ด ๊ด‘๊ณ ์™€ ์ผ์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋ถ€๋ถ„ ์†์„ฑ์€ C# 13๋ถ€ํ„ฐ ์ง€์›๋ฉ๋‹ˆ๋‹ค. ํ”„๋กœ์ ํŠธ๋Š” ๋ชจ๋“  ๋ถ€๋ถ„์„ ํ•จ๊ป˜ ์ปดํŒŒ์ผํ•ฉ๋‹ˆ๋‹ค.

๊ฐ„๋‹จํ•œ ์˜ˆ์ œ (Example.cs)

์ด ์˜ˆ์ œ๋ฅผ Example.cs๋กœ ๋”ฐ๋กœ ์ €์žฅํ•˜๊ณ  ์ด ํŽ˜์ด์ง€์˜ ๋‹ค๋ฅธ ์˜ˆ์ œ์™€ ๋…๋ฆฝ์ ์œผ๋กœ ์‹คํ–‰ํ•˜์„ธ์š”.

Example.cs:

// PROJECT-EXAMPLE
System.Console.WriteLine(new Item().Read());
partial class Item { public partial int Read(); }
partial class Item { public partial int Read() => 7; }

๊ฒฐ๊ณผ:

7

ํ†ต์‚ฌ๋ก 

public partial string Format(string name, int count);
public partial string Name { get; set; }

๊ณต๊ฐœ ๋ถ€๋ถ„ ๋ฉ”์„œ๋“œ ์„ ์–ธ ๋ฐ ๊ตฌํ˜„

ํŒŒ์ผ Example.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <LangVersion>14.0</LangVersion>
    <Nullable>enable</Nullable>
    
  </PropertyGroup>

</Project>

ํŒŒ์ผ Program.cs:

using System;
internal static class Program
{
    public static void Main()
    {
        var formatter = new Formatter();
        Console.WriteLine(formatter.Format("Bandages", 15));
    }
}

ํŒŒ์ผ Formatter.Contract.cs:

public partial class Formatter
{
    public partial string Format(string name, int count);
}

ํŒŒ์ผ Formatter.Implementation.cs:

public partial class Formatter
{
    public partial string Format(string name, int count) => $"{name}: {count}";
}

๊ฒฐ๊ณผ:

Bandages: 15

ํ• ๋‹น ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๊ฐ€ ํฌํ•จ๋œ ๋ถ€๋ถ„ ์†์„ฑ

ํŒŒ์ผ Example.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <LangVersion>14.0</LangVersion>
    <Nullable>enable</Nullable>
    
  </PropertyGroup>

</Project>

ํŒŒ์ผ Program.cs:

using System;
internal static class Program
{
    public static void Main()
    {
        var settings = new Settings { Name = "  Traveller  " };
        Console.WriteLine($"[{settings.Name}]");
    }
}

ํŒŒ์ผ Settings.Contract.cs:

public partial class Settings
{
    public partial string Name { get; set; }
}

ํŒŒ์ผ Settings.Implementation.cs:

public partial class Settings
{
    private string name = "";
    public partial string Name
    {
        get => name;
        set => name = value.Trim();
    }
}

๊ฒฐ๊ณผ:

[Traveller]

์˜ˆ์‹œ 3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        Counter value = new(5);
        Console.WriteLine(value.Value);
    }
}
public partial class Counter { public int Value { get; } public partial Counter(int value); }
public partial class Counter { public partial Counter(int value) { Value = value; } }

์˜ˆ์‹œ 4

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        Signal value = new();
        value.Fired += () => Console.WriteLine("Fired");
        value.Fire();
    }
}
public partial class Signal { public partial event Action Fired; }
public partial class Signal { private Action? handlers; public partial event Action Fired { add { handlers += value; } remove { handlers -= value; } } public void Fire() { handlers?.Invoke(); } }

๊ณต์‹ ์ถœ์ฒ˜: Microsoft ํ•™์Šต.

โš ๏ธ **GitHub.com Fallback** โš ๏ธ