internal override void OnBeforeSerializeContents(WorkflowMarkupSerializationManager serializationManager, object obj)
        {
            base.OnBeforeSerializeContents(serializationManager, obj);

            serializationManager.ExtendedPropertiesProviders.Add(this);
            this.keylookupDictionary = new Hashtable();
        }
Ejemplo n.º 2
0
        protected internal override object DeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value)
        {
            if (serializationManager == null)
            {
                throw new ArgumentNullException("serializationManager");
            }
            if (propertyType == null)
            {
                throw new ArgumentNullException("propertyType");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            // Work around For Bind based properties whose base type is an
            // ICollection<string> or its derivative, special case! (A synchronization
            // handle cannot begin with a * because it won't be a language independent
            // identifier :) )
            if (IsValidCompactAttributeFormat(value))
            {
                return(DeserializeFromCompactFormat(serializationManager, serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader, value));
            }
            else
            {
                return(SynchronizationHandlesTypeConverter.UnStringify(value));
            }
        }
        protected override void OnAfterSerialize(WorkflowMarkupSerializationManager serializationManager, object obj)
        {
            base.OnAfterSerialize(serializationManager, obj);

            serializationManager.ExtendedPropertiesProviders.Remove(this);
            this.keylookupDictionary = null;
        }
        protected virtual InstanceDescriptor GetInstanceDescriptor(WorkflowMarkupSerializationManager serializationManager, object value)
        {
            MarkupExtension markupExtension = value as MarkupExtension;
            if (markupExtension == null)
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(MarkupExtension).FullName), "value");
            return new InstanceDescriptor(markupExtension.GetType().GetConstructor(new Type[0]), null);

        }
Ejemplo n.º 5
0
 public XmlQualifiedName GetXmlQualifiedName(WorkflowMarkupSerializationManager manager, out string prefix)
 {
     prefix = String.Empty;
     if (OnGetXmlQualifiedName != null)
     {
         return(OnGetXmlQualifiedName(this, manager, out prefix));
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 6
0
        protected internal override string SerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
        {
            if (serializationManager == null)
            {
                throw new ArgumentNullException("serializationManager");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            CodeTypeReference reference = value as CodeTypeReference;

            if (reference == null)
            {
                return(string.Empty);
            }

            // make the typename as best we can, and try to get the fully qualified name
            // if a type is used in an assembly not referenced, GetType will complain
            string typeName = ConvertTypeReferenceToString(reference);
            Type   type     = serializationManager.GetType(typeName);

            if (type == null)
            {
                // TypeProvider can't find it, see if it's a common type in mscorlib
                type = Type.GetType(typeName, false);
                if (type == null)
                {
                    // still no luck finding it, so simply save the name without assembly information
                    // this is equivalent to what happened before
                    return(typeName);
                }
            }
            //
            // If we get a real type make sure that we get the correct fully qualified name for the target framework version
            string assemblyFullName = null;

            // If we didn't find an assembly value it is either a local type or something is wrong
            // However per the general guidance on multi-targeting it is up to the caller
            // to make sure that writers (such as Xoml) are given types that exist in the target framework
            // This makes it the job of the rules designer or rules validator to not call the Xoml stack
            // with types that do not exist in the target framework
            if (string.IsNullOrEmpty(assemblyFullName))
            {
                typeName = type.AssemblyQualifiedName;
            }
            else
            {
                typeName = string.Format(CultureInfo.InvariantCulture, "{0}, {1}", type.FullName, assemblyFullName);
            }
            return(typeName);
        }
Ejemplo n.º 7
0
 private static string GetAssemblyName(Type type, WorkflowMarkupSerializationManager manager)
 {
     //
     // Handle DesignTimeType
     if (type.Assembly == null)
     {
         return(string.Empty);
     }
     else
     {
         return(type.Assembly.FullName);
     }
 }
Ejemplo n.º 8
0
        protected internal override bool CanSerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
        {
            if (serializationManager == null)
            {
                throw new ArgumentNullException("serializationManager");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            return(value is ICollection <String>);
        }
Ejemplo n.º 9
0
        protected internal override string SerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
        {
            if (serializationManager == null)
            {
                throw new ArgumentNullException("serializationManager");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            return(SynchronizationHandlesTypeConverter.Stringify(value as ICollection <String>));
        }
        protected internal override bool ShouldSerializeValue(WorkflowMarkupSerializationManager serializationManager, object value)
        {
            if (value == null)
            {
                return(false);
            }

            if (!(value is IDictionary))
            {
                throw new InvalidOperationException(SR.GetString(SR.Error_DictionarySerializerNonDictionaryObject));
            }

            return(((IDictionary)value).Count > 0);
        }
        protected internal override void AddChild(WorkflowMarkupSerializationManager serializationManager, object parentObj, object childObj)
        {
            if (parentObj == null)
            {
                throw new ArgumentNullException("parentObj");
            }

            if (!IsValidCollectionType(parentObj.GetType()))
            {
                throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, parentObj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection <>).FullName));
            }

            parentObj.GetType().InvokeMember("Add", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, parentObj, new object[] { childObj }, CultureInfo.InvariantCulture);
        }
        protected internal override void ClearChildren(WorkflowMarkupSerializationManager serializationManager, object deserializedObject)
        {
            if (deserializedObject == null)
            {
                throw new ArgumentNullException("deserializedObject");
            }

            IDictionary dictionary = deserializedObject as IDictionary;

            if (dictionary == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.Error_DictionarySerializerNonDictionaryObject));
            }

            dictionary.Clear();
        }
        protected override InstanceDescriptor GetInstanceDescriptor(WorkflowMarkupSerializationManager serializationManager, object value)
        {
            TypeExtension typeExtension = value as TypeExtension;

            if (typeExtension == null)
            {
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(TypeExtension).FullName), "value");
            }
            if (typeExtension.Type != null)
            {
                return(new InstanceDescriptor(typeof(TypeExtension).GetConstructor(new Type[] { typeof(System.Type) }),
                                              new object[] { typeExtension.Type }));
            }
            return(new InstanceDescriptor(typeof(TypeExtension).GetConstructor(new Type[] { typeof(string) }),
                                          new object[] { typeExtension.TypeName }));
        }
        protected internal override IList GetChildren(WorkflowMarkupSerializationManager serializationManager, object obj)
        {
            IDictionary dictionary = obj as IDictionary;

            if (dictionary == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.Error_DictionarySerializerNonDictionaryObject));
            }

            List <object> childEntries = new List <object>();

            foreach (DictionaryEntry dictionaryEntry in dictionary)
            {
                childEntries.Add(dictionaryEntry);
            }
            return(childEntries);
        }
        protected internal override void ClearChildren(WorkflowMarkupSerializationManager serializationManager, object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (!IsValidCollectionType(obj.GetType()))
            {
                throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection <>).FullName));
            }

            ICollection collection = obj as ICollection;

            if (collection == null)
            {
                obj.GetType().InvokeMember("Clear", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, obj, new object[] { }, CultureInfo.InvariantCulture);
            }
        }
        protected internal override bool ShouldSerializeValue(WorkflowMarkupSerializationManager serializationManager, object value)
        {
            if (value == null)
            {
                return(false);
            }

            if (!IsValidCollectionType(value.GetType()))
            {
                throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, value.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection <>).FullName));
            }

            IEnumerable enumerable = value as IEnumerable;

            foreach (object obj in enumerable)
            {
                return(true);
            }

            return(false);
        }
        internal override ExtendedPropertyInfo[] GetExtendedProperties(WorkflowMarkupSerializationManager manager, object extendee)
        {
            List <ExtendedPropertyInfo> extendedProperties = new List <ExtendedPropertyInfo>();
            DictionaryEntry?            entry = null;

            if (manager.WorkflowMarkupStack[typeof(DictionaryEntry)] != null)
            {
                entry = (DictionaryEntry)manager.WorkflowMarkupStack[typeof(DictionaryEntry)];
            }
            if (this.deserializingDictionary || (entry.HasValue && entry.Value.Value == extendee))
            {
                ExtendedPropertyInfo extendedProperty =
                    new ExtendedPropertyInfo(typeof(DictionaryEntry).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance),
                                             new GetValueHandler(OnGetKeyValue),
                                             new SetValueHandler(OnSetKeyValue),
                                             new GetQualifiedNameHandler(OnGetXmlQualifiedName), manager);

                extendedProperties.Add(extendedProperty);
            }
            return(extendedProperties.ToArray());
        }
Ejemplo n.º 18
0
        internal static bool IsExtendedProperty(WorkflowMarkupSerializationManager manager, IList <PropertyInfo> propInfos, XmlQualifiedName xmlQualifiedName)
        {
            foreach (PropertyInfo propInfo in propInfos)
            {
                ExtendedPropertyInfo extendedProperty = propInfo as ExtendedPropertyInfo;
                if (extendedProperty == null)
                {
                    continue;
                }

                string           prefix = String.Empty;
                XmlQualifiedName qualifiedPropertyName = extendedProperty.GetXmlQualifiedName(manager, out prefix);
                if (qualifiedPropertyName.Name.Equals(xmlQualifiedName.Name, StringComparison.Ordinal) &&
                    qualifiedPropertyName.Namespace.Equals(xmlQualifiedName.Namespace, StringComparison.Ordinal))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 19
0
        internal static bool IsExtendedProperty(WorkflowMarkupSerializationManager manager, XmlQualifiedName xmlQualifiedName)
        {
            bool   isExtendedProperty = false;
            object extendee           = manager.Context.Current;

            if (extendee != null)
            {
                foreach (ExtendedPropertyInfo extendedProperty in manager.GetExtendedProperties(extendee))
                {
                    string           prefix = String.Empty;
                    XmlQualifiedName qualifiedPropertyName = extendedProperty.GetXmlQualifiedName(manager, out prefix);
                    if (qualifiedPropertyName.Name.Equals(xmlQualifiedName.Name, StringComparison.Ordinal) &&
                        qualifiedPropertyName.Namespace.Equals(xmlQualifiedName.Namespace, StringComparison.Ordinal))
                    {
                        isExtendedProperty = true;
                        break;
                    }
                }
            }

            return(isExtendedProperty);
        }
        protected internal override void AddChild(WorkflowMarkupSerializationManager serializationManager, object parentObj, object childObj)
        {
            if (parentObj == null)
            {
                throw new ArgumentNullException("parentObj");
            }

            if (childObj == null)
            {
                throw new ArgumentNullException("childObj");
            }

            IDictionary dictionary = parentObj as IDictionary;

            if (dictionary == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.Error_DictionarySerializerNonDictionaryObject));
            }

            object key = null;

            foreach (DictionaryEntry entry in keylookupDictionary)
            {
                if ((!entry.Value.GetType().IsValueType&& entry.Value == childObj) ||
                    (entry.Value.GetType().IsValueType&& entry.Value.Equals(childObj)))
                {
                    key = entry.Key;
                    break;
                }
            }

            if (key == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.Error_DictionarySerializerKeyNotFound, childObj.GetType().FullName));
            }

            dictionary.Add(key, childObj);
            keylookupDictionary.Remove(key);
        }
Ejemplo n.º 21
0
        protected internal override object DeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value)
        {
            if (!propertyType.IsAssignableFrom(typeof(CodeTypeReference)))
            {
                return(null);
            }

            // if the string is empty or markup extension,
            // then the object is null
            if (string.IsNullOrEmpty(value) || IsValidCompactAttributeFormat(value))
            {
                return(null);
            }

            // value is the fully qualified name of the type
            // however, it may refer to non-existant assemblies, so we may get an error
            CodeTypeReference result;

            try
            {
                Type type = serializationManager.GetType(value);
                if (type != null)
                {
                    result = new CodeTypeReference(type);
                    result.UserData[QualifiedName] = type.AssemblyQualifiedName;
                    return(result);
                }
            }
            catch (Exception)
            {
                // something went wrong getting the type, so simply pass in the string and
                // let CodeTypeReference figure it out. Note that CodeTypeReference has a method
                // RipOffAssemblyInformationFromTypeName, so assembly names are ignored.
            }
            result = new CodeTypeReference(value);
            result.UserData[QualifiedName] = value;
            return(result);
        }
        protected internal override IList GetChildren(WorkflowMarkupSerializationManager serializationManager, object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }



            if (!IsValidCollectionType(obj.GetType()))
            {
                throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection <>).FullName));
            }

            IEnumerable enumerable = obj as IEnumerable;
            ArrayList   arrayList  = new ArrayList();

            foreach (object containedObj in enumerable)
            {
                arrayList.Add(containedObj);
            }
            return(arrayList);
        }
Ejemplo n.º 23
0
        internal static Type ResolveWellKnownTypes(WorkflowMarkupSerializationManager manager, string xmlns, string typeName)
        {
            Type resolvedType = null;

            List <WorkflowMarkupSerializerMapping> knownMappings = new List <WorkflowMarkupSerializerMapping>();

            if (xmlns.Equals(StandardXomlKeys.WorkflowXmlNs, StringComparison.Ordinal))
            {
                if (!WorkflowMarkupSerializerMapping.wellKnownTypes.TryGetValue(typeName, out resolvedType))
                {
                    if (typeName.StartsWith("Rule", StringComparison.OrdinalIgnoreCase) ||
                        typeName.EndsWith("Action", StringComparison.OrdinalIgnoreCase))
                    {
                        knownMappings.Add(WorkflowMarkupSerializerMapping.Rules);
                    }
                }
            }
            else if (xmlns.Equals(StandardXomlKeys.Definitions_XmlNs, StringComparison.Ordinal))
            {
                knownMappings.Add(WorkflowMarkupSerializerMapping.Serialization);
            }

            if (resolvedType == null)
            {
                foreach (WorkflowMarkupSerializerMapping mapping in knownMappings)
                {
                    string fullyQualifiedTypeName = mapping.ClrNamespace + "." + typeName + ", " + mapping.AssemblyName;
                    resolvedType = manager.GetType(fullyQualifiedTypeName);
                    if (resolvedType != null)
                    {
                        break;
                    }
                }
            }

            return(resolvedType);
        }
Ejemplo n.º 24
0
        internal static void GetMappingFromType(WorkflowMarkupSerializationManager manager, Type type, out WorkflowMarkupSerializerMapping matchingMapping, out IList <WorkflowMarkupSerializerMapping> collectedMappings)
        {
            matchingMapping   = null;
            collectedMappings = new List <WorkflowMarkupSerializerMapping>();

            string clrNamespace = type.Namespace ?? String.Empty;
            string xmlNamespace = String.Empty;
            string assemblyName = String.Empty;
            string prefix       = String.Empty;

            assemblyName = GetAssemblyName(type, manager);

            if (type.Assembly.FullName.Equals(AssemblyRef.ActivitiesAssemblyRef, StringComparison.Ordinal))
            {
                xmlNamespace = StandardXomlKeys.WorkflowXmlNs;
                prefix       = StandardXomlKeys.WorkflowPrefix;
            }
            else if (type.Assembly.FullName.Equals(AssemblyRef.DialogAssemblyRef, StringComparison.Ordinal))
            {
                xmlNamespace = StandardXomlKeys.WorkflowXmlNs;
                prefix       = StandardXomlKeys.WorkflowPrefix;
            }
            else if (type.Assembly == Assembly.GetExecutingAssembly())
            {
                xmlNamespace = StandardXomlKeys.WorkflowXmlNs;
                prefix       = StandardXomlKeys.WorkflowPrefix;
            }

            if (xmlNamespace.Length == 0)
            {
                //First lookup the type's assembly for XmlNsDefinitionAttribute
                object[] xmlnsDefinitions = type.Assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute), true);
                foreach (XmlnsDefinitionAttribute xmlnsDefinition in xmlnsDefinitions)
                {
                    xmlNamespace = xmlnsDefinition.XmlNamespace;
                    assemblyName = xmlnsDefinition.AssemblyName;

                    if (type.Assembly == manager.LocalAssembly)
                    {
                        assemblyName = String.Empty;
                    }
                    else if (String.IsNullOrEmpty(assemblyName))
                    {
                        assemblyName = GetAssemblyName(type, manager);
                    }

                    if (String.IsNullOrEmpty(xmlNamespace))
                    {
                        xmlNamespace = GetFormatedXmlNamespace(clrNamespace, assemblyName);
                    }
                    prefix = GetPrefix(manager, type.Assembly, xmlNamespace);

                    WorkflowMarkupSerializerMapping mapping = new WorkflowMarkupSerializerMapping(prefix, xmlNamespace, clrNamespace, assemblyName, type.Assembly.FullName);
                    if (xmlnsDefinition.ClrNamespace.Equals(clrNamespace, StringComparison.Ordinal) && matchingMapping == null)
                    {
                        matchingMapping = mapping;
                    }
                    else
                    {
                        collectedMappings.Add(mapping);
                    }
                }
            }

            if (matchingMapping == null)
            {
                if (type.Assembly == manager.LocalAssembly)
                {
                    assemblyName = String.Empty;
                }
                else if (String.IsNullOrEmpty(assemblyName))
                {
                    assemblyName = GetAssemblyName(type, manager);
                }

                xmlNamespace = GetFormatedXmlNamespace(clrNamespace, assemblyName);

                if (String.IsNullOrEmpty(prefix))
                {
                    prefix = GetPrefix(manager, type.Assembly, xmlNamespace);
                }

                matchingMapping = new WorkflowMarkupSerializerMapping(prefix, xmlNamespace, clrNamespace, assemblyName, type.Assembly.FullName);
            }
        }
Ejemplo n.º 25
0
        internal static void GetMappingsFromXmlNamespace(WorkflowMarkupSerializationManager serializationManager, string xmlNamespace, out IList <WorkflowMarkupSerializerMapping> matchingMappings, out IList <WorkflowMarkupSerializerMapping> collectedMappings)
        {
            matchingMappings  = new List <WorkflowMarkupSerializerMapping>();
            collectedMappings = new List <WorkflowMarkupSerializerMapping>();

            if (serializationManager.WorkflowMarkupStack[typeof(XmlReader)] is XmlReader reader)
            {
                if (xmlNamespace.StartsWith(StandardXomlKeys.CLRNamespaceQualifier, StringComparison.OrdinalIgnoreCase))
                {
                    //Format for the xmlnamespace: clr-namespace:[Namespace][;Assembly=[AssemblyName]]
                    bool   invalidXmlnsFormat = false;
                    string clrNamespace       = xmlNamespace.Substring(StandardXomlKeys.CLRNamespaceQualifier.Length).Trim();
                    string assemblyName       = String.Empty;
                    int    index = clrNamespace.IndexOf(';');
                    if (index != -1)
                    {
                        assemblyName = (index + 1 < clrNamespace.Length) ? clrNamespace.Substring(index + 1).Trim() : String.Empty;
                        clrNamespace = clrNamespace.Substring(0, index).Trim();

                        if (!assemblyName.StartsWith(StandardXomlKeys.AssemblyNameQualifier, StringComparison.OrdinalIgnoreCase))
                        {
                            invalidXmlnsFormat = true;
                        }

                        assemblyName = assemblyName.Substring(StandardXomlKeys.AssemblyNameQualifier.Length);
                    }

                    if (!invalidXmlnsFormat)
                    {
                        if (clrNamespace.Equals(StandardXomlKeys.GlobalNamespace, StringComparison.OrdinalIgnoreCase))
                        {
                            clrNamespace = String.Empty;
                        }
                        matchingMappings.Add(new WorkflowMarkupSerializerMapping(reader.Prefix, xmlNamespace, clrNamespace, assemblyName));
                    }
                }
                else
                {
                    List <Assembly> referencedAssemblies = new List <Assembly>();
                    if (serializationManager.LocalAssembly != null)
                    {
                        referencedAssemblies.Add(serializationManager.LocalAssembly);
                    }

                    foreach (Assembly assembly in referencedAssemblies)
                    {
                        object[] xmlnsDefinitions = assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute), true);
                        if (xmlnsDefinitions != null)
                        {
                            foreach (XmlnsDefinitionAttribute xmlnsDefinition in xmlnsDefinitions)
                            {
                                string assemblyName = String.Empty;
                                if (serializationManager.LocalAssembly != assembly)
                                {
                                    if (xmlnsDefinition.AssemblyName != null && xmlnsDefinition.AssemblyName.Trim().Length > 0)
                                    {
                                        assemblyName = xmlnsDefinition.AssemblyName;
                                    }
                                    else
                                    {
                                        assemblyName = assembly.FullName;
                                    }
                                }

                                if (xmlnsDefinition.XmlNamespace.Equals(xmlNamespace, StringComparison.Ordinal))
                                {
                                    matchingMappings.Add(new WorkflowMarkupSerializerMapping(reader.Prefix, xmlNamespace, xmlnsDefinition.ClrNamespace, assemblyName));
                                }
                                else
                                {
                                    collectedMappings.Add(new WorkflowMarkupSerializerMapping(reader.Prefix, xmlNamespace, xmlnsDefinition.ClrNamespace, assemblyName));
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 26
0
 protected internal override bool CanSerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
 {
     return(value is CodeTypeReference);
 }
Ejemplo n.º 27
0
        public override object ProvideValue(IServiceProvider provider)
        {
            if (this.type != null)
            {
                return(this.type);
            }

            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            if (this.typeName == null)
            {
                throw new InvalidOperationException("typename");
            }

            WorkflowMarkupSerializationManager manager = provider as WorkflowMarkupSerializationManager;

            if (manager == null)
            {
                throw new ArgumentNullException("provider");
            }

            XmlReader reader = manager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader;

            if (reader == null)
            {
                Debug.Assert(false);
                return(this.typeName);
            }

            string typename  = this.typeName.Trim();
            string prefix    = String.Empty;
            int    typeIndex = typename.IndexOf(':');

            if (typeIndex >= 0)
            {
                prefix   = typename.Substring(0, typeIndex);
                typename = typename.Substring(typeIndex + 1);
                type     = manager.GetType(new XmlQualifiedName(typename, reader.LookupNamespace(prefix)));
                if (type != null)
                {
                    return(type);
                }

                // To Support types whose assembly is not available, we need to still resolve the clr namespace
                if (manager.XmlNamespaceBasedMappings.TryGetValue(reader.LookupNamespace(prefix), out List <WorkflowMarkupSerializerMapping> xmlnsMappings) && xmlnsMappings != null && xmlnsMappings.Count > 0)
                {
                    return(xmlnsMappings[0].ClrNamespace + "." + typename);
                }
                else
                {
                    return(typename);
                }
            }
            type = manager.GetType(new XmlQualifiedName(typename, reader.LookupNamespace(string.Empty)));

            // To Support Beta2 format
            if (type == null)
            {
                // If not design mode, get the value from serialization manager
                // At design time, we need to get the type from ITypeProvider else
                // we need to store the string in the hashtable we maintain internally
                if (type == null && manager.GetService(typeof(ITypeResolutionService)) == null)
                {
                    type = manager.SerializationManager.GetType(typename);
                }
            }
            if (type != null)
            {
                return(type);
            }

            return(this.typeName);
        }
Ejemplo n.º 28
0
 internal ExtendedPropertyInfo(PropertyInfo propertyInfo, GetValueHandler getValueHandler, SetValueHandler setValueHandler, GetQualifiedNameHandler qualifiedNameHandler, WorkflowMarkupSerializationManager manager)
     : this(propertyInfo, getValueHandler, setValueHandler, qualifiedNameHandler)
 {
     this.manager = manager;
 }
        protected internal sealed override string SerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
        {
            if (serializationManager == null)
                throw new ArgumentNullException("serializationManager");
            XmlWriter writer = serializationManager.WorkflowMarkupStack[typeof(XmlWriter)] as XmlWriter;
            if (writer == null)
                throw new ArgumentNullException("writer");
            if (value == null)
                throw new ArgumentNullException("value");

            writer.WriteString(MarkupExtensionSerializer.CompactFormatStart);

            string prefix = String.Empty;
            XmlQualifiedName qualifiedName = serializationManager.GetXmlQualifiedName(value.GetType(), out prefix);
            writer.WriteQualifiedName(qualifiedName.Name, qualifiedName.Namespace);

            int index = 0;

            Dictionary<string, string> constructorArguments = null;
            InstanceDescriptor instanceDescriptor = this.GetInstanceDescriptor(serializationManager, value);
            if (instanceDescriptor != null)
            {
                if (instanceDescriptor.MemberInfo is ConstructorInfo ctorInfo)
                {
                    ParameterInfo[] parameters = ctorInfo.GetParameters();
                    if (parameters != null && parameters.Length == instanceDescriptor.Arguments.Count)
                    {
                        int i = 0;
                        foreach (object argValue in instanceDescriptor.Arguments)
                        {
                            if (constructorArguments == null)
                                constructorArguments = new Dictionary<string, string>();
                            // 
                            if (argValue == null)
                                continue;
                            constructorArguments.Add(parameters[i].Name, parameters[i++].Name);
                            if (index++ > 0)
                                writer.WriteString(MarkupExtensionSerializer.CompactFormatPropertySeperator);
                            else
                                writer.WriteString(MarkupExtensionSerializer.CompactFormatTypeSeperator);
                            if (argValue.GetType() == typeof(string))
                            {
                                writer.WriteString(CreateEscapedValue(argValue as string));
                            }
                            else if (argValue is System.Type)
                            {
                                Type argType = argValue as Type;
                                if (argType.Assembly != null)
                                {
                                    string typePrefix = String.Empty;
                                    XmlQualifiedName typeQualifiedName = serializationManager.GetXmlQualifiedName(argType, out typePrefix);
                                    writer.WriteQualifiedName(XmlConvert.EncodeName(typeQualifiedName.Name), typeQualifiedName.Namespace);
                                }
                                else
                                {
                                    writer.WriteString(argType.FullName);
                                }
                            }
                            else
                            {
                                string stringValue = base.SerializeToString(serializationManager, argValue);
                                if (stringValue != null)
                                    writer.WriteString(stringValue);
                            }
                        }
                    }
                }
            }

            List<PropertyInfo> properties = new List<PropertyInfo>();
            properties.AddRange(GetProperties(serializationManager, value));
            properties.AddRange(serializationManager.GetExtendedProperties(value));
            foreach (PropertyInfo serializableProperty in properties)
            {
                if (Helpers.GetSerializationVisibility(serializableProperty) != DesignerSerializationVisibility.Hidden && serializableProperty.CanRead && serializableProperty.GetValue(value, null) != null)
                {
                    WorkflowMarkupSerializer propSerializer = serializationManager.GetSerializer(serializableProperty.PropertyType, typeof(WorkflowMarkupSerializer)) as WorkflowMarkupSerializer;
                    if (propSerializer == null)
                    {
                        serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerNotAvailable, serializableProperty.PropertyType.FullName)));
                        continue;
                    }

                    if (constructorArguments != null)
                    {
                        object[] attributes = serializableProperty.GetCustomAttributes(typeof(ConstructorArgumentAttribute), false);
                        if (attributes.Length > 0 && constructorArguments.ContainsKey((attributes[0] as ConstructorArgumentAttribute).ArgumentName))
                            // Skip this property, it has already been represented by a constructor parameter
                            continue;
                    }

                    //Get the property serializer so that we can convert the bind object to string
                    serializationManager.Context.Push(serializableProperty);
                    try
                    {
                        object propValue = serializableProperty.GetValue(value, null);
                        if (propSerializer.ShouldSerializeValue(serializationManager, propValue))
                        {
                            //We do not allow nested bind syntax
                            if (propSerializer.CanSerializeToString(serializationManager, propValue))
                            {
                                if (index++ > 0)
                                    writer.WriteString(MarkupExtensionSerializer.CompactFormatPropertySeperator);
                                else
                                    writer.WriteString(MarkupExtensionSerializer.CompactFormatTypeSeperator);
                                writer.WriteString(serializableProperty.Name);
                                writer.WriteString(MarkupExtensionSerializer.CompactFormatNameValueSeperator);

                                if (propValue.GetType() == typeof(string))
                                {
                                    writer.WriteString(CreateEscapedValue(propValue as string));
                                }
                                else
                                {
                                    string stringValue = propSerializer.SerializeToString(serializationManager, propValue);
                                    if (stringValue != null)
                                        writer.WriteString(stringValue);
                                }
                            }
                            else
                            {
                                serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerNoSerializeLogic, new object[] { serializableProperty.Name, value.GetType().FullName })));
                            }
                        }
                    }
                    catch
                    {
                        serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerNoSerializeLogic, new object[] { serializableProperty.Name, value.GetType().FullName })));
                        continue;
                    }
                    finally
                    {
                        Debug.Assert((PropertyInfo)serializationManager.Context.Current == serializableProperty, "Serializer did not remove an object it pushed into stack.");
                        serializationManager.Context.Pop();
                    }
                }
            }
            writer.WriteString(MarkupExtensionSerializer.CompactFormatEnd);
            return string.Empty;

        }
 protected internal sealed override bool CanSerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
 {
     return true;
 }