/// <inheritdoc />
        public TDbcToType Convert(TDbcFromType fromObject)
        {
            TDbcToType entry = new TDbcToType();

            //We use reflection now to set members, it is fast with fasterflect
            foreach (MemberInfo mi in OriginalSerializableMemberInfos)
            {
                //TODO: The set and get might be slow. We could build a table for this.
                //Strings need special handling
                if (mi.Type() == typeof(LocalizedStringDBC <string>))
                {
                    entry.SetPropertyValue(mi.Name, LocalizedStringConverter.Convert((LocalizedStringDBC <StringDBCReference>)fromObject.GetPropertyValue(mi.Name)));
                }
                else if (mi.Type() == typeof(string))
                {
                    //Sets the entry with the value from the original object.
                    entry.SetPropertyValue(mi.Name, StringReferenceConverter.Convert((StringDBCReference)fromObject.GetPropertyValue(mi.Name)));
                }
            }

            return(entry);
        }
Example #2
0
        /// <inheritdoc />
        public TDbcToType Convert(TDbcFromType fromObject)
        {
            TDbcToType entry = new TDbcToType();

            //We use reflection now to set members, it is fast with fasterflect
            foreach (MemberInfo mi in OriginalSerializableMemberInfos)
            {
                //TODO: The set and get might be slow. We could build a table for this.
                //Strings need special handling
                if (mi.Type() == typeof(LocalizedStringDBC <string>))
                {
                    entry.SetPropertyValue(mi.Name, LocalizedStringConverter.Convert((LocalizedStringDBC <StringDBCReference>)fromObject.GetPropertyValue(mi.Name)));
                }
                else if (mi.Type() == typeof(string))
                {
                    //Sets the entry with the value from the original object.
                    entry.SetPropertyValue(mi.Name, StringReferenceConverter.Convert((StringDBCReference)fromObject.GetPropertyValue(mi.Name)));
                }
                else if (mi.Type().Name.Contains("GenericStaticallySizedArrayChunk") && mi.Type().GenericTypeArguments[0] == typeof(string))
                {
                    object arrayObject = Activator.CreateInstance(mi.Type());

                    //for types with GenericStaticallySizedArrayChunk so we can set the members
                    foreach (MemberInfo arrayChunkMemberInfo in ComputeSerializableMembers(mi.Type()))
                    {
                        arrayObject.SetPropertyValue(arrayChunkMemberInfo.Name, StringReferenceConverter.Convert((StringDBCReference)fromObject.GetPropertyValue(mi.Name).GetPropertyValue(arrayChunkMemberInfo.Name)));
                    }

                    entry.SetPropertyValue(mi.Name, arrayObject);
                }
                else
                {
                    entry.SetPropertyValue(mi.Name, fromObject.GetPropertyValue(mi.Name));                     //else it's a normal field so it should directly be set.
                }
            }

            return(entry);
        }
        /// <inheritdoc />
        public TDbcToType Convert(TDbcFromType fromObject)
        {
            TDbcToType entry = new TDbcToType();

            //TODO: Refactor this to generic so it can shared with CreateDatabase project
            //We use reflection now to set members, it is fast with fasterflect
            foreach (MemberInfo mi in entry.GetType().MembersWith(MemberTypes.Property, typeof(WireMemberAttribute)))
            {
                //THIS IS WRONG. WE HAVE TO DO NON-MAPPED BECAUSE THEY WILL BE NULL OTHERWISE
                //So, for table to file there may be some unmapped but serializable fields (probably set with defaults)
                //and we need to NOT try to set or read these non-mapped fields. It should remain the default values assigned
                //if you do try you'll get exceptions.
                //if(mi.HasAttribute<NotMappedAttribute>())
                //	continue;

                //Strings need special handling
                if (mi.Type() == typeof(LocalizedStringDBC <StringDBCReference>))
                {
                    try
                    {
                        entry.SetPropertyValue(mi.Name, LocalizedStringConverter.Convert((LocalizedStringDBC <string>)fromObject.GetPropertyValue(mi.Name)));
                    }
                    catch (Exception e)
                    {
                        Logger.LogError($"Failed to convert Member: {mi.Name} on Type: {mi.DeclaringType} from Value: {(LocalizedStringDBC<string>)fromObject.GetPropertyValue(mi.Name)} Exception: {e.Message}");
                        throw;
                    }
                }
                else if (mi.Type() == typeof(StringDBCReference))
                {
                    try
                    {
                        entry.SetPropertyValue(mi.Name, StringReferenceConverter.Convert((string)fromObject.GetPropertyValue(mi.Name)));
                    }
                    catch (Exception e)
                    {
                        Logger.LogError($"Failed to convert Member: {mi.Name} on Type: {mi.DeclaringType} from Value: {(LocalizedStringDBC<string>)fromObject.GetPropertyValue(mi.Name)} Exception: {e.Message}");
                        throw;
                    }
                }
                else if (mi.Type().Name.Contains("GenericStaticallySizedArrayChunk") && mi.Type().GenericTypeArguments[0] == typeof(StringDBCReference))
                {
                    object arrayObject = Activator.CreateInstance(mi.Type());

                    //for types with GenericStaticallySizedArrayChunk so we can set the members
                    foreach (MemberInfo arrayChunkMemberInfo in ComputeSerializableMembers(mi.Type()))
                    {
                        arrayObject.SetPropertyValue(arrayChunkMemberInfo.Name, StringReferenceConverter.Convert((string)fromObject.GetPropertyValue(mi.Name).GetPropertyValue(arrayChunkMemberInfo.Name)));
                    }

                    entry.SetPropertyValue(mi.Name, arrayObject);
                }
                else
                {
                    //Sets the entry with the value from the original object.
                    entry.SetPropertyValue(mi.Name, fromObject.GetPropertyValue(mi.Name));
                }
            }

            return(entry);
        }