当前位置: 首页>>代码示例>>C#>>正文


C# Foo.HasEqualParameters方法代码示例

本文整理汇总了C#中System.Foo.HasEqualParameters方法的典型用法代码示例。如果您正苦于以下问题:C# Foo.HasEqualParameters方法的具体用法?C# Foo.HasEqualParameters怎么用?C# Foo.HasEqualParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Foo的用法示例。


在下文中一共展示了Foo.HasEqualParameters方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public static void Run()
        {
            // test config panel
            var bar = new Bar() { C = "sub" };
            var foo = new Foo() { C = "c", D = true, E = 2.0, F = 2, G = bar };
            var config = new ConfigurationPanel(foo);
            var copy = config.GetConfiguredObject() as Foo;
            if (!bar.HasEqualParameters(copy.G))
                throw new Exception("Sub-object comparison failed!");
            foo.G = copy.G = null;
            if (!foo.HasEqualParameters(copy))
                throw new Exception("Main object comparison failed!");
            var fprop = typeof(Foo).GetProperty("F");
            config.SetterFor(fprop)(200);
            if ((int)config.GetterFor(fprop)() != 200)
                throw new Exception("Getter or setter failed!");
            config.PropertyChanged += (args) =>
            {
                if (args.Property != fprop)
                    return;

                if ((int)args.Getter() > 150)
                    args.Setter((int)args.Getter() - 2);
            };
            config.SetterFor(fprop)(190);
            if ((int)config.GetterFor(fprop)() != 150)
                throw new Exception("PropertyChanged failed!");

            // test derived type panel
            var derivedConfig = new DerivedTypeConfigurationPanel(typeof(Interface), bar);
            if (!new Bar() { C = "sub" }.HasEqualParameters((Bar)derivedConfig.GetConfiguredObject()))
                throw new Exception("DerivedTypeConfigurationPanel failed!");
            var diffBar = new Bar() { C = "different" };
            derivedConfig.SetConfiguredObject(diffBar);
            if (!diffBar.HasEqualParameters((Bar)derivedConfig.GetConfiguredObject()))
                throw new Exception("SetConfiguredObject failed!");
        }
开发者ID:madelson,项目名称:Emotiv-Experimenter,代码行数:37,代码来源:ControlTests.cs

示例2: Run

        public static void Run()
        {
            var foo = new Foo();
            var parameters = foo.GetParameters().ToIArray();

            // check count
            if (parameters.Count != 2)
                throw new Exception("Bad parameter count: " + parameters.Count);

            // check default values
            foo.SetParametersToDefaultValues();
            foreach (var param in parameters)
                if (param.HasDefaultValue() && !foo.GetProperty(param.Property).Equals(param.DefaultValue))
                    throw new Exception("Parameter " + param.Property.Name + " has value " + foo.GetProperty(param.Property) + " instead of default value " + param.DefaultValue);

            // check min/max
            foo.I = (int)parameters.Where(p => p.Description == "I").First().MinValue - 1;
            string errorMessage;
            if (foo.AreParameterValuesValid(out errorMessage))
                throw new Exception("MinValue check failed!");
            foo.I = (int)parameters.Where(p => p.Description == "I").First().MaxValue + 1;
            if (foo.AreParameterValuesValid(out errorMessage))
                throw new Exception("MaxValue check failed!");

            // check transfer
            foo.SetParametersToDefaultValues();
            var foo2 = new Foo();
            foo.TransferParameterValuesTo(foo2);
            foreach (var param in parameters)
                if (!foo.GetProperty(param.Property).Equals(foo2.GetProperty(param.Property)))
                    throw new Exception("Property transfer failed on " + param.Property.Name);

            // check factory
            foo.S += "suffix";
            var factory = foo.GetFactory();
            for (int i = 0; i < 3; i++)
            {
                foo2 = (Foo)factory();
                if (foo2.I != foo.I || foo2.S != foo.S)
                    throw new Exception("Factory failed!");
            }

            // check parameter equals
            foo.SetParametersToDefaultValues();
            foo2.SetParametersToDefaultValues();
            if (!foo.HasEqualParameters(foo2))
                throw new Exception("Equals check failed on equal objects");
            foo.S = "different";
            if (foo.HasEqualParameters(foo2))
                throw new Exception("Equals check failed on unequal objects");

            // check description
            if (typeof(Foo).DisplayName() != "?")
                throw new Exception("DisplayName failed!");
            if (typeof(Foo).Description() != "D")
                throw new Exception("Description failed!");

            // check enum
            foreach (Enum value in Enum.GetValues(typeof(X)))
                if (!value.GetDescriptionForEnum().Description.Equals(value.ToString().ToLower()))
                    throw new Exception("GetDescription for enum failed!");
        }
开发者ID:madelson,项目名称:Emotiv-Experimenter,代码行数:62,代码来源:ParameterTests.cs


注:本文中的System.Foo.HasEqualParameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。