Exemplo n.º 1
0
    protected MyClass(SerializationInfo info, StreamingContext context)
    {
        GenericSerializationInfo genericInfo = new GenericSerializationInfo(info);

        m_T    = genericInfo.GetValue <T>("m_T");
        m_Name = genericInfo.GetValue <string>("m_Name");
    }
Exemplo n.º 2
0
    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        GenericSerializationInfo genericInfo = new GenericSerializationInfo(info);

        genericInfo.AddValue("m_T", m_T);       //using type inference
        genericInfo.AddValue("m_Name", m_Name); //using type inference
    }
Exemplo n.º 3
0
        static void MakeNullable(INamedTypeSymbol type, List <GenericSerializationInfo> list)
        {
            var info = new GenericSerializationInfo
            {
                FormatterName = $"global::MessagePack.Formatters.NullableFormatter<{type.TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>()",
                FullName      = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
            };

            list.Add(info);
        }
Exemplo n.º 4
0
        static void MakeArray(IArrayTypeSymbol array, List <GenericSerializationInfo> list)
        {
            var arrayInfo = new GenericSerializationInfo
            {
                FormatterName = $"global::MessagePack.Formatters.ArrayFormatter<{array.ElementType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>()",
                FullName      = array.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
            };

            list.Add(arrayInfo);
        }
Exemplo n.º 5
0
        static void MakeGeneric(INamedTypeSymbol type, string formatterTemplate, List <GenericSerializationInfo> list)
        {
            var typeArgs = string.Join(", ", type.TypeArguments.Select(x => x.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)));
            var f        = formatterTemplate.Replace("TREPLACE", typeArgs);

            var info = new GenericSerializationInfo
            {
                FormatterName = f,
                FullName      = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
            };

            list.Add(info);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Result Model 복사
        /// </summary>
        /// <returns></returns>
        //public ResultModelEx<T> Copy()
        //{
        //    ResultModelEx<T> retValue = new ResultModelEx<T>();
        //    retValue.Success = Success;
        //    retValue.Code = Code;
        //    retValue.Description = Description;
        //    retValue.Exception = Exception;
        //    retValue.Page = Page;
        //    retValue.Search = Search;
        //    retValue.Result = Result;
        //    return retValue;
        //}

        #region ISerializable 멤버

        public ResultModel(SerializationInfo info, StreamingContext context)
        {
            GenericSerializationInfo ginfo = new GenericSerializationInfo(info);

            Success     = info.GetBoolean("Success");
            Code        = info.GetString("Code");
            Description = info.GetString("Description");
            Exception   = info.GetString("Exception");
            //Page = (PageModel)info.GetValue("Page", typeof(PageModel));
            //Search = (SearchModel)info.GetValue("Search", typeof(SearchModel));
            //Page = (PageModel)info.GetValue("Page", typeof(PageModel));
            Result = (T)info.GetValue("Result", typeof(T));
        }
Exemplo n.º 7
0
        static void ExtractResolverInfo(InterfaceDefinition[] definitions, out GenericSerializationInfo[] genericInfoResults, out EnumSerializationInfo[] enumInfoResults, string messagePackGeneratedNamespace)
        {
            var genericInfos = new List <GenericSerializationInfo>();
            var enumInfos    = new List <EnumSerializationInfo>();

            foreach (var method in definitions.SelectMany(x => x.Methods))
            {
                if (method.UnwrappedOriginalResposneTypeSymbol == null)
                {
                    continue;
                }

                TraverseTypes(method.UnwrappedOriginalResposneTypeSymbol, genericInfos, enumInfos, messagePackGeneratedNamespace);

                // paramter type
                foreach (var p in method.Parameters.Select(x => x.OriginalSymbol.Type))
                {
                    TraverseTypes(p, genericInfos, enumInfos, messagePackGeneratedNamespace);
                }

                if (method.Parameters.Length > 1)
                {
                    // create dynamicargumenttuple
                    var parameterArguments = method.Parameters.Select(x => x.OriginalSymbol)
                                             .Select(x => $"default({x.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)})")
                                             .ToArray();

                    var typeArguments = method.Parameters.Select(x => x.OriginalSymbol).Select(x => x.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));

                    var tupleInfo = new GenericSerializationInfo
                    {
                        FormatterName = $"global::MagicOnion.DynamicArgumentTupleFormatter<{string.Join(", ", typeArguments)}>({string.Join(", ", parameterArguments)})",
                        FullName      = $"global::MagicOnion.DynamicArgumentTuple<{string.Join(", ", typeArguments)}>",
                    };
                    genericInfos.Add(tupleInfo);
                }
            }

            genericInfoResults = genericInfos.Distinct().ToArray();
            enumInfoResults    = enumInfos.Distinct().ToArray();
        }
Exemplo n.º 8
0
        static void ExtractResolverInfo(InterfaceDefinition[] definitions, out GenericSerializationInfo[] genericInfoResults, out EnumSerializationInfo[] enumInfoResults)
        {
            var genericInfos = new List <GenericSerializationInfo>();
            var enumInfos    = new List <EnumSerializationInfo>();

            foreach (var method in definitions.SelectMany(x => x.Methods))
            {
                if (method.UnwrappedOriginalResposneTypeSymbol == null)
                {
                    continue;
                }

                var namedResponse = method.UnwrappedOriginalResposneTypeSymbol as INamedTypeSymbol;

                if (method.UnwrappedOriginalResposneTypeSymbol.TypeKind == Microsoft.CodeAnalysis.TypeKind.Array)
                {
                    var array = method.UnwrappedOriginalResposneTypeSymbol as IArrayTypeSymbol;
                    if (!embeddedTypes.Contains(array.ToString()))
                    {
                        MakeArray(array, genericInfos);
                        if (array.ElementType.TypeKind == TypeKind.Enum)
                        {
                            MakeEnum(array.ElementType as INamedTypeSymbol, enumInfos);
                        }
                    }
                }
                else if (method.UnwrappedOriginalResposneTypeSymbol.TypeKind == Microsoft.CodeAnalysis.TypeKind.Enum)
                {
                    var enumType = method.UnwrappedOriginalResposneTypeSymbol as INamedTypeSymbol;
                    MakeEnum(enumType, enumInfos);
                }
                else if (namedResponse != null && namedResponse.IsGenericType)
                {
                    // generic type handling
                    var    genericType       = namedResponse.ConstructUnboundGenericType();
                    var    genericTypeString = genericType.ToDisplayString();
                    var    fullName          = namedResponse.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
                    string formatterString;

                    if (genericTypeString == "T?")
                    {
                        var more = namedResponse.TypeArguments[0];
                        if (more.TypeKind == TypeKind.Enum)
                        {
                            MakeEnum(more as INamedTypeSymbol, enumInfos);
                        }

                        MakeNullable(namedResponse, genericInfos);
                    }
                    else if (additionalSupportGenericFormatter.TryGetValue(genericTypeString, out formatterString))
                    {
                        MakeGeneric(namedResponse, formatterString, genericInfos);
                    }
                }

                // paramter type
                foreach (var p in method.Parameters)
                {
                    namedResponse = p.OriginalSymbol.Type as INamedTypeSymbol;

                    if (p.OriginalSymbol.Type.TypeKind == Microsoft.CodeAnalysis.TypeKind.Array)
                    {
                        var array = p.OriginalSymbol.Type as IArrayTypeSymbol;
                        if (embeddedTypes.Contains(array.ToString()))
                        {
                            continue;
                        }
                        MakeArray(array, genericInfos);
                        if (array.ElementType.TypeKind == TypeKind.Enum)
                        {
                            MakeEnum(array.ElementType as INamedTypeSymbol, enumInfos);
                        }
                    }
                    else if (p.OriginalSymbol.Type.TypeKind == Microsoft.CodeAnalysis.TypeKind.Enum)
                    {
                        var enumType = p.OriginalSymbol.Type as INamedTypeSymbol;
                        MakeEnum(enumType, enumInfos);
                    }
                    else if (namedResponse != null && namedResponse.IsGenericType)
                    {
                        // generic type handling
                        var    genericType       = namedResponse.ConstructUnboundGenericType();
                        var    genericTypeString = genericType.ToDisplayString();
                        var    fullName          = namedResponse.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
                        string formatterString;

                        if (genericTypeString == "T?")
                        {
                            var more = namedResponse.TypeArguments[0];
                            if (more.TypeKind == TypeKind.Enum)
                            {
                                MakeEnum(more as INamedTypeSymbol, enumInfos);
                            }

                            MakeNullable(namedResponse, genericInfos);
                        }
                        else if (additionalSupportGenericFormatter.TryGetValue(genericTypeString, out formatterString))
                        {
                            MakeGeneric(namedResponse, formatterString, genericInfos);
                        }
                    }
                }

                if (method.Parameters.Length > 1)
                {
                    // create dynamicargumenttuple
                    var parameterArguments = method.Parameters.Select(x => x.OriginalSymbol)
                                             .Select(x => $"default({x.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)})")
                                             .ToArray();

                    var typeArguments = method.Parameters.Select(x => x.OriginalSymbol).Select(x => x.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));

                    var tupleInfo = new GenericSerializationInfo
                    {
                        FormatterName = $"global::MagicOnion.DynamicArgumentTupleFormatter<{string.Join(", ", typeArguments)}>({string.Join(", ", parameterArguments)})",
                        FullName      = $"global::MagicOnion.DynamicArgumentTuple<{string.Join(", ", typeArguments)}>",
                    };
                    genericInfos.Add(tupleInfo);
                }
            }

            genericInfoResults = genericInfos.Distinct().ToArray();
            enumInfoResults    = enumInfos.Distinct().ToArray();
        }
Exemplo n.º 9
0
        static void TraverseTypes(ITypeSymbol typeSymbol, List <GenericSerializationInfo> genericInfos, List <EnumSerializationInfo> enumInfos, string messagePackGeneratedNamespace)
        {
            var namedTypeSymbol = typeSymbol as INamedTypeSymbol;

            if (typeSymbol.TypeKind == TypeKind.Array)
            {
                var array = (IArrayTypeSymbol)typeSymbol;
                if (embeddedTypes.Contains(array.ToString()))
                {
                    return;
                }
                MakeArray(array, genericInfos);
                if (array.ElementType.TypeKind == TypeKind.Enum)
                {
                    MakeEnum(array.ElementType as INamedTypeSymbol, enumInfos);
                }
            }
            else if (typeSymbol.TypeKind == TypeKind.Enum)
            {
                MakeEnum(namedTypeSymbol, enumInfos);
            }
            else if (namedTypeSymbol != null && namedTypeSymbol.IsGenericType)
            {
                var genericType       = namedTypeSymbol.ConstructUnboundGenericType();
                var genericTypeString = genericType.ToDisplayString();

                if (genericTypeString == "T?")
                {
                    // Nullable<T> (T?)
                    var more = namedTypeSymbol.TypeArguments[0];
                    if (more.TypeKind == TypeKind.Enum)
                    {
                        MakeEnum(more as INamedTypeSymbol, enumInfos);
                    }

                    MakeNullable(namedTypeSymbol, genericInfos);
                }
                else if (additionalSupportGenericFormatter.TryGetValue(genericTypeString, out var formatterString))
                {
                    // Well-known generic type.
                    // System.Collections.Generic.List<T> ...
                    MakeGenericWellKnown(namedTypeSymbol, formatterString, genericInfos);
                }
                else
                {
                    // User-defined generic type.
                    // The object formatter is generated by MessagePack.Generator

                    // MyProject.MyClass<T> --> global::MessagePack.Formatters.MyProject.MyClassFormatter<T>
                    // MyProject.MyClass<T1, T2> --> global::MessagePack.Formatters.MyProject.MyClassFormatter<T1, T2>
                    //     MyProject.MyClass<MyObject> --> global::MessagePack.Generated.MyProject.MyClassFormatter<global::MyProject.MyObject>
                    //     MyProject.MyClass<MyObject, OtherObject> --> global::MessagePack.Generated.MyProject.MyClassFormatter<global::MyProject.MyObject, global::MyProject.OtherObject>
                    //         global::{MessagePackGeneratedNamespace}.{Namespace}.{ClassName}Formatter<{TypeArgs}>

                    var typeNamespace     = namedTypeSymbol.ContainingNamespace.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat).Replace("global::", "");
                    var typeName          = namedTypeSymbol.Name;
                    var typeArgs          = string.Join(", ", namedTypeSymbol.TypeArguments.Select(x => x.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)).ToArray());
                    var formatterFullName =
                        $"global::{(string.IsNullOrWhiteSpace(messagePackGeneratedNamespace) ? "" : messagePackGeneratedNamespace + ".")}{(string.IsNullOrWhiteSpace(typeNamespace) ? "" : typeNamespace + ".")}{typeName}Formatter<{typeArgs}>";
                    var genericInfo = new GenericSerializationInfo
                    {
                        FormatterName = $"{formatterFullName}()",
                        FullName      = namedTypeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
                    };
                    genericInfos.Add(genericInfo);

                    // Recursively scan generic-types
                    foreach (var typeArg in namedTypeSymbol.TypeArguments)
                    {
                        TraverseTypes(typeArg, genericInfos, enumInfos, messagePackGeneratedNamespace);
                    }
                }
            }
        }
Exemplo n.º 10
0
        static void ExtractResolverInfo(InterfaceDefintion[] definitions, out GenericSerializationInfo[] genericInfoResults, out EnumSerializationInfo[] enumInfoResults)
        {
            var genericInfos = new List <GenericSerializationInfo>();
            var enumInfos    = new List <EnumSerializationInfo>();

            foreach (var method in definitions.SelectMany(x => x.Methods))
            {
                if (method.UnwrappedOriginalResposneTypeSymbol.TypeKind == Microsoft.CodeAnalysis.TypeKind.Array)
                {
                    var array = method.UnwrappedOriginalResposneTypeSymbol as IArrayTypeSymbol;
                    if (embeddedTypes.Contains(array.ToString()))
                    {
                        continue;
                    }
                    MakeArray(array, genericInfos);
                    if (array.ElementType.TypeKind == TypeKind.Enum)
                    {
                        MakeEnum(array.ElementType as INamedTypeSymbol, enumInfos);
                    }
                }
                else if (method.UnwrappedOriginalResposneTypeSymbol.TypeKind == Microsoft.CodeAnalysis.TypeKind.Enum)
                {
                    var enumType = method.UnwrappedOriginalResposneTypeSymbol as INamedTypeSymbol;
                    MakeEnum(enumType, enumInfos);
                }

                // paramter type
                foreach (var p in method.Parameters)
                {
                    if (p.OriginalSymbol.Type.TypeKind == Microsoft.CodeAnalysis.TypeKind.Array)
                    {
                        var array = p.OriginalSymbol.Type as IArrayTypeSymbol;
                        if (embeddedTypes.Contains(array.ToString()))
                        {
                            continue;
                        }
                        MakeArray(array, genericInfos);
                        if (array.ElementType.TypeKind == TypeKind.Enum)
                        {
                            MakeEnum(array.ElementType as INamedTypeSymbol, enumInfos);
                        }
                    }
                    else if (p.OriginalSymbol.Type.TypeKind == Microsoft.CodeAnalysis.TypeKind.Enum)
                    {
                        var enumType = p.OriginalSymbol.Type as INamedTypeSymbol;
                        MakeEnum(enumType, enumInfos);
                    }
                }

                if (method.Parameters.Length > 1)
                {
                    // create dynamicargumenttuple
                    var parameterArguments = method.Parameters.Select(x => x.OriginalSymbol)
                                             .Select(x => $"default({x.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)})")
                                             .ToArray();

                    var typeArguments = method.Parameters.Select(x => x.OriginalSymbol).Select(x => x.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));

                    var tupleInfo = new GenericSerializationInfo
                    {
                        FormatterName = $"global::MagicOnion.DynamicArgumentTupleFormatter<{string.Join(", ", typeArguments)}>({string.Join(", ", parameterArguments)})",
                        FullName      = $"global::MagicOnion.DynamicArgumentTuple<{string.Join(", ", typeArguments)}>",
                    };
                    genericInfos.Add(tupleInfo);
                }
            }

            genericInfoResults = genericInfos.Distinct().ToArray();
            enumInfoResults    = enumInfos.Distinct().ToArray();
        }