本文整理汇总了C#中Structure.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Structure.GetType方法的具体用法?C# Structure.GetType怎么用?C# Structure.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Structure
的用法示例。
在下文中一共展示了Structure.GetType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteRss
public static void WriteRss(Structure.RssFeed value, Stream destination)
{
var xsn = new XmlSerializerNamespaces();
xsn.Add("atom", "http://www.w3.org/2005/Atom");
xsn.Add("dc", "http://purl.org/dc/elements/1.1/");
xsn.Add("content", "http://purl.org/rss/1.0/modules/content/");
var ser = new XmlSerializer(value.GetType());
ser.Serialize(destination, value, xsn);
}
示例2: IsLegalValue
/// <summary>
/// Return true if the value given is allowed for the field given. This uses the hints from the GUI
/// system to decide what is and isn't allowed. (For example if a GUI slider goes from 10 to 20 at
/// increments of 2, then a value of 17 is not something you could achieve in the GUI, being only able
/// to go from 16 to 18 skipping over 17, and therefore this routine would return false for trying to
/// set it to 17).
/// <br/><br/>
/// Note that the value passed in may be altered (which is why it's ref) when it's not
/// exactly legal, but it's CLOSE ENOUGH to be coerced into a legal value. For example,
/// you set a slider to 10.45 and the slider only allows values on the 0.5 marks like 10, 10.5, 11. etc.
/// Rather than deny the attempt, the value will be nudged to the nearest legal value.
/// </summary>
/// <param name="field">Which KSPField is being checked?</param>
/// <param name="newVal">What is the value it's being set to? It is possible to
/// alter the value to an acceptable replacement which is why it passes by ref</param>
/// <param name="except">An exception you can choose to throw if you want, or null if the value is legal.</param>
/// <returns>Is it legal?</returns>
private bool IsLegalValue(BaseField field, ref Structure newVal, out KOSException except)
{
except = null;
bool isLegal = true;
Type fType = field.FieldInfo.FieldType;
object convertedVal = newVal;
if (!IsEditable(field))
{
except = new KOSInvalidFieldValueException("Field is read-only");
return false;
}
if (!newVal.GetType().IsSubclassOf(fType))
{
try
{
convertedVal = Convert.ChangeType(newVal, fType);
}
catch (InvalidCastException)
{
except = new KOSCastException(newVal.GetType(), fType);
return false;
}
catch (FormatException)
{
except = new KOSCastException(newVal.GetType(), fType);
return false;
}
}
List<UI_Control> controls = GetFieldControls(field);
// It's really normal for there to be only one control on a KSPField, but because
// it's technically possible to have more than one according to the structure of
// the API, this loop is here to check all of "them":
foreach (UI_Control control in controls)
{
// Some of these are subclasses of each other, so don't change this to an if/else.
// It's a series of if's on purpose so it checks all classes the control is derived from.
if (control is UI_Toggle)
{
// Seems there's nothing to check here, but maybe later there will be?
}
if (control is UI_Label)
{
except = new KOSInvalidFieldValueException("Labels are read-only objects that can't be changed");
isLegal = false;
}
var vector2 = control as UI_Vector2;
if (vector2 != null)
{
// I have no clue what this actually looks like in the UI? What is a
// user editable 2-D vector widget? I've never seen this before.
if (convertedVal != null)
{
var vec2 = (Vector2)convertedVal;
if (vec2.x < vector2.minValueX || vec2.x > vector2.maxValueX ||
vec2.y < vector2.minValueY || vec2.y > vector2.maxValueY)
{
except = new KOSInvalidFieldValueException("Vector2 is outside of allowed range of values");
isLegal = false;
}
}
}
var range = control as UI_FloatRange;
if (range != null)
{
float val = Convert.ToSingle(convertedVal);
val = KOSMath.ClampToIndent(val, range.minValue, range.maxValue, range.stepIncrement);
convertedVal = Convert.ToDouble(val);
}
if (!isLegal)
break;
}
newVal = FromPrimitiveWithAssert(convertedVal);
return isLegal;
}
示例3: testStructure
/// <summary> Tests a structure (segment or group) against the corresponding part of a profile. </summary>
public virtual NuGenHL7Exception[] testStructure(Structure s, ProfileStructure profile, System.String profileID)
{
System.Collections.ArrayList exList = new System.Collections.ArrayList(20);
if (profile is Seg)
{
if (typeof(Segment).IsAssignableFrom(s.GetType()))
{
addToList(testSegment((Segment) s, (Seg) profile, profileID), exList);
}
else
{
exList.Add(new NuGenProfileNotHL7CompliantException("Mismatch between a segment in the profile and the structure " + s.GetType().FullName + " in the message"));
}
}
else if (profile is SegGroup)
{
if (typeof(Group).IsAssignableFrom(s.GetType()))
{
addToList(testGroup((Group) s, (SegGroup) profile, profileID), exList);
}
else
{
exList.Add(new NuGenProfileNotHL7CompliantException("Mismatch between a group in the profile and the structure " + s.GetType().FullName + " in the message"));
}
}
return toArray(exList);
}
示例4: hasContent
/// <summary> Tests a composite against the corresponding section of a profile.</summary>
/*public HL7Exception[] testComposite(Composite comp, AbstractComposite profile) {
}*/
/// <summary> Tests a primitive datatype against a profile. Tests include
/// length, datatype, whether the profile defines any children
/// (this would indicate an error), constant value if defined.
/// Table values are not verified.
/// </summary>
/*public Hl7Exception[] testPrimitive(Primitive, AbstractComponent profile) {
}*/
/// <summary>Returns true is there is content in the given structure </summary>
private bool hasContent(Structure struct_Renamed)
{
if (typeof(Group).IsAssignableFrom(struct_Renamed.GetType()))
{
return hasContent((Group) struct_Renamed);
}
else if (typeof(Segment).IsAssignableFrom(struct_Renamed.GetType()))
{
return hasContent((Segment) struct_Renamed);
}
else
{
throw new NuGenHL7Exception("Structure " + struct_Renamed.GetType().FullName + " not recognized", NuGenHL7Exception.APPLICATION_INTERNAL_ERROR);
}
}
示例5: contains
/// <summary> Determines whether the given structure matches the given name, or contains
/// a child that does.
/// </summary>
/// <param name="s">the structure to check
/// </param>
/// <param name="name">the name to look for
/// </param>
/// <param name="firstDescendentsOnly">only checks first descendents (i.e. first
/// child, first child of first child, etc.) In theory the first child
/// of a group should always be present, and we don't use this method with
/// subsequent children because finding the next position within a group is
/// straightforward.
/// </param>
/// <param name="upToFirstRequired">only checks first descendents and of their siblings
/// up to the first required one. This may be needed because in practice
/// some first children of groups are not required.
/// </param>
public static bool contains(Structure s, System.String name, bool firstDescendentsOnly, bool upToFirstRequired)
{
bool contains = false;
if (typeof(Segment).IsAssignableFrom(s.GetType()))
{
if (s.getStructureName().Equals(name))
contains = true;
}
else
{
Group g = (Group) s;
System.String[] names = g.Names;
for (int i = 0; i < names.Length && !contains; i++)
{
try
{
contains = MessageIterator.contains(g.get_Renamed(names[i], 0), name, firstDescendentsOnly, upToFirstRequired);
if (firstDescendentsOnly)
break;
if (upToFirstRequired && g.isRequired(names[i]))
break;
}
catch (HL7Exception e)
{
//UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
throw new System.ApplicationException("HL7Exception due to bad index: " + e.Message);
}
}
}
return contains;
}