本文整理匯總了C#中System.Foo.GetFactory方法的典型用法代碼示例。如果您正苦於以下問題:C# Foo.GetFactory方法的具體用法?C# Foo.GetFactory怎麽用?C# Foo.GetFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Foo
的用法示例。
在下文中一共展示了Foo.GetFactory方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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!");
}