1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using Xamarin.Forms; namespace Greetings { public class ReflectedColorsPage : ContentPage { public ReflectedColorsPage() { StackLayout stackLayout = new StackLayout { // BackgroundColor = Color.Blue, Orientation = StackOrientation.Horizontal }; // Loop through the Color structure fields. foreach (FieldInfo info in typeof(Color).GetRuntimeFields()) { // Skip the obsolete (i.e. misspelled) colors. if (info.GetCustomAttribute<ObsoleteAttribute>() != null) continue; if (info.IsPublic && info.IsStatic && info.FieldType == typeof(Color)) { stackLayout.Children.Add(CreateColorLabel((Color)info.GetValue(null), info.Name)); } } // Loop through the Color structure properties. foreach (PropertyInfo info in typeof(Color).GetRuntimeProperties()) { MethodInfo methodInfo = info.GetMethod; if (methodInfo.IsPublic && methodInfo.IsStatic && methodInfo.ReturnType == typeof(Color)) { stackLayout.Children.Add(CreateColorLabel((Color)info.GetValue(null), info.Name)); } } Padding = new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5); // Put the StackLayout in a ScrollView. Content = new ScrollView { Orientation = ScrollOrientation.Horizontal, Content = stackLayout }; } Label CreateColorLabel (Color color, string name) { Color backgroundColor = Color.Default; if (color != Color.Default) { // Standard luminance calculation. double luminance = 0.30 * color.R + 0.59 * color.G + 0.11 * color.B; backgroundColor = luminance > 0.5 ? Color.Black : Color.White; } // Create the Label. return new Label { Text = name, TextColor = color, FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)), BackgroundColor = backgroundColor, }; } } } | cs |
자마린에서 쓰는 메서드, 속성 이해가 잘 안되네. 어린 애들은 이거 보고 금방 이해하겠지?
메서드는 멤버 함수고 속성은 게터 있는 필드야
get은 읽기 속성, set은 쓰기 속성 입니다.