Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我使用一个接口实现了一个弹出窗口。有没有办法在一些参数中硬编码?_C# - Fatal编程技术网

C# 我使用一个接口实现了一个弹出窗口。有没有办法在一些参数中硬编码?

C# 我使用一个接口实现了一个弹出窗口。有没有办法在一些参数中硬编码?,c#,C#,我有调用依赖服务的代码,以访问iOS和Android中的弹出式实现。它是这样做的: DependencyService.Get<IPopUp>().Popup("XYZ", "ABC", (Color)Application.Current.Resources["PopUpTitleColor"], (Color)Application.Current.Resources["PopUpMessageColor"],

我有调用依赖服务的代码,以访问iOS和Android中的弹出式实现。它是这样做的:

DependencyService.Get<IPopUp>().Popup("XYZ", "ABC",
            (Color)Application.Current.Resources["PopUpTitleColor"],
            (Color)Application.Current.Resources["PopUpMessageColor"],
            (Color)Application.Current.Resources["PopUpBackgroundColor"],
            (Color)Application.Current.Resources["PopUpSeparatorColor"],
            (sen, args) => {
                DidShowFirstMessage = true;
            });

public interface IPopUp
{
    void Popup(string title,
        string message,
        Color titleColor,
        Color messageColor,
        Color popUpBackgroundColor,
        Color popUpSeparatorColor,
        EventHandler handler);
}

[assembly: Dependency(typeof(PopupImplemention))]
namespace Japanese.iOS.CustomRenderers
{
    public class PopupImplemention : IPopUp
    {
        public void Popup(string title,
            string message,
            Color titleColor,
            Color messageColor,
            Color popUpBackgroundColor,
            Color popUpSeparatorColor,
            EventHandler handler)
        {
每次调用弹出窗口时,它都使用相同的颜色参数。有没有一种不改变PopupImplementation的方法,我可以这样调用Popup:

DependencyService.Get<IPopUp>().Popup("XYZ", "ABC", (sen, args) => {
            DidShowFirstMessage = true;
});
由于它是一个接口,我认为我无法硬编码参数,因此想知道如何才能做到这一点。

您可以创建:

公共静态void popup此IPopUp弹出窗口、字符串标题、字符串消息、EventHandler处理程序 { 弹出,弹出 标题 消息 ColorApplication.Current.Resources[PopuptleColor], ColorApplication.Current.Resources[PopUpMessageColor], ColorApplication.Current.Resources[PopuBackgroundColor], ColorApplication.Current.Resources[PopusSeparatorColor], 处理者 ; }
创建一个扩展方法,您可以尝试使用它,但是use应该将编译时常量指定为默认值,并且必须在参数列表的末尾定义可选参数