Last active
March 6, 2025 12:23
-
-
Save baobao/7738bb33b51039acfaeb344cbd483055 to your computer and use it in GitHub Desktop.
【Unity】開発の幅が広がるC#のリフレクション入門のサンプルコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| namespace info.shibuya24 | |
| { | |
| internal class ReflectionSample : ParentReflectionSample | |
| { | |
| public static int StaticPublicField = 1; | |
| private static int StaticPrivateField = 2; | |
| internal static int StaticInternalField = 3; | |
| protected static int StaticProtectedField = 4; | |
| public static int StaticPublicProp { get; set; } = 5; | |
| private static int StaticPrivateProp { get; set; } = 6; | |
| internal static int StaticInternalProp { get; set; } = 7; | |
| protected static int StaticProtectedProp { get; set; } = 8; | |
| public const int ConstPublicField = 9; | |
| private const int ConstPrivateField = 10; | |
| internal const int ConstInternalField = 11; | |
| protected const int ConstProtectedField = 12; | |
| public int MemberPublicField = 13; | |
| internal int MemberInternalField = 14; | |
| private int MemberPrivateField = 15; | |
| protected int MemberProtectedField = 16; | |
| public readonly int ReadonlyMemberPublicField = 17; | |
| internal readonly int ReadonlyMemberInternalField = 18; | |
| private readonly int ReadonlyMemberPrivateField = 19; | |
| protected readonly int ReadonlyMemberProtectedField = 20; | |
| public int MemberPublicProp { get; set; } = 21; | |
| internal int MemberInternalProp { get; set; } = 22; | |
| private int MemberPrivateProp { get; set; } = 23; | |
| protected int MemberProtectedProp { get; set; } = 24; | |
| public static void StaticPublicMethod() | |
| { | |
| Debug.Log($"{nameof(StaticPublicMethod)} : 25"); | |
| } | |
| private static void StaticPrivateMethod() | |
| { | |
| Debug.Log($"{nameof(StaticPrivateMethod)} : 26"); | |
| } | |
| protected static void StaticProtectedMethod() | |
| { | |
| Debug.Log($"{nameof(StaticProtectedMethod)} : 27"); | |
| } | |
| internal static void StaticInternalMethod() | |
| { | |
| Debug.Log($"{nameof(StaticInternalMethod)} : 28"); | |
| } | |
| public void MemberPublicMethod() | |
| { | |
| Debug.Log($"{nameof(MemberPublicMethod)} : 29"); | |
| } | |
| private void MemberPrivateMethod() | |
| { | |
| Debug.Log($"{nameof(MemberPrivateMethod)} : 30"); | |
| } | |
| private void MemberPrivateMethodArg(int id, string name) | |
| { | |
| Debug.Log($"{nameof(MemberPrivateMethodArg)} id : {id}, name : {name}"); | |
| } | |
| protected void MemberProtectedMethod() | |
| { | |
| Debug.Log($"{nameof(MemberProtectedMethod)} : 31"); | |
| } | |
| internal void MemberInternalMethod() | |
| { | |
| Debug.Log($"{nameof(MemberInternalMethod)} : 32"); | |
| } | |
| } | |
| internal class ParentReflectionSample | |
| { | |
| public static int ParentStatciPublicField = 33; | |
| private static int ParentStaticPrivateField = 34; | |
| internal static int ParentStaticInternalField = 35; | |
| protected static int ParentStaticProtectedField = 36; | |
| public static int ParentStatciPublicProp { get; set; } = 37; | |
| private static int ParentStaticPrivateProp { get; set; } = 38; | |
| internal static int ParentStaticInternalProp { get; set; } = 39; | |
| protected static int ParentStaticProtectedProp { get; set; } = 40; | |
| public const int ParentConstPublicField = 41; | |
| private const int ParentConstPrivateField = 42; | |
| internal const int ParentConstInternalField = 43; | |
| protected const int ParentConstProtectedField = 44; | |
| public int ParentMemberPublicField = 45; | |
| internal int ParentMemberInternalField = 46; | |
| private int ParentMemberPrivateField = 47; | |
| protected int ParentMemberProtectedField = 48; | |
| public readonly int ParentReadonlyMemberPublicField = 49; | |
| internal readonly int ParentReadonlyMemberInternalField = 50; | |
| private readonly int ParentReadonlyMemberPrivateField = 51; | |
| protected readonly int ParentReadonlyMemberProtectedField = 52; | |
| public int ParentMemberPublicProp { get; set; } = 53; | |
| internal int ParentMemberInternalProp { get; set; } = 54; | |
| private int ParentMemberPrivateProp { get; set; } = 55; | |
| protected int ParentMemberProtectedProp { get; set; } = 56; | |
| public static void ParentStaticPublicMethod() | |
| { | |
| Debug.Log($"{nameof(ParentStaticPublicMethod)} : 57"); | |
| } | |
| private static void ParentStaticPrivateMethod() | |
| { | |
| Debug.Log($"{nameof(ParentStaticPrivateMethod)} : 58"); | |
| } | |
| protected static void ParentStaticProtectedMethod() | |
| { | |
| Debug.Log($"{nameof(ParentStaticProtectedMethod)} : 59"); | |
| } | |
| internal static void ParentStaticInternalMethod() | |
| { | |
| Debug.Log($"{nameof(ParentStaticInternalMethod)} : 60"); | |
| } | |
| public void ParentMemberPublicMethod() | |
| { | |
| Debug.Log($"{nameof(ParentMemberPublicMethod)} : 61"); | |
| } | |
| private void ParentMemberPrivateMethod() | |
| { | |
| Debug.Log($"{nameof(ParentMemberPrivateMethod)} : 62"); | |
| } | |
| protected void ParentMemberProtectedMethod() | |
| { | |
| Debug.Log($"{nameof(ParentMemberProtectedMethod)} : 63"); | |
| } | |
| internal void ParentMemberInternalMethod() | |
| { | |
| Debug.Log($"{nameof(ParentMemberInternalMethod)} : 64"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment