/// <summary> /// Initializes a new instance of the <see cref="VertexElement" /> struct. /// </summary> /// <param name="semanticName">Name of the semantic.</param> /// <param name="semanticIndex">Index of the semantic.</param> /// <param name="format">The format.</param> /// <param name="alignedByteOffset">The aligned byte offset.</param> public VertexElement(string semanticName, int semanticIndex, Format format, int alignedByteOffset = AppendAligned) : this() { if (semanticName == null) { throw new ArgumentNullException("semanticName"); } // All semantics will be upper case. semanticName = semanticName.ToUpperInvariant(); var match = MatchSemanticIndex.Match(semanticName); if (match.Success) { throw new ArgumentException("Semantic name cannot a semantic index when using constructor with explicit semantic index. Use implicit semantic index constructor."); } // Convert to singleton string in order to speed up things. this.semanticName = (SingletonString)semanticName; this.semanticIndex = semanticIndex; this.format = format; this.alignedByteOffset = alignedByteOffset; // Precalculate hashcode hashCode = ComputeHashCode(); }
/// <summary> /// Initializes a new instance of the <see cref="VertexElement" /> struct. /// </summary> /// <param name="semanticName">Name of the semantic.</param> /// <param name="format">The format.</param> /// <remarks> /// If the semantic name contains a postfix number, this number will be used as a semantic index. /// </remarks> public VertexElement(string semanticName, Format format) : this() { if (semanticName == null) { throw new ArgumentNullException("semanticName"); } // All semantics will be upper case. semanticName = semanticName.ToUpperInvariant(); var match = MatchSemanticIndex.Match(semanticName); if (match.Success) { // Convert to singleton string in order to speed up things. this.semanticName = (SingletonString)match.Groups[1].Value; semanticIndex = int.Parse(match.Groups[2].Value); } else { this.semanticName = (SingletonString)semanticName; } this.format = format; alignedByteOffset = AppendAligned; // Precalculate hashcode hashCode = ComputeHashCode(); }
public static ModifiablePropertyType GetProperty(KeyValuePair<string, object> dmsPropertyValue) { var dmsProperty = default(ModifiablePropertyType); if (dmsPropertyValue.Value == null) { dmsProperty = new SingletonString { Value = null }; } else { var propertyType = dmsPropertyValue.Value.GetType(); if (propertyType == typeof(string)) { dmsProperty = new SingletonString { Value = Convert.ToString(dmsPropertyValue.Value) }; } else if (propertyType == typeof(bool) || propertyType == typeof(bool?)) { dmsProperty = new SingletonBoolean { Value = Convert.ToBoolean(dmsPropertyValue.Value), ValueSpecified = true }; } else if (propertyType == typeof(int) || propertyType == typeof(int?)) { dmsProperty = new SingletonInteger32 { Value = Convert.ToInt32(dmsPropertyValue.Value), ValueSpecified = true }; } else if (propertyType == typeof(float) || propertyType == typeof(float?) || propertyType == typeof(double) || propertyType == typeof(double?)) { dmsProperty = new SingletonFloat64 { Value = Convert.ToDouble(dmsPropertyValue.Value), ValueSpecified = true }; } else if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?)) { dmsProperty = new SingletonDateTime { Value = Convert.ToDateTime(dmsPropertyValue.Value), ValueSpecified = true }; } else if (propertyType == typeof(Guid) || propertyType == typeof(Guid?)) { dmsProperty = new SingletonId { Value = ((Guid)dmsPropertyValue.Value).ToString() }; } else if (propertyType == typeof(string[])) { dmsProperty = new ListOfString { Value = (string[])dmsPropertyValue.Value }; } else if (propertyType == typeof(List<string>)) { dmsProperty = new ListOfString { Value = ((List<string>)dmsPropertyValue.Value).ToArray() }; } else { throw new NotImplementedException(propertyType.FullName); } } dmsProperty.propertyId = dmsPropertyValue.Key; return dmsProperty; }