0 Replies - 762 Views - Last Post: 03 May 2017 - 04:46 PM

#1 Dialupp  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 210
  • Joined: 31-October 16

Is this a method?

Posted 03 May 2017 - 04:46 PM

Hey guys silly question is this a method down below its called "CreateColorLabel" I assume it is because the parameters and so but I realized doesn't let me have a public modifier is this because its implemented in the constructor? Also what would be point of create a method in the constructor?

    class ReflectedColorsPage : ContentPage
    {

        public ReflectedColorsPage()
        {
            StackLayout stackLayout = new StackLayout();
            // 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
            {
                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
                };
            }


        }
    }



Is This A Good Question/Topic? 0
  • +

Page 1 of 1