public static T[] ToArray <T>(this string str, ToValue <T> parser, params char[] separator) { if (null == str) { return(new T[0]); } var split = str.Split(separator); var values = new T[split.Length]; for (int n = 0, cnt = split.Length; n < cnt; ++n) { try { values[n] = parser(split[n]); } catch (Exception e) { throw new ToArrayFailedException { Index = n, Split = split[n], Str = str, Except = e, }; } } return(values); }
/// <summary> /// Initializes a new instance of the <see cref="RepresentationMapRefMutableCore"/> class. /// </summary> /// <param name="representationMapRef"> /// The iref. /// </param> public RepresentationMapRefMutableCore(IRepresentationMapRef representationMapRef) : base(representationMapRef) { this.valueMappings = new DictionaryOfSets<string, string>(); if (representationMapRef.CodelistMap != null) { this.codelistMap = representationMapRef.CodelistMap.CreateMutableInstance(); } if (representationMapRef.ToTextFormat != null) { this.toTextFormat = new TextFormatMutableCore(representationMapRef.ToTextFormat); } this.toValueType = representationMapRef.ToValueType; this.valueMappings = representationMapRef.ValueMappings; }
/////////////////////////////////////////////////////////////////////////////////////////////////// ////////////BUILD FROM V2 SCHEMA ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes a new instance of the <see cref="RepresentationMapRefCore"/> class. /// </summary> /// <param name="textFormatType"> /// The text format type. /// </param> /// <param name="toValueType"> /// The to value type. /// </param> /// <param name="parent"> /// The parent. /// </param> public RepresentationMapRefCore(TextFormatType textFormatType, string toValueType, ISdmxStructure parent) : base(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.RepresentationMap), parent) { this.valueMappings = new DictionaryOfSets<string, string>(); this.toTextFormat = new TextFormatObjectCore(textFormatType, this); if (toValueType != null) { switch (toValueType) { case Org.Sdmx.Resources.SdmxMl.Schemas.V20.structure.ToValueTypeTypeConstants.Description: this.toValueType = ToValue.Description; break; case Org.Sdmx.Resources.SdmxMl.Schemas.V20.structure.ToValueTypeTypeConstants.Name: this.toValueType = ToValue.Name; break; case Org.Sdmx.Resources.SdmxMl.Schemas.V20.structure.ToValueTypeTypeConstants.Value: this.toValueType = ToValue.Value; break; } } this.Validate(); }
/// <summary> /// Initializes a new instance of the <see cref="RepresentationMapRefCore"/> class. /// </summary> /// <param name="xref"> /// The xref. /// </param> /// <param name="parent"> /// The parent. /// </param> /// <exception cref="SdmxSemmanticException"> /// Throws Validate exception. /// </exception> protected internal RepresentationMapRefCore(IRepresentationMapRefMutableObject xref, ISdmxStructure parent) : base(xref, parent) { this.valueMappings = new DictionaryOfSets<string, string>(); if (xref.CodelistMap != null) { this.codelistMap = new CrossReferenceImpl(this, xref.CodelistMap); } if (xref.ToTextFormat != null) { this.toTextFormat = new TextFormatObjectCore(xref.ToTextFormat, this); } if (xref.ValueMappings != null) { this.valueMappings = new DictionaryOfSets<string, string>(xref.ValueMappings); } this.toValueType = xref.ToValueType; try { this.Validate(); } catch (SdmxSemmanticException ex) { throw new SdmxSemmanticException(ex, ExceptionCode.ObjectStructureConstructionError, this); } catch (Exception th) { throw new SdmxException(th, ExceptionCode.ObjectStructureConstructionError, this); } }
/////////////////////////////////////////////////////////////////////////////////////////////////// ////////////BUILD FROM MUTABLE OBJECTS ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// ////////////BUILD FROM V21 SCHEMA ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// #region Constructors and Destructors /// <summary> /// Initializes a new instance of the <see cref="RepresentationMapRefCore"/> class. /// </summary> /// <param name="representationMapType"> /// The iref. /// </param> /// <param name="parent"> /// The parent. /// </param> /// <exception cref="SdmxSemmanticException"> /// Throws Validate exception. /// </exception> public RepresentationMapRefCore(RepresentationMapType representationMapType, ISdmxStructure parent) : base(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.RepresentationMap), parent) { this.valueMappings = new DictionaryOfSets<string, string>(); if (representationMapType.CodelistMap != null) { // Local Reference string agencyId = this.MaintainableParent.AgencyId; string maintainableId = this.MaintainableParent.Id; string version = this.MaintainableParent.Version; this.codelistMap = new CrossReferenceImpl( this, agencyId, maintainableId, version, SdmxStructureEnumType.CodeListMap, representationMapType.CodelistMap.GetTypedRef<LocalCodelistMapRefType>().id); } if (representationMapType.ToTextFormat != null) { this.toTextFormat = new TextFormatObjectCore(representationMapType.ToTextFormat, this); } if (representationMapType.ToValueType != null) { switch (representationMapType.ToValueType) { case ToValueTypeTypeConstants.Description: this.toValueType = ToValue.Description; break; case ToValueTypeTypeConstants.Name: this.toValueType = ToValue.Name; break; case ToValueTypeTypeConstants.Value: this.toValueType = ToValue.Value; break; } } if (representationMapType.ValueMap != null) { foreach (ValueMappingType vmt in representationMapType.ValueMap.ValueMapping) { ISet<string> mappings = valueMappings[vmt.source]; if (mappings==null) { mappings = new HashSet<string>(); valueMappings.Add(vmt.source, mappings); } mappings.Add(vmt.target); } } try { this.Validate(); } catch (SdmxSemmanticException ex) { throw new SdmxSemmanticException(ex, ExceptionCode.ObjectStructureConstructionError, this); } catch (Exception th) { throw new SdmxException(th, ExceptionCode.ObjectStructureConstructionError, this); } }