本文整理汇总了C#中PrivateType.GetStaticFieldOrProperty方法的典型用法代码示例。如果您正苦于以下问题:C# PrivateType.GetStaticFieldOrProperty方法的具体用法?C# PrivateType.GetStaticFieldOrProperty怎么用?C# PrivateType.GetStaticFieldOrProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PrivateType
的用法示例。
在下文中一共展示了PrivateType.GetStaticFieldOrProperty方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InstanceTest
public void InstanceTest()
{
try
{
InvisibleForm actual;
actual = InvisibleForm.Instance;
Assert.IsNotNull(actual, "InvisibleForm.Instance returned null");
// Reset and try again
PrivateType invisibleForm = new PrivateType(typeof(InvisibleForm));
invisibleForm.SetStaticFieldOrProperty("instanceForm", null);
actual = InvisibleForm.Instance;
Assert.IsNotNull(actual, "InvisibleForm.Instance returned null");
Assert.AreSame(actual, invisibleForm.GetStaticFieldOrProperty("instanceForm"), "Second call to the property should return the same opbject instance.");
Form f = actual as Form;
Assert.IsFalse(f.Visible, "InvisibleForm should not be visible");
}
catch (Exception ex)
{
// Use try catch to test a workaround on CI build (AppVeyor)
Console.WriteLine(ex.Message);
}
}
示例2: InstanceTest
public void InstanceTest()
{
InvisibleForm actual;
actual = InvisibleForm.Instance;
Assert.IsNotNull(actual, "InvisibleForm.Instance returned null");
// Reset and try again
PrivateType invisibleForm = new PrivateType(typeof(InvisibleForm));
invisibleForm.SetStaticFieldOrProperty("instanceForm", null);
actual = InvisibleForm.Instance;
Assert.IsNotNull(actual, "InvisibleForm.Instance returned null");
Assert.AreSame(actual, invisibleForm.GetStaticFieldOrProperty("instanceForm"), "Second call to the property should return the same opbject instance.");
Form f = actual as Form;
Assert.IsFalse(f.Visible, "InvisibleForm should not be visible");
}
示例3: FieldValidation_Password
public void FieldValidation_Password()
{
string ctd;
bool isValid;
FieldValidationResult validationResult;
PrivateType fieldSettingAccessor = new PrivateType(typeof(PasswordFieldSetting));
string minLengthError = (string)fieldSettingAccessor.GetStaticFieldOrProperty("MinLengthName");
string maxLengthError = (string)fieldSettingAccessor.GetStaticFieldOrProperty("MaxLengthName");
string regexError = (string)fieldSettingAccessor.GetStaticFieldOrProperty("RegexName");
//string compulsoryError = (string)fieldSettingAccessor.GetStaticFieldOrProperty("CompulsoryName");
//====
ctd = @"<?xml version='1.0' encoding='utf-8'?>
<ContentType name='ValidatedContent' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'>
<Fields>
<Field name='PasswordTest' type='Password'>
<Configuration>
<MinLength>3</MinLength>
<MaxLength>8</MaxLength>
<Regex>^[a-zA-Z0-9]*$</Regex>
</Configuration>
</Field>
</Fields>
</ContentType>";
ContentTypeInstaller.InstallContentType(ctd);
SNC.Content content = SNC.Content.CreateNew("ValidatedContent", _testRoot, "abc");
content["PasswordTest"] = new PasswordField.PasswordData { Text = "ab" };
isValid = content.IsValid;
validationResult = content.Fields["PasswordTest"].ValidationResult;
Assert.IsFalse(isValid, "#1");
Assert.IsTrue(validationResult.Category == ShortTextFieldSetting.MinLengthName, "#2");
Assert.IsTrue((int)content.Fields["PasswordTest"].ValidationResult.GetParameter(ShortTextFieldSetting.MinLengthName) == 3, "#3");
content["PasswordTest"] = new PasswordField.PasswordData { Text = "abcdefgh01" };
isValid = content.IsValid;
Assert.IsFalse(isValid, "#4");
Assert.IsTrue(content.Fields["PasswordTest"].ValidationResult.Category == ShortTextFieldSetting.MaxLengthName, "#5");
Assert.IsTrue((int)content.Fields["PasswordTest"].ValidationResult.GetParameter(ShortTextFieldSetting.MaxLengthName) == 8, "#6");
content["PasswordTest"] = new PasswordField.PasswordData { Text = "[email protected]#$%^" };
isValid = content.IsValid;
Assert.IsFalse(isValid, "#7");
Assert.IsTrue(content.Fields["PasswordTest"].ValidationResult.Category == ShortTextFieldSetting.RegexName, "#8");
content["PasswordTest"] = new PasswordField.PasswordData { Text = "Correct" };
isValid = content.IsValid;
Assert.IsTrue(isValid, "#9");
}
示例4: FieldValidation_Xml
public void FieldValidation_Xml()
{
string ctd;
bool isValid;
FieldValidationResult validationResult;
PrivateType fieldSettingAccessor = new PrivateType(typeof(XmlFieldSetting));
string compulsoryError = (string)fieldSettingAccessor.GetStaticFieldOrProperty("CompulsoryName");
string namespaceError = (string)fieldSettingAccessor.GetStaticFieldOrProperty("ExpectedXmlNamespaceName");
string notWellformedXmlError = (string)fieldSettingAccessor.GetStaticFieldOrProperty("NotWellformedXmlName");
//====
ctd = @"<?xml version='1.0' encoding='utf-8'?>
<ContentType name='ContentWithXmlField' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'>
<Fields>
<Field name='XmlTest' type='Xml'>
<Configuration>
<ExpectedXmlNamespace>htp://example.com/namespace</ExpectedXmlNamespace>
</Configuration>
</Field>
</Fields>
</ContentType>";
ContentTypeInstaller.InstallContentType(ctd);
SNC.Content content = SNC.Content.CreateNew("ContentWithXmlField", _testRoot, null);
//----
content["XmlTest"] = null;
Assert.IsTrue(content.IsValid, "#1");
//----
content["XmlTest"] = "<a xmlns='htp://example.com/namespace'><b>content</b></a>";
Assert.IsTrue(content.IsValid, "#2");
//----
content["XmlTest"] = "";
isValid = content.IsValid;
validationResult = content.Fields["XmlTest"].ValidationResult;
Assert.IsFalse(isValid, "#3");
Assert.IsTrue(validationResult.Category == notWellformedXmlError, "#4");
//----
content["XmlTest"] = "<a xmlns='htp://example.com/namespace'><b>content<b></a>";
isValid = content.IsValid;
validationResult = content.Fields["XmlTest"].ValidationResult;
Assert.IsFalse(isValid, "#5");
Assert.IsTrue(validationResult.Category == notWellformedXmlError, "#6");
//----
content["XmlTest"] = "<a><b>content</b></a>";
isValid = content.IsValid;
validationResult = content.Fields["XmlTest"].ValidationResult;
Assert.IsFalse(isValid, "#7");
Assert.IsTrue(validationResult.Category == namespaceError, "#8");
//=======================
ctd = @"<?xml version='1.0' encoding='utf-8'?>
<ContentType name='ContentWithXmlField' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'>
<Fields>
<Field name='XmlTest' type='Xml'>
<Configuration>
<Compulsory>true</Compulsory>
<ExpectedXmlNamespace>htp://example.com/namespace</ExpectedXmlNamespace>
</Configuration>
</Field>
</Fields>
</ContentType>";
ContentTypeInstaller.InstallContentType(ctd);
content = SNC.Content.CreateNew("ContentWithXmlField", _testRoot, null);
content["XmlTest"] = null;
isValid = content.IsValid;
validationResult = content.Fields["XmlTest"].ValidationResult;
Assert.IsFalse(isValid, "#9");
Assert.IsTrue(validationResult.Category == compulsoryError, "#10");
//=======================
content["XmlTest"] = "<a xmlns='htp://example.com/namespace'><b>content</b></a>";
var sb = new StringBuilder();
var writer = XmlWriter.Create(sb);
writer.WriteStartDocument();
writer.WriteStartElement("root");
content.Fields["XmlTest"].Export(writer, new ExportContext("/Root", "c:\\"));
writer.WriteEndElement();
writer.Flush();
writer.Close();
//.........这里部分代码省略.........
示例5: FieldValidation_ShortText_Compulsory
public void FieldValidation_ShortText_Compulsory()
{
string ctd;
bool isValid;
FieldValidationResult validationResult;
PrivateType fieldSettingAccessor = new PrivateType(typeof(ShortTextFieldSetting));
string compulsoryError = (string)fieldSettingAccessor.GetStaticFieldOrProperty("CompulsoryName");
//====
ctd = @"<?xml version='1.0' encoding='utf-8'?>
<ContentType name='ValidatedContent' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'>
<Fields>
<Field name='ShortTextTest' type='ShortText'>
<Configuration>
<Compulsory>true</Compulsory>
<MinLength>3</MinLength>
<MaxLength>8</MaxLength>
<Regex>^[a-zA-Z0-9]*$</Regex>
</Configuration>
</Field>
</Fields>
</ContentType>";
ContentTypeInstaller.InstallContentType(ctd);
SNC.Content content = SNC.Content.CreateNew("ValidatedContent", _testRoot, "abc");
content["ShortTextTest"] = null;
isValid = content.IsValid;
validationResult = content.Fields["ShortTextTest"].ValidationResult;
Assert.IsFalse(isValid, "#1");
Assert.IsTrue(validationResult.Category == compulsoryError, "#2");
content["ShortTextTest"] = "";
isValid = content.IsValid;
validationResult = content.Fields["ShortTextTest"].ValidationResult;
Assert.IsFalse(isValid, "#3");
Assert.IsTrue(validationResult.Category == compulsoryError, "#4");
content["ShortTextTest"] = "Correct";
isValid = content.IsValid;
Assert.IsTrue(isValid, "#5");
}