/// <summary> /// Fabricates the entity. /// </summary> /// <param name="fabricator">The fabricator.</param> /// <param name="data">The data.</param> /// <param name="dataType">Type of the data.</param> /// <param name="throwError">if set to <c>true</c> [throw error].</param> /// <returns></returns> public static object Fabricate(this SchemaFabricator fabricator, string data, string dataType, bool throwError) { var eventBytes = System.Text.Encoding.UTF8.GetBytes(data); var dictionaryReader = JsonReaderWriterFactory.CreateJsonReader( eventBytes, 0, eventBytes.Length, new XmlDictionaryReaderQuotas()); var fabricatorType = fabricator.GetType(dataType); if (fabricatorType == null) { // We should consider the possibility that form of type instantiation could // be used to instantiate types that the host doesn't want instantiated. There // needs to be a way to blacklist or whitelist types. if (WhiteList.Contains(dataType)) { fabricatorType = TypeHelper.ResolveType(dataType, false); } } if (fabricatorType != null) { var serializer = new DataContractJsonSerializer(fabricatorType); var trueEntity = serializer.ReadObject(dictionaryReader); return(trueEntity); } if (throwError) { throw new EPException(string.Format("Unable to fabricate object of type {0}", dataType)); } return(null); }
/// <summary> /// Fabricates the entity. /// </summary> /// <param name="fabricator">The fabricator.</param> /// <param name="data">The data.</param> /// <param name="dataType">Type of the data.</param> /// <returns></returns> public static object Fabricate(this SchemaFabricator fabricator, string data, string dataType) { return(Fabricate(fabricator, data, dataType, true)); }