Exemplo n.º 1
0
 public WorkBookBD(string fileName, bool loadFile)
 {
     this.FileName = fileName;
     if (loadFile)
     {
         xml = XElement.Load(fileName);
     }
     else
     {
         createTree();
     }
     typeList = new TypeListCollection();
     copyList = new CopyListCollection();
     typeInfo = new TypeModel();
     history = new WBOHistory(this);
     err = new WBOError(this);
 }
Exemplo n.º 2
0
 public MyViewModel()
 {
     Types = new ObservableCollection<TypeModel>();
     for (var a = 0; a < 5; a++)
     {
         var lvl1 = new TypeModel { Name = "Type " + a, Fields = new ObservableCollection<TypeModel>() };
         for (var b = 0; b < 5; b++)
         {
             var lvl2 = new TypeModel { Name = lvl1.Name + "." + b, Fields = new ObservableCollection<TypeModel>() };
             for (var c = 0; c < 5; c++)
             {
                 var lvl3 = new TypeModel { Name = lvl2.Name + "." + c, Fields = new ObservableCollection<TypeModel>() };
                 for (var d = 0; d < 5; d++)
                     lvl3.Fields.Add(new TypeModel { Name = lvl3.Name + "." + d, Fields = new ObservableCollection<TypeModel>() });
                 lvl2.Fields.Add(lvl3);
             }
             lvl1.Fields.Add(lvl2);
         }
         Types.Add(lvl1);
     }
 }
 public ProtobufInputFormatter(TypeModel typeModel)
 {
     SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(ContentType));
     this.SupportedMediaTypes.Add(ContentType);
     _typeModel = typeModel;
 }
Exemplo n.º 4
0
 static void TestEnumModel(TypeModel model)
 {
     var obj = model.GetSerializerCore <Foo>(default);
Exemplo n.º 5
0
 public static TypeRef FromDefinitionIndex(TypeModel model, int index)
 => new TypeRef
 {
     model = model, definitionIndex = index
 };
Exemplo n.º 6
0
 static bool SerializeDateTimeKind(TypeModel model)
 {
     return((bool)typeof(TypeModel).GetMethod(
                "SerializeDateTimeKind", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(model, null));
 }
Exemplo n.º 7
0
 public ProtocolBufferBinaryConverter()
 {
     _typeModel = TypeModelBuilder.Create <T>();
 }
Exemplo n.º 8
0
 public NullProtoWriter(TypeModel model, SerializationContext context) : base(model, context)
 {
 }
Exemplo n.º 9
0
 internal static bool TrySerializeAny(int fieldNumber, SerializerFeatures features, Type type, TypeModel model, ref ProtoWriter.State state, object value)
 => Get(type).TrySerializeAny(fieldNumber, features, model, ref state, value);
Exemplo n.º 10
0
 internal static bool TryDeserialize(ObjectScope scope, Type type, TypeModel model, ref ProtoReader.State state, ref object value)
 => Get(type).TryDeserialize(scope, model, ref state, ref value);
Exemplo n.º 11
0
 protected override bool TryDeepClone(TypeModel model, ref object value)
 {
     value = model.DeepClone <T>(TypeHelper <T> .FromObject(value));
     return(true);
 }
Exemplo n.º 12
0
 internal static bool TrySerializeRoot(Type type, TypeModel model, ref ProtoWriter.State state, object value)
 => Get(type).TrySerializeRoot(model, ref state, value);
Exemplo n.º 13
0
            protected override bool TrySerializeAny(int fieldNumber, SerializerFeatures features, TypeModel model, ref ProtoWriter.State state, object value)
            {
                var serializer = TypeModel.TryGetSerializer <T>(model);

                if (serializer == null)
                {
                    return(false);
                }
                // note this null-check is non-trivial; for value-type T it promotes the null to a default
                T typed = TypeHelper <T> .FromObject(value);

                CheckAnyAuxFlow(features, serializer);
                if ((features & SerializerFeatures.CategoryMessageWrappedAtRoot) == SerializerFeatures.CategoryMessageWrappedAtRoot)
                {
                    if (fieldNumber != TypeModel.ListItemTag)
                    {
                        ThrowHelper.ThrowInvalidOperationException($"Special root-like wrapping is limited to field {TypeModel.ListItemTag}");
                    }
                    state.WriteAsRoot <T>(typed, serializer);
                }
                else
                {
                    state.WriteAny <T>(fieldNumber, features, typed, serializer);
                }
                return(true);
            }
Exemplo n.º 14
0
 internal static bool TryDeserializeRoot(Type type, TypeModel model, ref ProtoReader.State state, ref object value, bool autoCreate)
 => Get(type).TryDeserializeRoot(model, ref state, ref value, autoCreate);
Exemplo n.º 15
0
 public MethodModel(ApiModel api, string name, TypeModel returnType, int index)
     : base(api, name, returnType)
 {
     Index = index;
 }
Exemplo n.º 16
0
        /// <summary>
        /// Creates a new writer against a stream
        /// </summary>
        /// <param name="dest">The destination stream</param>
        /// <param name="model">The model to use for serialization; this can be null, but this will impair the ability to serialize sub-objects</param>
        /// <param name="context">Additional context about this serialization operation</param>
        public static ProtoWriter Create(Stream dest, TypeModel model, SerializationContext context = null)
#pragma warning disable CS0618
        => new ProtoWriter(dest, model, context);
Exemplo n.º 17
0
        private IEnumerable<PropertyModel> CreatePropertiesForElements(Uri source, TypeModel typeModel, XmlSchemaParticle particle,  IEnumerable<Particle> items)
        {
            var properties = new List<PropertyModel>();
            var order = 0;
            foreach (var item in items)
            {
                PropertyModel property = null;

                var element = item.XmlParticle as XmlSchemaElement;
                // ElementSchemaType must be non-null. This is not the case when maxOccurs="0".
                if (element != null && element.ElementSchemaType != null)
                {
                    var elementQualifiedName = element.ElementSchemaType.QualifiedName;

                    if (elementQualifiedName.IsEmpty)
                    {
                        elementQualifiedName = element.RefName;

                        if (elementQualifiedName.IsEmpty)
                        {
                            // inner type, have to generate a type name
                            var typeName = ToTitleCase(typeModel.Name) + ToTitleCase(element.QualifiedName.Name);
                            elementQualifiedName = new XmlQualifiedName(typeName, typeModel.XmlSchemaName.Namespace);
                            // try to avoid name clashes
                            if (NameExists(elementQualifiedName))
                                elementQualifiedName = new[] { "Item", "Property", "Element" }
                                    .Select(s => new XmlQualifiedName(elementQualifiedName.Name + s, elementQualifiedName.Namespace))
                                    .First(n => !NameExists(n));
                        }
                    }

                    var propertyName = ToTitleCase(element.QualifiedName.Name);
                    if (propertyName == typeModel.Name) propertyName += "Property"; // member names cannot be the same as their enclosing type

                    property = new PropertyModel(_configuration)
                    {
                        OwningType = typeModel,
                        XmlSchemaName = element.QualifiedName,
                        Name = propertyName,
                        Type = CreateTypeModel(source, element.ElementSchemaType, elementQualifiedName),
                        IsNillable = element.IsNillable,
                        IsNullable = item.MinOccurs < 1.0m,
                        IsCollection = item.MaxOccurs > 1.0m || particle.MaxOccurs > 1.0m, // http://msdn.microsoft.com/en-us/library/vstudio/d3hx2s7e(v=vs.100).aspx
                        DefaultValue = element.DefaultValue,
                        Form = element.Form == XmlSchemaForm.None ? element.GetSchema().ElementFormDefault : element.Form,
                        XmlNamespace = element.QualifiedName.Namespace != "" && element.QualifiedName.Namespace != typeModel.XmlSchemaName.Namespace ? element.QualifiedName.Namespace : null,
                    };
                }
                else
                {
                    var any = item.XmlParticle as XmlSchemaAny;
                    if (any != null)
                    {
                        property = new PropertyModel(_configuration)
                        {
                            OwningType = typeModel,
                            Name = "Any",
                            Type = new SimpleModel(_configuration) { ValueType = (UseXElementForAny ? typeof(XElement) : typeof(XmlElement)), UseDataTypeAttribute = false },
                            IsNullable = item.MinOccurs < 1.0m,
                            IsCollection = item.MaxOccurs > 1.0m || particle.MaxOccurs > 1.0m, // http://msdn.microsoft.com/en-us/library/vstudio/d3hx2s7e(v=vs.100).aspx
                            IsAny = true,
                        };
                    }
                    else
                    {
                        var groupRef = item.XmlParticle as XmlSchemaGroupRef;
                        if (groupRef != null)
                        {
                            if (GenerateInterfaces)
                                CreateTypeModel(new Uri(groupRef.SourceUri), Groups[groupRef.RefName], groupRef.RefName);

                            var groupItems = GetElements(groupRef.Particle);
                            var groupProperties = CreatePropertiesForElements(source, typeModel, item.XmlParticle, groupItems);
                            properties.AddRange(groupProperties);
                        }
                    }
                }

                // Discard duplicate property names. This is most likely due to:
                // - Choice or
                // - Element and attribute with the same name
                if (property != null && !properties.Any(p => p.Name == property.Name))
                {
                    var itemDocs = GetDocumentation(item.XmlParticle);
                    property.Documentation.AddRange(itemDocs);

                    if (EmitOrder)
                        property.Order = order++;
                    property.IsDeprecated = itemDocs.Any(d => d.Text.StartsWith("DEPRECATED"));

                    properties.Add(property);
                }
            }

            return properties;
        }
Exemplo n.º 18
0
 internal static bool TryDeepClone(Type type, TypeModel model, ref object value)
 => Get(type).TryDeepClone(model, ref value);
Exemplo n.º 19
0
 public Int64Serializer(TypeModel model)
 {
 }
Exemplo n.º 20
0
 internal static bool IsKnownType(Type type, TypeModel model, CompatibilityLevel ambient)
 => Get(type).IsKnownType(model, ambient);
Exemplo n.º 21
0
 public ImaqServer(TypeModel customSerializer)
     : base(new ImaqCoordinator(),
            (r, c) => new ImaqFlow(r, c),
            customSerializer)
 {
 }
Exemplo n.º 22
0
 internal static bool CanSerialize(Type type, TypeModel model, out SerializerFeatures features)
 => Get(type).CanSerialize(model, out features);
Exemplo n.º 23
0
 public ProtocolBufferBinaryConverter(Model model)
 {
     _typeModel = TypeModelBuilder.Create(model);
 }
Exemplo n.º 24
0
 public StreamProtoReader(Stream source, TypeModel model, SerializationContext context, long length)
 => Init(source, model, context, length);
Exemplo n.º 25
0
 public static TypeRef FromReferenceIndex(TypeModel model, int index)
 => new TypeRef
 {
     model = model, referenceIndex = index
 };
Exemplo n.º 26
0
 public StreamProtoReader(Stream source, TypeModel model, SerializationContext context)
 => Init(source, model, context, TO_EOF);
Exemplo n.º 27
0
 // Token: 0x06000243 RID: 579 RVA: 0x000022E5 File Offset: 0x000004E5
 public SByteSerializer(TypeModel model)
 {
 }
Exemplo n.º 28
0
 public static ProtoReader Create(Stream source, TypeModel model, SerializationContext context = null, long length = TO_EOF)
 => Create(source, model, (object)context, length);
Exemplo n.º 29
0
        public TypeSerializer(TypeModel model, Type forType, int[] fieldNumbers, IProtoSerializer[] serializers, MethodInfo[] baseCtorCallbacks, bool isRootType, bool useConstructor, CallbackSet callbacks, Type constructType, MethodInfo factory)
        {
            Helpers.DebugAssert(forType != null);
            Helpers.DebugAssert(fieldNumbers != null);
            Helpers.DebugAssert(serializers != null);
            Helpers.DebugAssert(fieldNumbers.Length == serializers.Length);

            Helpers.Sort(fieldNumbers, serializers);
            bool hasSubTypes = false;

            for (int i = 1; i < fieldNumbers.Length; i++)
            {
                if (fieldNumbers[i] == fieldNumbers[i - 1])
                {
                    throw new InvalidOperationException("Duplicate field-number detected; " +
                                                        fieldNumbers[i].ToString() + " on: " + forType.FullName);
                }
                if (!hasSubTypes && serializers[i].ExpectedType != forType)
                {
                    hasSubTypes = true;
                }
            }
            this.forType = forType;
            this.factory = factory;

            if (constructType == null)
            {
                constructType = forType;
            }
            else
            {
                if (!forType.IsAssignableFrom(constructType))
                {
                    throw new InvalidOperationException(forType.FullName + " cannot be assigned from " + constructType.FullName);
                }
            }
            this.constructType  = constructType;
            this.serializers    = serializers;
            this.fieldNumbers   = fieldNumbers;
            this.callbacks      = callbacks;
            this.isRootType     = isRootType;
            this.useConstructor = useConstructor;

            if (baseCtorCallbacks != null && baseCtorCallbacks.Length == 0)
            {
                baseCtorCallbacks = null;
            }
            this.baseCtorCallbacks = baseCtorCallbacks;

            if (Helpers.GetUnderlyingType(forType) != null)
            {
                throw new ArgumentException("Cannot create a TypeSerializer for nullable types", "forType");
            }

            if (model.MapType(iextensible).IsAssignableFrom(forType))
            {
                if (forType.IsValueType || !isRootType || hasSubTypes)
                {
                    throw new NotSupportedException("IExtensible is not supported in structs or classes with inheritance");
                }
                isExtensible = true;
            }
            hasConstructor = !constructType.IsAbstract && Helpers.GetConstructor(constructType, Helpers.EmptyTypes, true) != null;

            if (constructType != forType && useConstructor && !hasConstructor)
            {
                throw new ArgumentException("The supplied default implementation cannot be created: " + constructType.FullName, "constructType");
            }
        }
        internal static bool IdentifyImmutable(TypeModel model, Type declaredType, out MethodInfo builderFactory, out PropertyInfo isEmpty, out PropertyInfo length, out MethodInfo add, out MethodInfo addRange, out MethodInfo finish)
        {
            builderFactory = add = addRange = finish = null;
            isEmpty        = length = null;
            if (model == null || declaredType == null)
            {
                return(false);
            }
#if COREFX || PROFILE259
            TypeInfo declaredTypeInfo = declaredType.GetTypeInfo();
#else
            Type declaredTypeInfo = declaredType;
#endif

            // try to detect immutable collections; firstly, they are all generic, and all implement IReadOnlyCollection<T> for some T
            if (!declaredTypeInfo.IsGenericType)
            {
                return(false);
            }

#if COREFX || PROFILE259
            Type[] typeArgs = declaredTypeInfo.GenericTypeArguments, effectiveType;
#else
            Type[] typeArgs = declaredTypeInfo.GetGenericArguments(), effectiveType;
#endif
            switch (typeArgs.Length)
            {
            case 1:
                effectiveType = typeArgs;
                break;     // fine

            case 2:
                Type kvp = model.MapType(typeof(System.Collections.Generic.KeyValuePair <,>));
                if (kvp == null)
                {
                    return(false);
                }
                kvp           = kvp.MakeGenericType(typeArgs);
                effectiveType = new Type[] { kvp };
                break;

            default:
                return(false);    // no clue!
            }

            if (ResolveIReadOnlyCollection(declaredType, null) == null)
            {
                return(false);                                                        // no IReadOnlyCollection<T> found
            }
            // and we want to use the builder API, so for generic Foo<T> or IFoo<T> we want to use Foo.CreateBuilder<T>
            string name = declaredType.Name;
            int    i    = name.IndexOf('`');
            if (i <= 0)
            {
                return(false);
            }
            name = declaredTypeInfo.IsInterface ? name.Substring(1, i - 1) : name.Substring(0, i);

            Type outerType = model.GetType(declaredType.Namespace + "." + name, declaredTypeInfo.Assembly);
            // I hate special-cases...
            if (outerType == null && name == "ImmutableSet")
            {
                outerType = model.GetType(declaredType.Namespace + ".ImmutableHashSet", declaredTypeInfo.Assembly);
            }
            if (outerType == null)
            {
                return(false);
            }

#if PROFILE259
            foreach (MethodInfo method in outerType.GetTypeInfo().DeclaredMethods)
#else
            foreach (MethodInfo method in outerType.GetMethods())
#endif
            {
                if (!method.IsStatic || method.Name != "CreateBuilder" || !method.IsGenericMethodDefinition || method.GetParameters().Length != 0 ||
                    method.GetGenericArguments().Length != typeArgs.Length)
                {
                    continue;
                }

                builderFactory = method.MakeGenericMethod(typeArgs);
                break;
            }
            Type voidType = model.MapType(typeof(void));
            if (builderFactory == null || builderFactory.ReturnType == null || builderFactory.ReturnType == voidType)
            {
                return(false);
            }

#if COREFX
            TypeInfo typeInfo = declaredType.GetTypeInfo();
#else
            Type typeInfo = declaredType;
#endif
            isEmpty = Helpers.GetProperty(typeInfo, "IsDefaultOrEmpty", false); //struct based immutabletypes can have both a "default" and "empty" state
            if (isEmpty == null)
            {
                isEmpty = Helpers.GetProperty(typeInfo, "IsEmpty", false);
            }
            if (isEmpty == null)
            {
                //Fallback to checking length if a "IsEmpty" property is not found
                length = Helpers.GetProperty(typeInfo, "Length", false);
                if (length == null)
                {
                    length = Helpers.GetProperty(typeInfo, "Count", false);
                }

                if (length == null)
                {
                    length = Helpers.GetProperty(ResolveIReadOnlyCollection(declaredType, effectiveType[0]), "Count", false);
                }

                if (length == null)
                {
                    return(false);
                }
            }

            add = Helpers.GetInstanceMethod(builderFactory.ReturnType, "Add", effectiveType);
            if (add == null)
            {
                return(false);
            }

            finish = Helpers.GetInstanceMethod(builderFactory.ReturnType, "ToImmutable", Helpers.EmptyTypes);
            if (finish == null || finish.ReturnType == null || finish.ReturnType == voidType)
            {
                return(false);
            }

            if (!(finish.ReturnType == declaredType || Helpers.IsAssignableFrom(declaredType, finish.ReturnType)))
            {
                return(false);
            }

            addRange = Helpers.GetInstanceMethod(builderFactory.ReturnType, "AddRange", new Type[] { declaredType });
            if (addRange == null)
            {
                Type enumerable = model.MapType(typeof(System.Collections.Generic.IEnumerable <>), false);
                if (enumerable != null)
                {
                    addRange = Helpers.GetInstanceMethod(builderFactory.ReturnType, "AddRange", new Type[] { enumerable.MakeGenericType(effectiveType) });
                }
            }

            return(true);
        }
Exemplo n.º 31
0
 internal string SerializeType(Type type)
 {
     return(TypeModel.SerializeType(model, type));
 }
Exemplo n.º 32
0
 private CompiledSerializer(IProtoTypeSerializer head, TypeModel model)
 {
     this.head    = head;
     serializer   = Compiler.CompilerContext.BuildSerializer(head, model);
     deserializer = Compiler.CompilerContext.BuildDeserializer(head, model);
 }
Exemplo n.º 33
0
        private IEnumerable<PropertyModel> CreatePropertiesForAttributes(Uri source, TypeModel typeModel, IEnumerable<XmlSchemaObject> items)
        {
            var properties = new List<PropertyModel>();

            foreach (var item in items)
            {
                var attribute = item as XmlSchemaAttribute;
                if (attribute != null)
                {
                    if (attribute.Use != XmlSchemaUse.Prohibited)
                    {
                        var attributeQualifiedName = attribute.AttributeSchemaType.QualifiedName;

                        if (attributeQualifiedName.IsEmpty)
                        {
                            attributeQualifiedName = attribute.QualifiedName;

                            if (attributeQualifiedName.IsEmpty || attributeQualifiedName.Namespace == "")
                            {
                                // inner type, have to generate a type name
                                var typeName = ToTitleCase(typeModel.Name) + ToTitleCase(attribute.QualifiedName.Name);
                                attributeQualifiedName = new XmlQualifiedName(typeName, typeModel.XmlSchemaName.Namespace);
                                // try to avoid name clashes
                                if (NameExists(attributeQualifiedName))
                                    attributeQualifiedName = new[] { "Item", "Property", "Element" }
                                        .Select(s => new XmlQualifiedName(attributeQualifiedName.Name + s, attributeQualifiedName.Namespace))
                                        .First(n => !NameExists(n));
                            }
                        }

                        var attributeName = ToTitleCase(attribute.QualifiedName.Name);
                        if (attributeName == typeModel.Name) attributeName += "Property"; // member names cannot be the same as their enclosing type

                        var property = new PropertyModel(_configuration)
                        {
                            OwningType = typeModel,
                            Name = attributeName,
                            XmlSchemaName = attribute.QualifiedName,
                            Type = CreateTypeModel(source, attribute.AttributeSchemaType, attributeQualifiedName),
                            IsAttribute = true,
                            IsNullable = attribute.Use != XmlSchemaUse.Required,
                            DefaultValue = attribute.DefaultValue,
                            Form = attribute.Form == XmlSchemaForm.None ? attribute.GetSchema().AttributeFormDefault : attribute.Form,
                            XmlNamespace = attribute.QualifiedName.Namespace != "" && attribute.QualifiedName.Namespace != typeModel.XmlSchemaName.Namespace ? attribute.QualifiedName.Namespace : null,
                        };

                        var attributeDocs = GetDocumentation(attribute);
                        property.Documentation.AddRange(attributeDocs);

                        properties.Add(property);
                    }
                }
                else
                {
                    var attributeGroupRef = item as XmlSchemaAttributeGroupRef;
                    if (attributeGroupRef != null)
                    {
                        if (GenerateInterfaces)
                            CreateTypeModel(new Uri(attributeGroupRef.SourceUri), AttributeGroups[attributeGroupRef.RefName], attributeGroupRef.RefName);

                        var groupItems = AttributeGroups[attributeGroupRef.RefName].Attributes;
                        var groupProperties = CreatePropertiesForAttributes(source, typeModel, groupItems.Cast<XmlSchemaObject>());
                        properties.AddRange(groupProperties);
                    }
                }
            }

            return properties;
        }
Exemplo n.º 34
0
 /// <summary>
 /// Queries an extensible object for an additional (unexpected) data-field for the instance.
 /// Each occurrence of the field is yielded separately, making this usage suitable for "repeated"
 /// (list) fields.
 /// </summary>
 /// <remarks>The extended data is processed lazily as the enumerator is iterated.</remarks>
 /// <param name="model">The model to use for configuration.</param>
 /// <param name="type">The data-type of the field.</param>
 /// <param name="instance">The extensible object to obtain the value from.</param>
 /// <param name="tag">The field identifier; the tag should not be defined as a known data-field for the instance.</param>
 /// <param name="format">The data-format to use when decoding the value.</param>
 /// <returns>An enumerator that yields each occurrence of the field.</returns>
 public static IEnumerable GetValues(TypeModel model, System.Type type, IExtensible instance, int tag, DataFormat format)
 {
     return(ExtensibleUtil.GetExtendedValues(model, type, instance, tag, format, false, false));
 }
Exemplo n.º 35
0
 private static void Verify(GoalPlanningModel1 obj, TypeModel model, string caption)
 {
     var clone = (GoalPlanningModel1)model.DeepClone(obj);
     Assert.IsNull(clone.PublishedGoals, caption + ":published");
     Assert.IsNotNull(clone.ProposedGoals, caption + ":proposed");
     Assert.AreEqual(1, clone.ProposedGoals.Count(), caption + ":count");
     Assert.AreEqual(23, clone.ProposedGoals.Single().X, caption + ":X");
 }
Exemplo n.º 36
0
 /// <summary>
 /// Appends the value as an additional (unexpected) data-field for the instance.
 /// Note that for non-repeated sub-objects, this equates to a merge operation;
 /// for repeated sub-objects this adds a new instance to the set; for simple
 /// values the new value supercedes the old value.
 /// </summary>
 /// <remarks>Note that appending a value does not remove the old value from
 /// the stream; avoid repeatedly appending values for the same field.</remarks>
 /// <param name="model">The model to use for configuration.</param>
 /// <param name="format">The data-format to use when encoding the value.</param>
 /// <param name="instance">The extensible object to append the value to.</param>
 /// <param name="tag">The field identifier; the tag should not be defined as a known data-field for the instance.</param>
 /// <param name="value">The value to append.</param>
 public static void AppendValue(TypeModel model, IExtensible instance, int tag, DataFormat format, object value)
 {
     ExtensibleUtil.AppendExtendValue(model, instance, tag, format, value);
 }