예제 #1
0
 private CSharpSerializableParseOptions(SerializationInfo info, StreamingContext context)
 {
     this.options = new CSharpParseOptions(
         languageVersion: (LanguageVersion)info.GetValue("LanguageVersion", typeof(LanguageVersion)),
         documentationMode: (DocumentationMode)info.GetValue("DocumentationMode", typeof(DocumentationMode)),
         kind: (SourceCodeKind)info.GetValue("Kind", typeof(SourceCodeKind)),
         preprocessorSymbols: info.GetArray <string>("PreprocessorSymbols"));
 }
예제 #2
0
        private CSharpParseOptions(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            //public readonly LanguageVersion LanguageVersion;
            this.LanguageVersion = (LanguageVersion)info.GetValue("LanguageVersion", typeof(LanguageVersion));

            //internal readonly ImmutableArray<string> PreprocessorSymbols;
            this.PreprocessorSymbols = info.GetArray <string>("PreprocessorSymbols");
        }
예제 #3
0
            public override Method SetObjectData(Method method, SerializationInfo info)
            {
                var methodKind = info.GetValue <MethodKind>("Kind");

                switch (methodKind)
                {
                case MethodKind.CurrentMethod:
                    return(CurrentMethod);

                case MethodKind.Specialized:
                    return(mdDecoder.Specialize(info.GetValue <Method>("GenericMethod"), info.GetArray <Typ>("MethodTypeArguments")));

                case MethodKind.Path:
                    var isStatic      = info.GetBoolean("Static");
                    var fullName      = info.GetString("FullName");
                    var declaringType = info.GetValue <Typ>("DeclaringType");
                    var genericArity  = info.GetInt32("GenericArity");

                    IIndexable <Typ> formals;
                    foreach (var m in mdDecoder.Methods(declaringType))
                    {
                        if (mdDecoder.IsStatic(m) != isStatic)
                        {
                            continue;
                        }
                        if (mdDecoder.FullName(m) != fullName)
                        {
                            continue;
                        }
                        if (mdDecoder.IsGeneric(m, out formals))
                        {
                            if (formals.Count != genericArity)
                            {
                                continue;
                            }
                        }
                        else if (genericArity != 0)
                        {
                            continue;
                        }
                        return(m);
                    }
                    foreach (var m in this.contractDecoder.ModelMethods(declaringType))
                    {
                        if (mdDecoder.IsStatic(m) != isStatic)
                        {
                            continue;
                        }
                        if (mdDecoder.FullName(m) != fullName)
                        {
                            continue;
                        }
                        if (mdDecoder.IsGeneric(m, out formals))
                        {
                            Contract.Assume(formals != null);
                            if (formals.Count != genericArity)
                            {
                                continue;
                            }
                        }
                        else if (genericArity != 0)
                        {
                            continue;
                        }
                        return(m);
                    }
                    throw new SerializationException(String.Format("Unable to find {0}method \"{1}\"", isStatic ? "static " : "", fullName));

                default:
                    throw new SerializationException("Unknown method kind: " + methodKind);
                }
            }
예제 #4
0
            [ContractVerification(false)] // Too hard to prove?
            public override Typ SetObjectData(Typ type, SerializationInfo info)
            {
                var typeKind = info.GetValue <TypeKind>("Kind");

                switch (typeKind)
                {
                case TypeKind.Default:
                    return(default(Typ));

                case TypeKind.SystemVoid:
                    return(mdDecoder.System_Void);

                case TypeKind.Primitive:
                    if (mdDecoder.TryGetSystemType(info.GetString("FullName"), out type))
                    {
                        return(type);
                    }
                    throw new SerializationException(String.Format("Unable to construct system type \"{0}\".", info.GetString("FullName")));

                case TypeKind.SystemObject:
                    return(mdDecoder.System_Object);

                case TypeKind.FormalTypeParameter:
                {
                    IIndexable <Typ> formals;
                    if (!mdDecoder.IsGeneric(info.GetValue <Typ>("Type"), out formals, true))
                    {
                        throw new SerializationException(String.Format("Trying to get a formal type parameter of \"{0}\", which is not generic", info.GetValue <Typ>("Type")));
                    }
                    return(formals[info.GetInt32("Index")]);
                }

                case TypeKind.MethodFormalTypeParameter:
                {
                    IIndexable <Typ> formals;
                    if (!mdDecoder.IsGeneric(info.GetValue <Method>("Method"), out formals))
                    {
                        throw new SerializationException(String.Format("Trying to get a method formal type parameter of \"{0}\", which is not generic", info.GetValue <Method>("Method")));
                    }
                    return(formals[info.GetInt32("Index")]);
                }

                case TypeKind.ManagedPointer:
                    return(mdDecoder.ManagedPointer(info.GetValue <Typ>("ElementType")));

                case TypeKind.UnmanagedPointer:
                    return(mdDecoder.UnmanagedPointer(info.GetValue <Typ>("ElementType")));

                case TypeKind.Array:
                    return(mdDecoder.ArrayType(info.GetValue <Typ>("ElementType"), info.GetInt32("Rank")));

                case TypeKind.Specialized:
                    return(mdDecoder.Specialize(info.GetValue <Typ>("ElementType"), info.GetArray <Typ>("TypeArguments")));

                case TypeKind.Path:
                    // Essentially we loop among all the types until we found the one we need

                    var parentType = info.GetValue <Typ>("NestedIn");
                    var name       = info.GetString("Name");

                    IEnumerable <Typ> types;
                    string            @namespace;

                    if (parentType == null || parentType.Equals(null))     // Must work with CCI1 AND CCI2, one uses a class, the other one uses a struct, thank you!
                    {
                        var      module = info.GetString("Module");
                        Assembly assembly;
                        if (!this.TryGetAssembly(module, out assembly))
                        {
                            throw new SerializationException(String.Format("Unable to find module \"{0}\"", module));
                        }
                        @namespace = info.GetString("Namespace");
                        types      = mdDecoder.GetTypes(assembly);
                    }
                    else
                    {
                        @namespace = null;
                        types      = mdDecoder.NestedTypes(parentType);
                    }
                    var genericArity = info.GetInt32("GenericArity");

                    if (this.TryGetType(types, @namespace, name, genericArity, out type))
                    {
                        return(type);
                    }
                    throw new SerializationException(String.Format("Unable to find type {0}", name));

                default:
                    throw new SerializationException("Unknown type kind: " + typeKind);
                }
            }
예제 #5
0
 private MetadataReferenceProperties(SerializationInfo info, StreamingContext context)
 {
     this.kind              = (MetadataImageKind)info.GetValue("kind", typeof(MetadataImageKind));
     this.aliases           = info.GetArray <string>("aliases");
     this.embedInteropTypes = info.GetBoolean("embedInteropTypes");
 }
예제 #6
0
 private CSDiagnosticInfo(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     additionalLocations = info.GetArray <Location>("additionalLocations");
 }