Beispiel #1
0
        internal MetaType(RuntimeTypeModel model, Type type)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            WireType         defaultWireType;
            IProtoSerializer coreSerializer = ValueMember.TryGetCoreSerializer(null, DataFormat.Default, type, out defaultWireType, false, false);

            if (coreSerializer != null)
            {
                throw new ArgumentException("Data of this type has inbuilt behaviour, and cannot be added to a model in this way: " + type.FullName);
            }

            this.type  = type;
            this.model = model;

            if (type.IsEnum)
            {
                EnumPassthru = type.IsDefined(typeof(FlagsAttribute), false);
            }
        }
        private void CascadeDependents(BasicList list, MetaType metaType)
        {
            MetaType surrogateOrBaseOrSelf;

            if (metaType.IsList)
            {
                Type listItemType = TypeModel.GetListItemType(this, metaType.Type);
                if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, listItemType, out WireType _, asReference: false, dynamicType: false, overwriteList: false, allowComplexTypes: false) != null)
                {
                    return;
                }
                int num = FindOrAddAuto(listItemType, demand: false, addWithContractOnly: false, addEvenIfAutoDisabled: false);
                if (num >= 0)
                {
                    surrogateOrBaseOrSelf = ((MetaType)types[num]).GetSurrogateOrBaseOrSelf(deep: false);
                    if (!list.Contains(surrogateOrBaseOrSelf))
                    {
                        list.Add(surrogateOrBaseOrSelf);
                        CascadeDependents(list, surrogateOrBaseOrSelf);
                    }
                }
                return;
            }
            if (metaType.IsAutoTuple)
            {
                if (MetaType.ResolveTupleConstructor(metaType.Type, out MemberInfo[] mappedMembers) != null)
Beispiel #3
0
 private void CascadeDependents(BasicList list, MetaType metaType)
 {
     if (metaType.IsList)
     {
         Type listItemType = TypeModel.GetListItemType(this, metaType.Type);
         if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, listItemType, out WireType _, false, false, false, false) == null)
         {
             int num = FindOrAddAuto(listItemType, false, false, false);
             if (num >= 0)
             {
                 MetaType surrogateOrBaseOrSelf = ((MetaType)types[num]).GetSurrogateOrBaseOrSelf(false);
                 if (!list.Contains(surrogateOrBaseOrSelf))
                 {
                     list.Add(surrogateOrBaseOrSelf);
                     CascadeDependents(list, surrogateOrBaseOrSelf);
                 }
             }
         }
     }
     else
     {
         MetaType surrogateOrBaseOrSelf;
         if (metaType.IsAutoTuple)
         {
             if (MetaType.ResolveTupleConstructor(metaType.Type, out MemberInfo[] array) != (ConstructorInfo)null)
Beispiel #4
0
        internal IProtoSerializer TryGetBasicTypeSerializer(Type type)
        {
            int num = this.basicTypes.IndexOf(RuntimeTypeModel.BasicTypeFinder, type);

            if (num >= 0)
            {
                return(((RuntimeTypeModel.BasicType) this.basicTypes[num]).Serializer);
            }
            BasicList        basicList = this.basicTypes;
            IProtoSerializer result;

            lock (basicList)
            {
                num = this.basicTypes.IndexOf(RuntimeTypeModel.BasicTypeFinder, type);
                if (num >= 0)
                {
                    result = ((RuntimeTypeModel.BasicType) this.basicTypes[num]).Serializer;
                }
                else
                {
                    IProtoSerializer arg_9A_0;
                    if (MetaType.GetContractFamily(this, type, null) == MetaType.AttributeFamily.None)
                    {
                        WireType         wireType;
                        IProtoSerializer protoSerializer = ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out wireType, false, false, false, false);
                        arg_9A_0 = protoSerializer;
                    }
                    else
                    {
                        arg_9A_0 = null;
                    }
                    IProtoSerializer protoSerializer2 = arg_9A_0;
                    if (protoSerializer2 != null)
                    {
                        this.basicTypes.Add(new RuntimeTypeModel.BasicType(type, protoSerializer2));
                    }
                    result = protoSerializer2;
                }
            }
            return(result);
        }
        // Token: 0x06000389 RID: 905 RVA: 0x00013428 File Offset: 0x00011628
        internal string GetSchemaTypeName(Type effectiveType, DataFormat dataFormat, bool asReference, bool dynamicType, ref bool requiresBclImport)
        {
            Type underlyingType = Helpers.GetUnderlyingType(effectiveType);

            if (underlyingType != null)
            {
                effectiveType = underlyingType;
            }
            if (effectiveType == base.MapType(typeof(byte[])))
            {
                return("bytes");
            }
            WireType         wireType;
            IProtoSerializer protoSerializer = ValueMember.TryGetCoreSerializer(this, dataFormat, effectiveType, out wireType, false, false, false, false);

            if (protoSerializer == null)
            {
                if (asReference || dynamicType)
                {
                    requiresBclImport = true;
                    return("bcl.NetObjectProxy");
                }
                return(this[effectiveType].GetSurrogateOrBaseOrSelf(true).GetSchemaTypeName());
            }
            else
            {
                if (!(protoSerializer is ParseableSerializer))
                {
                    ProtoTypeCode typeCode = Helpers.GetTypeCode(effectiveType);
                    switch (typeCode)
                    {
                    case ProtoTypeCode.Boolean:
                        return("bool");

                    case ProtoTypeCode.Char:
                    case ProtoTypeCode.Byte:
                    case ProtoTypeCode.UInt16:
                    case ProtoTypeCode.UInt32:
                        if (dataFormat == DataFormat.FixedSize)
                        {
                            return("fixed32");
                        }
                        return("uint32");

                    case ProtoTypeCode.SByte:
                    case ProtoTypeCode.Int16:
                    case ProtoTypeCode.Int32:
                        if (dataFormat == DataFormat.ZigZag)
                        {
                            return("sint32");
                        }
                        if (dataFormat != DataFormat.FixedSize)
                        {
                            return("int32");
                        }
                        return("sfixed32");

                    case ProtoTypeCode.Int64:
                        if (dataFormat == DataFormat.ZigZag)
                        {
                            return("sint64");
                        }
                        if (dataFormat != DataFormat.FixedSize)
                        {
                            return("int64");
                        }
                        return("sfixed64");

                    case ProtoTypeCode.UInt64:
                        if (dataFormat == DataFormat.FixedSize)
                        {
                            return("fixed64");
                        }
                        return("uint64");

                    case ProtoTypeCode.Single:
                        return("float");

                    case ProtoTypeCode.Double:
                        return("double");

                    case ProtoTypeCode.Decimal:
                        requiresBclImport = true;
                        return("bcl.Decimal");

                    case ProtoTypeCode.DateTime:
                        requiresBclImport = true;
                        return("bcl.DateTime");

                    case (ProtoTypeCode)17:
                        break;

                    case ProtoTypeCode.String:
                        if (asReference)
                        {
                            requiresBclImport = true;
                        }
                        if (!asReference)
                        {
                            return("string");
                        }
                        return("bcl.NetObjectProxy");

                    default:
                        if (typeCode == ProtoTypeCode.TimeSpan)
                        {
                            requiresBclImport = true;
                            return("bcl.TimeSpan");
                        }
                        if (typeCode == ProtoTypeCode.Guid)
                        {
                            requiresBclImport = true;
                            return("bcl.Guid");
                        }
                        break;
                    }
                    throw new NotSupportedException("No .proto map found for: " + effectiveType.FullName);
                }
                if (asReference)
                {
                    requiresBclImport = true;
                }
                if (!asReference)
                {
                    return("string");
                }
                return("bcl.NetObjectProxy");
            }
        }
 // Token: 0x0600036A RID: 874 RVA: 0x00012A1C File Offset: 0x00010C1C
 private void CascadeDependents(BasicList list, MetaType metaType)
 {
     if (metaType.IsList)
     {
         Type     listItemType = TypeModel.GetListItemType(this, metaType.Type);
         WireType wireType;
         if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, listItemType, out wireType, false, false, false, false) == null)
         {
             int num = this.FindOrAddAuto(listItemType, false, false, false);
             if (num >= 0)
             {
                 MetaType metaType2 = ((MetaType)this.types[num]).GetSurrogateOrBaseOrSelf(false);
                 if (!list.Contains(metaType2))
                 {
                     list.Add(metaType2);
                     this.CascadeDependents(list, metaType2);
                     return;
                 }
             }
         }
     }
     else
     {
         MetaType metaType2;
         if (metaType.IsAutoTuple)
         {
             MemberInfo[] array;
             if (MetaType.ResolveTupleConstructor(metaType.Type, out array) != null)
             {
                 for (int i = 0; i < array.Length; i++)
                 {
                     Type type = null;
                     if (array[i] is PropertyInfo)
                     {
                         type = ((PropertyInfo)array[i]).PropertyType;
                     }
                     else if (array[i] is FieldInfo)
                     {
                         type = ((FieldInfo)array[i]).FieldType;
                     }
                     WireType wireType2;
                     if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out wireType2, false, false, false, false) == null)
                     {
                         int num2 = this.FindOrAddAuto(type, false, false, false);
                         if (num2 >= 0)
                         {
                             metaType2 = ((MetaType)this.types[num2]).GetSurrogateOrBaseOrSelf(false);
                             if (!list.Contains(metaType2))
                             {
                                 list.Add(metaType2);
                                 this.CascadeDependents(list, metaType2);
                             }
                         }
                     }
                 }
             }
         }
         else
         {
             foreach (object obj in metaType.Fields)
             {
                 ValueMember valueMember = (ValueMember)obj;
                 Type        type2       = valueMember.ItemType;
                 if (type2 == null)
                 {
                     type2 = valueMember.MemberType;
                 }
                 WireType wireType3;
                 if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type2, out wireType3, false, false, false, false) == null)
                 {
                     int num3 = this.FindOrAddAuto(type2, false, false, false);
                     if (num3 >= 0)
                     {
                         metaType2 = ((MetaType)this.types[num3]).GetSurrogateOrBaseOrSelf(false);
                         if (!list.Contains(metaType2))
                         {
                             list.Add(metaType2);
                             this.CascadeDependents(list, metaType2);
                         }
                     }
                 }
             }
         }
         if (metaType.HasSubtypes)
         {
             SubType[] subtypes = metaType.GetSubtypes();
             for (int j = 0; j < subtypes.Length; j++)
             {
                 metaType2 = subtypes[j].DerivedType.GetSurrogateOrSelf();
                 if (!list.Contains(metaType2))
                 {
                     list.Add(metaType2);
                     this.CascadeDependents(list, metaType2);
                 }
             }
         }
         metaType2 = metaType.BaseType;
         if (metaType2 != null)
         {
             metaType2 = metaType2.GetSurrogateOrSelf();
         }
         if (metaType2 != null && !list.Contains(metaType2))
         {
             list.Add(metaType2);
             this.CascadeDependents(list, metaType2);
         }
     }
 }
        // Token: 0x06000369 RID: 873 RVA: 0x00012780 File Offset: 0x00010980
        public override string GetSchema(Type type)
        {
            BasicList basicList = new BasicList();
            MetaType  metaType  = null;
            bool      flag      = false;

            if (type == null)
            {
                foreach (object obj in this.types)
                {
                    MetaType surrogateOrBaseOrSelf = ((MetaType)obj).GetSurrogateOrBaseOrSelf(false);
                    if (!basicList.Contains(surrogateOrBaseOrSelf))
                    {
                        basicList.Add(surrogateOrBaseOrSelf);
                        this.CascadeDependents(basicList, surrogateOrBaseOrSelf);
                    }
                }
            }
            else
            {
                Type underlyingType = Helpers.GetUnderlyingType(type);
                if (underlyingType != null)
                {
                    type = underlyingType;
                }
                WireType wireType;
                flag = (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out wireType, false, false, false, false) != null);
                if (!flag)
                {
                    int num = this.FindOrAddAuto(type, false, false, false);
                    if (num < 0)
                    {
                        throw new ArgumentException("The type specified is not a contract-type", "type");
                    }
                    metaType = ((MetaType)this.types[num]).GetSurrogateOrBaseOrSelf(false);
                    basicList.Add(metaType);
                    this.CascadeDependents(basicList, metaType);
                }
            }
            StringBuilder stringBuilder = new StringBuilder();
            string        text          = null;

            if (!flag)
            {
                foreach (object obj2 in ((IEnumerable)((metaType == null) ? this.types : basicList)))
                {
                    MetaType metaType2 = (MetaType)obj2;
                    if (!metaType2.IsList)
                    {
                        string @namespace = metaType2.Type.Namespace;
                        if (!Helpers.IsNullOrEmpty(@namespace) && [email protected]("System."))
                        {
                            if (text == null)
                            {
                                text = @namespace;
                            }
                            else if (!(text == @namespace))
                            {
                                text = null;
                                break;
                            }
                        }
                    }
                }
            }
            if (!Helpers.IsNullOrEmpty(text))
            {
                stringBuilder.Append("package ").Append(text).Append(';');
                Helpers.AppendLine(stringBuilder);
            }
            bool          flag2          = false;
            StringBuilder stringBuilder2 = new StringBuilder();

            MetaType[] array = new MetaType[basicList.Count];
            basicList.CopyTo(array, 0);
            Array.Sort <MetaType>(array, MetaType.Comparer.Default);
            if (flag)
            {
                Helpers.AppendLine(stringBuilder2).Append("message ").Append(type.Name).Append(" {");
                MetaType.NewLine(stringBuilder2, 1).Append("optional ").Append(this.GetSchemaTypeName(type, DataFormat.Default, false, false, ref flag2)).Append(" value = 1;");
                Helpers.AppendLine(stringBuilder2).Append('}');
            }
            else
            {
                foreach (MetaType metaType3 in array)
                {
                    if (!metaType3.IsList || metaType3 == metaType)
                    {
                        metaType3.WriteSchema(stringBuilder2, 0, ref flag2);
                    }
                }
            }
            if (flag2)
            {
                stringBuilder.Append("import \"bcl.proto\"; // schema for protobuf-net's handling of core .NET types");
                Helpers.AppendLine(stringBuilder);
            }
            return(Helpers.AppendLine(stringBuilder.Append(stringBuilder2)).ToString());
        }
Beispiel #8
0
 private void CascadeDependents(BasicList list, MetaType metaType)
 {
     if (metaType.IsList)
     {
         Type     listItemType = TypeModel.GetListItemType(this, metaType.Type);
         WireType wireType;
         if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, listItemType, out wireType, false, false, false, false) == null)
         {
             int num = this.FindOrAddAuto(listItemType, false, false, false);
             if (num >= 0)
             {
                 MetaType metaType2 = ((MetaType)this.types[num]).GetSurrogateOrBaseOrSelf(false);
                 if (!list.Contains(metaType2))
                 {
                     list.Add(metaType2);
                     this.CascadeDependents(list, metaType2);
                 }
             }
         }
     }
     else
     {
         MetaType metaType2;
         if (metaType.IsAutoTuple)
         {
             MemberInfo[] array;
             if (MetaType.ResolveTupleConstructor(metaType.Type, out array) != null)
             {
                 for (int i = 0; i < array.Length; i++)
                 {
                     Type type = null;
                     if (array[i] is PropertyInfo)
                     {
                         type = ((PropertyInfo)array[i]).get_PropertyType();
                     }
                     else if (array[i] is FieldInfo)
                     {
                         type = ((FieldInfo)array[i]).get_FieldType();
                     }
                     WireType wireType2;
                     if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out wireType2, false, false, false, false) == null)
                     {
                         int num2 = this.FindOrAddAuto(type, false, false, false);
                         if (num2 >= 0)
                         {
                             metaType2 = ((MetaType)this.types[num2]).GetSurrogateOrBaseOrSelf(false);
                             if (!list.Contains(metaType2))
                             {
                                 list.Add(metaType2);
                                 this.CascadeDependents(list, metaType2);
                             }
                         }
                     }
                 }
             }
         }
         else
         {
             IEnumerator enumerator = metaType.Fields.GetEnumerator();
             try
             {
                 while (enumerator.MoveNext())
                 {
                     ValueMember valueMember = (ValueMember)enumerator.get_Current();
                     Type        type2       = valueMember.ItemType;
                     if (type2 == null)
                     {
                         type2 = valueMember.MemberType;
                     }
                     WireType wireType3;
                     if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type2, out wireType3, false, false, false, false) == null)
                     {
                         int num3 = this.FindOrAddAuto(type2, false, false, false);
                         if (num3 >= 0)
                         {
                             metaType2 = ((MetaType)this.types[num3]).GetSurrogateOrBaseOrSelf(false);
                             if (!list.Contains(metaType2))
                             {
                                 list.Add(metaType2);
                                 this.CascadeDependents(list, metaType2);
                             }
                         }
                     }
                 }
             }
             finally
             {
                 IDisposable disposable = enumerator as IDisposable;
                 if (disposable != null)
                 {
                     disposable.Dispose();
                 }
             }
         }
         if (metaType.HasSubtypes)
         {
             SubType[] subtypes = metaType.GetSubtypes();
             for (int j = 0; j < subtypes.Length; j++)
             {
                 SubType subType = subtypes[j];
                 metaType2 = subType.DerivedType.GetSurrogateOrSelf();
                 if (!list.Contains(metaType2))
                 {
                     list.Add(metaType2);
                     this.CascadeDependents(list, metaType2);
                 }
             }
         }
         metaType2 = metaType.BaseType;
         if (metaType2 != null)
         {
             metaType2 = metaType2.GetSurrogateOrSelf();
         }
         if (metaType2 != null && !list.Contains(metaType2))
         {
             list.Add(metaType2);
             this.CascadeDependents(list, metaType2);
         }
     }
 }
Beispiel #9
0
        public override string GetSchema(Type type)
        {
            BasicList basicList = new BasicList();
            MetaType  metaType  = null;
            bool      flag      = false;

            if (type == null)
            {
                BasicList.NodeEnumerator enumerator = this.types.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    MetaType metaType2             = (MetaType)enumerator.Current;
                    MetaType surrogateOrBaseOrSelf = metaType2.GetSurrogateOrBaseOrSelf(false);
                    if (!basicList.Contains(surrogateOrBaseOrSelf))
                    {
                        basicList.Add(surrogateOrBaseOrSelf);
                        this.CascadeDependents(basicList, surrogateOrBaseOrSelf);
                    }
                }
            }
            else
            {
                Type underlyingType = Helpers.GetUnderlyingType(type);
                if (underlyingType != null)
                {
                    type = underlyingType;
                }
                WireType wireType;
                flag = (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out wireType, false, false, false, false) != null);
                if (!flag)
                {
                    int num = this.FindOrAddAuto(type, false, false, false);
                    if (num < 0)
                    {
                        throw new ArgumentException("The type specified is not a contract-type", "type");
                    }
                    metaType = ((MetaType)this.types[num]).GetSurrogateOrBaseOrSelf(false);
                    basicList.Add(metaType);
                    this.CascadeDependents(basicList, metaType);
                }
            }
            StringBuilder stringBuilder = new StringBuilder();
            string        text          = null;

            if (!flag)
            {
                IEnumerable enumerable  = (metaType != null) ? basicList : this.types;
                IEnumerator enumerator2 = enumerable.GetEnumerator();
                try
                {
                    while (enumerator2.MoveNext())
                    {
                        MetaType metaType3 = (MetaType)enumerator2.get_Current();
                        if (!metaType3.IsList)
                        {
                            string @namespace = metaType3.Type.get_Namespace();
                            if (!Helpers.IsNullOrEmpty(@namespace))
                            {
                                if ([email protected]("System."))
                                {
                                    if (text == null)
                                    {
                                        text = @namespace;
                                    }
                                    else if (!(text == @namespace))
                                    {
                                        text = null;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator2 as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            if (!Helpers.IsNullOrEmpty(text))
            {
                stringBuilder.Append("package ").Append(text).Append(';');
                Helpers.AppendLine(stringBuilder);
            }
            bool          flag2          = false;
            StringBuilder stringBuilder2 = new StringBuilder();

            MetaType[] array = new MetaType[basicList.Count];
            basicList.CopyTo(array, 0);
            Array.Sort <MetaType>(array, MetaType.Comparer.Default);
            if (flag)
            {
                Helpers.AppendLine(stringBuilder2).Append("message ").Append(type.get_Name()).Append(" {");
                MetaType.NewLine(stringBuilder2, 1).Append("optional ").Append(this.GetSchemaTypeName(type, DataFormat.Default, false, false, ref flag2)).Append(" value = 1;");
                Helpers.AppendLine(stringBuilder2).Append('}');
            }
            else
            {
                for (int i = 0; i < array.Length; i++)
                {
                    MetaType metaType4 = array[i];
                    if (!metaType4.IsList || metaType4 == metaType)
                    {
                        metaType4.WriteSchema(stringBuilder2, 0, ref flag2);
                    }
                }
            }
            if (flag2)
            {
                stringBuilder.Append("import \"bcl.proto\"; // schema for protobuf-net's handling of core .NET types");
                Helpers.AppendLine(stringBuilder);
            }
            return(Helpers.AppendLine(stringBuilder.Append(stringBuilder2)).ToString());
        }
Beispiel #10
0
        // Token: 0x0600040A RID: 1034 RVA: 0x00015168 File Offset: 0x00013368
        private IProtoSerializer BuildSerializer()
        {
            int opaqueToken = 0;
            IProtoSerializer result;

            try
            {
                this.model.TakeLock(ref opaqueToken);
                Type             type = (this.itemType == null) ? this.memberType : this.itemType;
                WireType         wireType;
                IProtoSerializer protoSerializer = ValueMember.TryGetCoreSerializer(this.model, this.dataFormat, type, out wireType, this.asReference, this.dynamicType, this.OverwriteList, true);
                if (protoSerializer == null)
                {
                    throw new InvalidOperationException("No serializer defined for type: " + type.FullName);
                }
                if (this.itemType != null && this.SupportNull)
                {
                    if (this.IsPacked)
                    {
                        throw new NotSupportedException("Packed encodings cannot support null values");
                    }
                    protoSerializer = new TagDecorator(1, wireType, this.IsStrict, protoSerializer);
                    protoSerializer = new NullDecorator(this.model, protoSerializer);
                    protoSerializer = new TagDecorator(this.fieldNumber, WireType.StartGroup, false, protoSerializer);
                }
                else
                {
                    protoSerializer = new TagDecorator(this.fieldNumber, wireType, this.IsStrict, protoSerializer);
                }
                if (this.itemType != null)
                {
                    if (!this.SupportNull)
                    {
                        if (Helpers.GetUnderlyingType(this.itemType) == null)
                        {
                            Type type2 = this.itemType;
                        }
                    }
                    else
                    {
                        Type type3 = this.itemType;
                    }
                    if (this.memberType.IsArray)
                    {
                        protoSerializer = new ArrayDecorator(this.model, protoSerializer, this.fieldNumber, this.IsPacked, wireType, this.memberType, this.OverwriteList, this.SupportNull);
                    }
                    else
                    {
                        protoSerializer = ListDecorator.Create(this.model, this.memberType, this.defaultType, protoSerializer, this.fieldNumber, this.IsPacked, wireType, this.member != null && PropertyDecorator.CanWrite(this.model, this.member), this.OverwriteList, this.SupportNull);
                    }
                }
                else if (this.defaultValue != null && !this.IsRequired && this.getSpecified == null)
                {
                    protoSerializer = new DefaultValueDecorator(this.model, this.defaultValue, protoSerializer);
                }
                if (this.memberType == this.model.MapType(typeof(Uri)))
                {
                    protoSerializer = new UriDecorator(this.model, protoSerializer);
                }
                if (this.member != null)
                {
                    if (this.member is PropertyInfo)
                    {
                        protoSerializer = new PropertyDecorator(this.model, this.parentType, (PropertyInfo)this.member, protoSerializer);
                    }
                    else
                    {
                        if (!(this.member is FieldInfo))
                        {
                            throw new InvalidOperationException();
                        }
                        protoSerializer = new FieldDecorator(this.parentType, (FieldInfo)this.member, protoSerializer);
                    }
                    if (this.getSpecified != null || this.setSpecified != null)
                    {
                        protoSerializer = new MemberSpecifiedDecorator(this.getSpecified, this.setSpecified, protoSerializer);
                    }
                }
                result = protoSerializer;
            }
            finally
            {
                this.model.ReleaseLock(opaqueToken);
            }
            return(result);
        }
        public override string GetSchema(Type type)
        {
            BasicList basicList = new BasicList();
            MetaType  metaType  = null;
            bool      flag      = false;

            if (type == null)
            {
                BasicList.NodeEnumerator enumerator = types.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    MetaType surrogateOrBaseOrSelf = ((MetaType)enumerator.Current).GetSurrogateOrBaseOrSelf(deep: false);
                    if (!basicList.Contains(surrogateOrBaseOrSelf))
                    {
                        basicList.Add(surrogateOrBaseOrSelf);
                        CascadeDependents(basicList, surrogateOrBaseOrSelf);
                    }
                }
            }
            else
            {
                Type underlyingType = Helpers.GetUnderlyingType(type);
                if (underlyingType != null)
                {
                    type = underlyingType;
                }
                flag = (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out WireType _, asReference: false, dynamicType: false, overwriteList: false, allowComplexTypes: false) != null);
                if (!flag)
                {
                    int num = FindOrAddAuto(type, demand: false, addWithContractOnly: false, addEvenIfAutoDisabled: false);
                    if (num < 0)
                    {
                        throw new ArgumentException("The type specified is not a contract-type", "type");
                    }
                    metaType = ((MetaType)types[num]).GetSurrogateOrBaseOrSelf(deep: false);
                    basicList.Add(metaType);
                    CascadeDependents(basicList, metaType);
                }
            }
            StringBuilder stringBuilder = new StringBuilder();
            string        text          = null;

            if (!flag)
            {
                foreach (MetaType item in (IEnumerable)((metaType == null) ? types : basicList))
                {
                    if (!item.IsList)
                    {
                        string @namespace = item.Type.Namespace;
                        if (!Helpers.IsNullOrEmpty(@namespace) && [email protected]("System."))
                        {
                            if (text == null)
                            {
                                text = @namespace;
                            }
                            else if (!(text == @namespace))
                            {
                                text = null;
                                break;
                            }
                        }
                    }
                }
            }
            if (!Helpers.IsNullOrEmpty(text))
            {
                stringBuilder.Append("package ").Append(text).Append(';');
                Helpers.AppendLine(stringBuilder);
            }
            bool          requiresBclImport = false;
            StringBuilder stringBuilder2    = new StringBuilder();

            MetaType[] array = new MetaType[basicList.Count];
            basicList.CopyTo(array, 0);
            Array.Sort(array, MetaType.Comparer.Default);
            if (flag)
            {
                Helpers.AppendLine(stringBuilder2).Append("message ").Append(type.Name)
                .Append(" {");
                MetaType.NewLine(stringBuilder2, 1).Append("optional ").Append(GetSchemaTypeName(type, DataFormat.Default, asReference: false, dynamicType: false, ref requiresBclImport))
                .Append(" value = 1;");
                Helpers.AppendLine(stringBuilder2).Append('}');
            }
            else
            {
                foreach (MetaType metaType3 in array)
                {
                    if (!metaType3.IsList || metaType3 == metaType)
                    {
                        metaType3.WriteSchema(stringBuilder2, 0, ref requiresBclImport);
                    }
                }
            }
            if (requiresBclImport)
            {
                stringBuilder.Append("import \"bcl.proto\"; // schema for protobuf-net's handling of core .NET types");
                Helpers.AppendLine(stringBuilder);
            }
            return(Helpers.AppendLine(stringBuilder.Append(stringBuilder2)).ToString());
        }