示例#1
0
        private bool ScalarProperty_ReadPropertiesFromAttributes(SerializationContext serializationContext,
                                                                 ScalarProperty scalarProperty, XmlReader reader)
        {
            // Type
            if (!serializationContext.Result.Failed)
            {
                string attribType = DONetEntityModelDesignerSerializationHelper.Instance.ReadAttribute(serializationContext, scalarProperty, reader, "type");
                if (!string.IsNullOrEmpty(attribType))
                {
                    string typeDisplayName = SystemPrimitiveTypesConverter.GetDisplayName(attribType);
                    if (!string.IsNullOrEmpty(typeDisplayName))
                    {
                        Type        clrType     = SystemPrimitiveTypesConverter.GetClrType(typeDisplayName);
                        Guid        typeId      = SystemPrimitiveTypesConverter.GetTypeId(clrType);
                        IModelRoot  entityModel = scalarProperty.Store.GetEntityModel();
                        IDomainType domainType  = entityModel.GetDomainType(typeId);
                        if (domainType == null)
                        {
                            domainType =
                                entityModel.BuildInDomainTypes.SingleOrDefault(type => type.FullName == "System.String");
                        }

                        scalarProperty.Type = (DomainType)domainType;

                        return(true);
                    }
                    else
                    {   // Invalid property value, ignored.
                        EntityModelDesignerSerializationBehaviorSerializationMessages.IgnoredPropertyValue(serializationContext, reader, "type", typeof(global::System.String), attribType);
                    }
                }
            }

            return(false);
        }
示例#2
0
        public ScalarProperty AddScalarProperty(string name, Type type)
        {
            Guid        typeId      = SystemPrimitiveTypesConverter.GetTypeId(type);
            IDomainType domainType  = null;
            IModelRoot  entityModel = this.Store.GetEntityModel();

            if (typeId != default(Guid))
            {
                domainType = entityModel.GetDomainType(typeId);
            }
            else
            {
                domainType = entityModel.DomainTypes.SingleOrDefault(item => item.FullName == type.FullName);
            }

            if (domainType != null)
            {
                return(AddScalarProperty(name, (DomainType)domainType));
            }

            throw new ArgumentOutOfRangeException("type is not registered as Domain Type!");
        }
示例#3
0
        private void CustomReadPropertiesFromAttributes(SerializationContext serializationContext, ModelElement element, XmlReader reader)
        {
            // Always call the base class so any extensions are deserialized
            base.ReadPropertiesFromAttributes(serializationContext, element, reader);

            ScalarProperty instanceOfScalarProperty = element as ScalarProperty;

            global::System.Diagnostics.Debug.Assert(instanceOfScalarProperty != null, "Expecting an instance of ScalarProperty");

            ModelUpgrader.Instance.RequestSerializationUpgrade(
                upgrader => upgrader.ReadPropertiesFromAttributes(serializationContext, instanceOfScalarProperty, reader));

            // Type

/*
 *          if (!serializationContext.Result.Failed)
 *          {
 *              string attribType = DONetEntityModelDesignerSerializationHelper.Instance.ReadAttribute(serializationContext, element, reader, "type");
 *              if (!string.IsNullOrEmpty(attribType))
 *              {
 *                  string typeDisplayName = SystemPrimitiveTypesConverter.GetDisplayName(attribType);
 *                  if (!string.IsNullOrEmpty(typeDisplayName))
 *                  {
 *                      Type clrType = SystemPrimitiveTypesConverter.GetClrType(typeDisplayName);
 *                      Guid typeId = SystemPrimitiveTypesConverter.GetTypeId(clrType);
 *                      IModelRoot entityModel = element.Store.GetEntityModel();
 *                      IDomainType domainType = entityModel.GetDomainType(typeId);
 *                      if (domainType == null)
 *                      {
 *                          domainType =
 *                              entityModel.BuildInDomainTypes.SingleOrDefault(type => type.FullName == "System.String");
 *                      }
 *
 *                      instanceOfScalarProperty.Type = (DomainType) domainType;
 *
 *                      element.Store.PropertyBag["@@OldModelConversions"] = true;
 *                  }
 *                  else
 *                  {	// Invalid property value, ignored.
 *                      EntityModelDesignerSerializationBehaviorSerializationMessages.IgnoredPropertyValue(serializationContext, reader, "type", typeof(global::System.String), attribType);
 *                  }
 *              }
 *          }
 */

            // typeId
            if (!serializationContext.Result.Failed)
            {
                string attribType = DONetEntityModelDesignerSerializationHelper.Instance.ReadAttribute(serializationContext, element, reader, "typeId");
                if (!string.IsNullOrEmpty(attribType))
                {
                    Guid        typeId      = new Guid(attribType);
                    IModelRoot  entityModel = element.Store.GetEntityModel();
                    IDomainType domainType  = entityModel.GetDomainType(typeId);
                    if (domainType == null)
                    {
                        domainType =
                            entityModel.BuildInDomainTypes.SingleOrDefault(type => type.FullName == "System.String");
                    }

                    instanceOfScalarProperty.Type = (DomainType)domainType;
                }
            }
        }