IsValid() 개인적인 메소드

private IsValid ( ITypeDescriptorContext context, object value ) : bool
context ITypeDescriptorContext
value object
리턴 bool
예제 #1
0
			private void DeserializeBoxSettings(AnnotationBox boxSettings, XmlElement boxSettingsNode)
			{
				string font = boxSettingsNode.GetAttribute("font");
				string color = boxSettingsNode.GetAttribute("color");
				string italics = boxSettingsNode.GetAttribute("italics");
				string bold = boxSettingsNode.GetAttribute("bold");
				string numberOfLines = boxSettingsNode.GetAttribute("number-of-lines");
				string truncation = boxSettingsNode.GetAttribute("truncation");
				string justification = boxSettingsNode.GetAttribute("justification");
				string verticalAlignment = boxSettingsNode.GetAttribute("vertical-alignment");
				string fitWidth = boxSettingsNode.GetAttribute("fit-width");
				string alwaysVisible = boxSettingsNode.GetAttribute("always-visible");

				if (!String.IsNullOrEmpty(font))
					boxSettings.Font = font;
				if (!String.IsNullOrEmpty(color))
					boxSettings.Color = color;
				if (!String.IsNullOrEmpty(italics))
					boxSettings.Italics = (String.Compare("true", italics, true) == 0);
				if (!String.IsNullOrEmpty(bold))
					boxSettings.Bold = (String.Compare("true", bold, true) == 0);
				if (!String.IsNullOrEmpty(numberOfLines))
				{
					byte result;
					if (!byte.TryParse(numberOfLines, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out result))
						result = 1;

					boxSettings.NumberOfLines = result;
				}

				if (!String.IsNullOrEmpty(fitWidth))
					boxSettings.FitWidth = (String.Compare("true", fitWidth) == 0);

				if (!String.IsNullOrEmpty(alwaysVisible))
					boxSettings.AlwaysVisible = (String.Compare("true", alwaysVisible, true) == 0);

				if (!String.IsNullOrEmpty(truncation))
				{
					AnnotationBox.TruncationBehaviour fromString = boxSettings.Truncation;
					EnumConverter converter = new EnumConverter(typeof(AnnotationBox.TruncationBehaviour));
					if (converter.IsValid(truncation))
						boxSettings.Truncation = (AnnotationBox.TruncationBehaviour)converter.ConvertFromString(truncation);
				}

				if (!String.IsNullOrEmpty(justification))
				{
					AnnotationBox.JustificationBehaviour fromString = boxSettings.Justification;
					EnumConverter converter = new EnumConverter(typeof(AnnotationBox.JustificationBehaviour));
					if (converter.IsValid(justification))
						boxSettings.Justification = (AnnotationBox.JustificationBehaviour)converter.ConvertFromString(justification);
				}

				if (!String.IsNullOrEmpty(verticalAlignment))
				{
					AnnotationBox.VerticalAlignmentBehaviour fromString = boxSettings.VerticalAlignment;
					EnumConverter converter = new EnumConverter(typeof(AnnotationBox.VerticalAlignmentBehaviour));
					if (converter.IsValid(verticalAlignment))
						boxSettings.VerticalAlignment = (AnnotationBox.VerticalAlignmentBehaviour)converter.ConvertFromString(verticalAlignment);
				}

				XmlElement configurationSettings = (XmlElement)boxSettingsNode.SelectSingleNode("configuration-settings");
				if (configurationSettings != null)
				{
					string showLabel = configurationSettings.GetAttribute("show-label");
					string showLabelIfEmpty = configurationSettings.GetAttribute("show-label-if-empty");
					if (!String.IsNullOrEmpty(showLabel))
						boxSettings.ConfigurationOptions.ShowLabel = (String.Compare("true", showLabel, true) == 0);
					if (!String.IsNullOrEmpty(showLabelIfEmpty))
						boxSettings.ConfigurationOptions.ShowLabelIfValueEmpty = (String.Compare("true", showLabelIfEmpty, true) == 0);
				}
			}
 public override bool IsValid(ITypeDescriptorContext context, object value)
 {
     if (value != null)
     {
         if (value.GetType() == this.m_Type)
         {
             return true;
         }
         if (value.GetType() != typeof(string))
         {
             return false;
         }
         char[] separator = new char[] { '\n' };
         string[] strArray = ((string) value).Split(separator);
         if (strArray.Length < 2)
         {
             return false;
         }
         EnumConverter converter = new EnumConverter(typeof(WrapMode));
         if (!converter.IsValid(strArray[0]))
         {
             return false;
         }
         if (!converter.IsValid(strArray[1]))
         {
             return false;
         }
         for (int i = 2; i < strArray.Length; i++)
         {
             char[] chArray2 = new char[] { ',' };
             string[] strArray2 = strArray[i].Split(chArray2);
             if (strArray2.Length != 4)
             {
                 return false;
             }
             foreach (string str in strArray2)
             {
                 float num3;
                 if (!float.TryParse(str, NumberStyles.Float, CultureInfo.InvariantCulture, out num3))
                 {
                     return false;
                 }
             }
         }
     }
     return true;
 }