protected internal override object DeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value)
 {
     CodeTypeReference reference;
     if (!propertyType.IsAssignableFrom(typeof(CodeTypeReference)))
     {
         return null;
     }
     if (string.IsNullOrEmpty(value) || base.IsValidCompactAttributeFormat(value))
     {
         return null;
     }
     try
     {
         Type type = serializationManager.GetType(value);
         if (type != null)
         {
             reference = new CodeTypeReference(type);
             reference.UserData["QualifiedName"] = type.AssemblyQualifiedName;
             return reference;
         }
     }
     catch (Exception)
     {
     }
     reference = new CodeTypeReference(value);
     reference.UserData["QualifiedName"] = value;
     return reference;
 }
Esempio n. 2
0
        protected internal override object DeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value)
        {
            CodeTypeReference reference;

            if (!propertyType.IsAssignableFrom(typeof(CodeTypeReference)))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(value) || base.IsValidCompactAttributeFormat(value))
            {
                return(null);
            }
            try
            {
                Type type = serializationManager.GetType(value);
                if (type != null)
                {
                    reference = new CodeTypeReference(type);
                    reference.UserData["QualifiedName"] = type.AssemblyQualifiedName;
                    return(reference);
                }
            }
            catch (Exception)
            {
            }
            reference = new CodeTypeReference(value);
            reference.UserData["QualifiedName"] = value;
            return(reference);
        }
        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;
            TypeProvider typeProvider     = serializationManager.GetService(typeof(ITypeProvider)) as TypeProvider;

            if (typeProvider != null)
            {
                assemblyFullName = typeProvider.GetAssemblyName(type);
            }
            //
            // 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);
        }
        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.EndsWith("Activity", StringComparison.OrdinalIgnoreCase))
                    {
                        knownMappings.Add(WorkflowMarkupSerializerMapping.Activities);
                        knownMappings.Add(WorkflowMarkupSerializerMapping.ComponentModel);
                    }
                    if (typeName.EndsWith("Designer", StringComparison.OrdinalIgnoreCase))
                    {
                        knownMappings.Add(WorkflowMarkupSerializerMapping.Activities);
                        knownMappings.Add(WorkflowMarkupSerializerMapping.ComponentModel);
                        knownMappings.Add(WorkflowMarkupSerializerMapping.ComponentModelDesign);
                    }
                    else if (typeName.EndsWith("Theme", StringComparison.OrdinalIgnoreCase))
                    {
                        knownMappings.Add(WorkflowMarkupSerializerMapping.ComponentModelDesign);
                        knownMappings.Add(WorkflowMarkupSerializerMapping.Activities);
                    }
                    else 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);
        }
        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;
            TypeProvider typeProvider = serializationManager.GetService(typeof(ITypeProvider)) as TypeProvider;
            if (typeProvider != null)
            {
                assemblyFullName = typeProvider.GetAssemblyName(type);
            }
            //
            // 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;
        }
        internal static Type ResolveWellKnownTypes(WorkflowMarkupSerializationManager manager, string xmlns, string typeName)
        {
            Type type = null;
            List <WorkflowMarkupSerializerMapping> list = new List <WorkflowMarkupSerializerMapping>();

            if (xmlns.Equals("http://schemas.microsoft.com/winfx/2006/xaml/workflow", StringComparison.Ordinal))
            {
                if (!wellKnownTypes.TryGetValue(typeName, out type))
                {
                    if (typeName.EndsWith("Activity", StringComparison.OrdinalIgnoreCase))
                    {
                        list.Add(Activities);
                        list.Add(ComponentModel);
                    }
                    if (typeName.EndsWith("Designer", StringComparison.OrdinalIgnoreCase))
                    {
                        list.Add(Activities);
                        list.Add(ComponentModel);
                        list.Add(ComponentModelDesign);
                    }
                    else if (typeName.EndsWith("Theme", StringComparison.OrdinalIgnoreCase))
                    {
                        list.Add(ComponentModelDesign);
                        list.Add(Activities);
                    }
                    else if (typeName.StartsWith("Rule", StringComparison.OrdinalIgnoreCase) || typeName.EndsWith("Action", StringComparison.OrdinalIgnoreCase))
                    {
                        list.Add(Rules);
                    }
                }
            }
            else if (xmlns.Equals("http://schemas.microsoft.com/winfx/2006/xaml", StringComparison.Ordinal))
            {
                list.Add(Serialization);
            }
            if (type == null)
            {
                foreach (WorkflowMarkupSerializerMapping mapping in list)
                {
                    string str = mapping.ClrNamespace + "." + typeName + ", " + mapping.AssemblyName;
                    type = manager.GetType(str);
                    if (type != null)
                    {
                        return(type);
                    }
                }
            }
            return(type);
        }
Esempio n. 7
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);
            }
            string typeName = ConvertTypeReferenceToString(reference);
            Type   type     = serializationManager.GetType(typeName);

            if (type == null)
            {
                type = Type.GetType(typeName, false);
                if (type == null)
                {
                    return(typeName);
                }
            }
            string       assemblyName = null;
            TypeProvider service      = serializationManager.GetService(typeof(ITypeProvider)) as TypeProvider;

            if (service != null)
            {
                assemblyName = service.GetAssemblyName(type);
            }
            if (string.IsNullOrEmpty(assemblyName))
            {
                return(type.AssemblyQualifiedName);
            }
            return(string.Format(CultureInfo.InvariantCulture, "{0}, {1}", new object[] { type.FullName, assemblyName }));
        }
        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);
        }
        private DependencyProperty ResolveDependencyProperty(WorkflowMarkupSerializationManager serializationManager, XmlReader reader, object attachedObj, string fullPropertyName)
        {
            Type ownerType = null;
            string propertyName = String.Empty;
            int separatorIndex = fullPropertyName.IndexOf(".");
            if (separatorIndex != -1)
            {
                string ownerTypeName = fullPropertyName.Substring(0, separatorIndex);
                propertyName = fullPropertyName.Substring(separatorIndex + 1);
                if (!String.IsNullOrEmpty(ownerTypeName) && !String.IsNullOrEmpty(propertyName))
                    ownerType = serializationManager.GetType(new XmlQualifiedName(ownerTypeName, reader.LookupNamespace(reader.Prefix)));
            }
            else
            {
                ownerType = attachedObj.GetType();
                propertyName = fullPropertyName;
            }

            if (ownerType == null)
                return null;

            //We need to make sure that the register method is always called for the dynamic property before we try to resolve it
            //In cases of attached properties if this statement is not there then the dynamic property wont be found as it is
            //not registered till the first access of the static field
            DependencyProperty dependencyProperty = null;

            FieldInfo fieldInfo = ownerType.GetField(propertyName + "Property", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
            if (fieldInfo == null)
                fieldInfo = ownerType.GetField(propertyName + "Event", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
            if (fieldInfo != null)
            {
                dependencyProperty = fieldInfo.GetValue(attachedObj) as DependencyProperty;
                if (dependencyProperty != null)
                {
                    object[] attributes = dependencyProperty.DefaultMetadata.GetAttributes(typeof(DesignerSerializationVisibilityAttribute));
                    if (attributes.Length > 0)
                    {
                        DesignerSerializationVisibilityAttribute serializationVisibilityAttribute = attributes[0] as DesignerSerializationVisibilityAttribute;
                        if (serializationVisibilityAttribute.Visibility == DesignerSerializationVisibility.Hidden)
                            dependencyProperty = null;
                    }
                }
            }

            return dependencyProperty;
        }
 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;
     }
     string typeName = ConvertTypeReferenceToString(reference);
     Type type = serializationManager.GetType(typeName);
     if (type == null)
     {
         type = Type.GetType(typeName, false);
         if (type == null)
         {
             return typeName;
         }
     }
     string assemblyName = null;
     TypeProvider service = serializationManager.GetService(typeof(ITypeProvider)) as TypeProvider;
     if (service != null)
     {
         assemblyName = service.GetAssemblyName(type);
     }
     if (string.IsNullOrEmpty(assemblyName))
     {
         return type.AssemblyQualifiedName;
     }
     return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", new object[] { type.FullName, assemblyName });
 }
 internal static Type ResolveWellKnownTypes(WorkflowMarkupSerializationManager manager, string xmlns, string typeName)
 {
     Type type = null;
     List<WorkflowMarkupSerializerMapping> list = new List<WorkflowMarkupSerializerMapping>();
     if (xmlns.Equals("http://schemas.microsoft.com/winfx/2006/xaml/workflow", StringComparison.Ordinal))
     {
         if (!wellKnownTypes.TryGetValue(typeName, out type))
         {
             if (typeName.EndsWith("Activity", StringComparison.OrdinalIgnoreCase))
             {
                 list.Add(Activities);
                 list.Add(ComponentModel);
             }
             if (typeName.EndsWith("Designer", StringComparison.OrdinalIgnoreCase))
             {
                 list.Add(Activities);
                 list.Add(ComponentModel);
                 list.Add(ComponentModelDesign);
             }
             else if (typeName.EndsWith("Theme", StringComparison.OrdinalIgnoreCase))
             {
                 list.Add(ComponentModelDesign);
                 list.Add(Activities);
             }
             else if (typeName.StartsWith("Rule", StringComparison.OrdinalIgnoreCase) || typeName.EndsWith("Action", StringComparison.OrdinalIgnoreCase))
             {
                 list.Add(Rules);
             }
         }
     }
     else if (xmlns.Equals("http://schemas.microsoft.com/winfx/2006/xaml", StringComparison.Ordinal))
     {
         list.Add(Serialization);
     }
     if (type == null)
     {
         foreach (WorkflowMarkupSerializerMapping mapping in list)
         {
             string str = mapping.ClrNamespace + "." + typeName + ", " + mapping.AssemblyName;
             type = manager.GetType(str);
             if (type != null)
             {
                 return type;
             }
         }
     }
     return type;
 }
        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.EndsWith("Activity", StringComparison.OrdinalIgnoreCase))
                    {
                        knownMappings.Add(WorkflowMarkupSerializerMapping.Activities);
                        knownMappings.Add(WorkflowMarkupSerializerMapping.ComponentModel);
                    }
                    if (typeName.EndsWith("Designer", StringComparison.OrdinalIgnoreCase))
                    {
                        knownMappings.Add(WorkflowMarkupSerializerMapping.Activities);
                        knownMappings.Add(WorkflowMarkupSerializerMapping.ComponentModel);
                        knownMappings.Add(WorkflowMarkupSerializerMapping.ComponentModelDesign);
                    }
                    else if (typeName.EndsWith("Theme", StringComparison.OrdinalIgnoreCase))
                    {
                        knownMappings.Add(WorkflowMarkupSerializerMapping.ComponentModelDesign);
                        knownMappings.Add(WorkflowMarkupSerializerMapping.Activities);
                    }
                    else 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;
        }
        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)
            {
                string name   = this.typeName.Trim();
                string prefix = string.Empty;
                int    index  = name.IndexOf(':');
                if (index >= 0)
                {
                    prefix    = name.Substring(0, index);
                    name      = name.Substring(index + 1);
                    this.type = manager.GetType(new XmlQualifiedName(name, reader.LookupNamespace(prefix)));
                    if (this.type != null)
                    {
                        return(this.type);
                    }
                    List <WorkflowMarkupSerializerMapping> list = null;
                    if ((manager.XmlNamespaceBasedMappings.TryGetValue(reader.LookupNamespace(prefix), out list) && (list != null)) && (list.Count > 0))
                    {
                        return(list[0].ClrNamespace + "." + name);
                    }
                    return(name);
                }
                this.type = manager.GetType(new XmlQualifiedName(name, reader.LookupNamespace(string.Empty)));
                if (this.type == null)
                {
                    ITypeProvider service = provider.GetService(typeof(ITypeProvider)) as ITypeProvider;
                    if (service != null)
                    {
                        this.type = service.GetType(name);
                    }
                    if ((this.type == null) && (manager.GetService(typeof(ITypeResolutionService)) == null))
                    {
                        this.type = manager.SerializationManager.GetType(name);
                    }
                }
                if (this.type != null)
                {
                    return(this.type);
                }
            }
            return(this.typeName);
        }
Esempio n. 14
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
                List <WorkflowMarkupSerializerMapping> xmlnsMappings = null;
                if (manager.XmlNamespaceBasedMappings.TryGetValue(reader.LookupNamespace(prefix), out 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)
            {
                ITypeProvider typeProvider = provider.GetService(typeof(ITypeProvider)) as ITypeProvider;
                if (typeProvider != null)
                {
                    type = typeProvider.GetType(typename);
                }

                // 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);
        }
        // This function parses the data bind syntax (markup extension in xaml terms).  The syntax is:
        // {ObjectTypeName arg1, arg2, name3=arg3, name4=arg4, ...}
        // For example, an ActivityBind would have the syntax as the following:
        // {wcm:ActivityBind ID=Workflow1, Path=error1}
        // We also support positional arguments, so the above expression is equivalent to 
        // {wcm:ActivityBind Workflow1, Path=error1} or {wcm:ActivityBind Workflow1, error1}
        // Notice that the object must have the appropriate constructor to support positional arugments.
        // There should be no constructors that takes the same number of arugments, regardless of their types.
        internal object DeserializeFromCompactFormat(WorkflowMarkupSerializationManager serializationManager, XmlReader reader, string attrValue)
        {
            if (attrValue.Length == 0 || !attrValue.StartsWith("{", StringComparison.Ordinal) || !attrValue.EndsWith("}", StringComparison.Ordinal))
            {
                serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.IncorrectSyntax, attrValue), reader));
                return null;
            }

            // check for correct format:  typename name=value name=value
            int argIndex = attrValue.IndexOf(" ", StringComparison.Ordinal);
            if (argIndex == -1)
                argIndex = attrValue.IndexOf("}", StringComparison.Ordinal);

            string typename = attrValue.Substring(1, argIndex - 1).Trim();
            string arguments = attrValue.Substring(argIndex + 1, attrValue.Length - (argIndex + 1));
            // lookup the type of the target
            string prefix = String.Empty;
            int typeIndex = typename.IndexOf(":", StringComparison.Ordinal);
            if (typeIndex >= 0)
            {
                prefix = typename.Substring(0, typeIndex);
                typename = typename.Substring(typeIndex + 1);
            }

            Type type = serializationManager.GetType(new XmlQualifiedName(typename, reader.LookupNamespace(prefix)));
            if (type == null && !typename.EndsWith("Extension", StringComparison.Ordinal))
            {
                typename = typename + "Extension";
                type = serializationManager.GetType(new XmlQualifiedName(typename, reader.LookupNamespace(prefix)));
            }
            if (type == null)
            {
                serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_MarkupSerializerTypeNotResolved, typename), reader));
                return null;
            }

            // Break apart the argument string.
            object obj = null;
            Dictionary<string, object> namedArgs = new Dictionary<string, object>();
            ArrayList argTokens = null;
            try
            {
                argTokens = TokenizeAttributes(serializationManager, arguments, (reader is IXmlLineInfo) ? ((IXmlLineInfo)reader).LineNumber : 1, (reader is IXmlLineInfo) ? ((IXmlLineInfo)reader).LinePosition : 1);
            }
            catch (Exception error)
            {
                serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_MarkupExtensionDeserializeFailed, attrValue, error.Message), reader));
                return null;
            }
            if (argTokens != null)
            {
                // Process the positional arugments and find the correct constructor to call.
                ArrayList positionalArgs = new ArrayList();
                bool firstEqual = true;
                for (int i = 0; i < argTokens.Count; i++)
                {
                    char token = (argTokens[i] is char) ? (char)argTokens[i] : '\0';
                    if (token == '=')
                    {
                        if (positionalArgs.Count > 0 && firstEqual)
                            positionalArgs.RemoveAt(positionalArgs.Count - 1);
                        firstEqual = false;
                        namedArgs.Add(argTokens[i - 1] as string, argTokens[i + 1] as string);
                        i++;
                    }
                    if (token == ',')
                        continue;

                    if (namedArgs.Count == 0)
                        positionalArgs.Add(argTokens[i] as string);
                }

                if (positionalArgs.Count > 0)
                {
                    ConstructorInfo matchConstructor = null;
                    ConstructorInfo[] constructors = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                    ParameterInfo[] matchParameters = null;
                    foreach (ConstructorInfo ctor in constructors)
                    {
                        ParameterInfo[] parameters = ctor.GetParameters();
                        if (parameters.Length == positionalArgs.Count)
                        {
                            matchConstructor = ctor;
                            matchParameters = parameters;
                            break;
                        }
                    }

                    if (matchConstructor != null)
                    {
                        for (int i = 0; i < positionalArgs.Count; i++)
                        {
                            positionalArgs[i] = XmlConvert.DecodeName((string)positionalArgs[i]);
                            string argVal = (string)positionalArgs[i];
                            RemoveEscapes(ref argVal);
                            positionalArgs[i] = InternalDeserializeFromString(serializationManager, matchParameters[i].ParameterType, argVal);
                            positionalArgs[i] = GetValueFromMarkupExtension(serializationManager, positionalArgs[i]);
                        }

                        obj = Activator.CreateInstance(type, positionalArgs.ToArray());
                    }
                }
                else
                    obj = Activator.CreateInstance(type);
            }
            else
                obj = Activator.CreateInstance(type);

            if (obj == null)
            {
                serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_CantCreateInstanceOfBaseType, type.FullName), reader));
                return null;
            }

            if (namedArgs.Count > 0)
            {
                WorkflowMarkupSerializer serializer = serializationManager.GetSerializer(obj.GetType(), typeof(WorkflowMarkupSerializer)) as WorkflowMarkupSerializer;
                if (serializer == null)
                {
                    serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerNotAvailable, obj.GetType().FullName), reader));
                    return obj;
                }
                List<PropertyInfo> properties = new List<PropertyInfo>();
                try
                {
                    properties.AddRange(serializer.GetProperties(serializationManager, obj));
                    properties.AddRange(serializationManager.GetExtendedProperties(obj));
                }
                catch (Exception e)
                {
                    serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerThrewException, obj.GetType().FullName, e.Message), e, reader));
                    return obj;
                }

                foreach (string key in namedArgs.Keys)
                {
                    string argName = key;
                    string argVal = namedArgs[key] as string;
                    RemoveEscapes(ref argName);
                    RemoveEscapes(ref argVal);

                    PropertyInfo property = WorkflowMarkupSerializer.LookupProperty(properties, argName);
                    if (property != null)
                    {
                        serializationManager.Context.Push(property);
                        try
                        {
                            DeserializeSimpleProperty(serializationManager, reader, obj, argVal);
                        }
                        finally
                        {
                            Debug.Assert((PropertyInfo)serializationManager.Context.Current == property, "Serializer did not remove an object it pushed into stack.");
                            serializationManager.Context.Pop();
                        }
                    }
                    else
                    {
                        serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerPrimitivePropertyNoLogic, new object[] { argName, argName, obj.GetType().FullName }), reader));
                    }
                }
            }

            return obj;
        }
        private object CreateInstance(WorkflowMarkupSerializationManager serializationManager, XmlQualifiedName xmlQualifiedName, XmlReader reader)
        {
            object obj = null;
            // resolve the type
            Type type = null;
            try
            {
                type = serializationManager.GetType(xmlQualifiedName);
            }
            catch (Exception e)
            {
                serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerTypeNotResolvedWithInnerError, new object[] { GetClrFullName(serializationManager, xmlQualifiedName), e.Message }), e, reader));
                return null;
            }
            if (type == null && !xmlQualifiedName.Name.EndsWith("Extension", StringComparison.Ordinal))
            {
                string typename = xmlQualifiedName.Name + "Extension";
                try
                {
                    type = serializationManager.GetType(new XmlQualifiedName(typename, xmlQualifiedName.Namespace));
                }
                catch (Exception e)
                {
                    serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerTypeNotResolvedWithInnerError, new object[] { GetClrFullName(serializationManager, xmlQualifiedName), e.Message }), e, reader));
                    return null;
                }
            }

            if (type == null)
            {
                serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerTypeNotResolved, new object[] { GetClrFullName(serializationManager, xmlQualifiedName) }), reader));
                return null;
            }

            if (type.IsPrimitive || type == typeof(string) || type == typeof(decimal) || type == typeof(DateTime) ||
                type == typeof(TimeSpan) || type.IsEnum || type == typeof(Guid))
            {
                try
                {
                    string stringValue = reader.ReadString();
                    if (type == typeof(DateTime))
                    {
                        obj = DateTime.Parse(stringValue, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
                    }
                    else if (type.IsPrimitive || type == typeof(decimal) || type == typeof(TimeSpan) || type.IsEnum || type == typeof(Guid))
                    {
                        //These non CLS-compliant are not supported in the XmlReader 
                        TypeConverter typeConverter = TypeDescriptor.GetConverter(type);
                        if (typeConverter != null && typeConverter.CanConvertFrom(typeof(string)))
                            obj = typeConverter.ConvertFrom(null, CultureInfo.InvariantCulture, stringValue);
                        else if (typeof(IConvertible).IsAssignableFrom(type))
                            obj = Convert.ChangeType(stringValue, type, CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        obj = stringValue;
                    }
                }
                catch (Exception e)
                {
                    serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerCreateInstanceFailed, e.Message), reader));
                    return null;
                }
            }
            else
            {
                // get the serializer
                WorkflowMarkupSerializer serializer = serializationManager.GetSerializer(type, typeof(WorkflowMarkupSerializer)) as WorkflowMarkupSerializer;
                if (serializer == null)
                {
                    serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerNotAvailable, type.FullName), reader));
                    return null;
                }

                // create an instance
                try
                {
                    obj = serializer.CreateInstance(serializationManager, type);
                }
                catch (Exception e)
                {
                    serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_SerializerCreateInstanceFailed, type.FullName, e.Message), reader));
                    return null;
                }
            }
            return obj;
        }
        private object InternalDeserializeFromString(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");

            object propVal = null;
            XmlReader reader = serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader;
            if (reader == null)
            {
                Debug.Assert(false, "XmlReader not available.");
                return null;
            }
            if (IsValidCompactAttributeFormat(value))
            {
                propVal = DeserializeFromCompactFormat(serializationManager, reader, value);
            }
            else
            {
                if (value.StartsWith("{}", StringComparison.Ordinal))
                    value = value.Substring(2);
                // Check for Nullable types
                if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
                {
                    Type genericType = (Type)propertyType.GetGenericArguments()[0];
                    Debug.Assert(genericType != null);
                    propertyType = genericType;
                }
                if (propertyType.IsPrimitive || propertyType == typeof(System.String))
                {
                    propVal = Convert.ChangeType(value, propertyType, CultureInfo.InvariantCulture);
                }
                else if (propertyType.IsEnum)
                {
                    propVal = Enum.Parse(propertyType, value, true);
                }
                else if (typeof(Delegate).IsAssignableFrom(propertyType))
                {
                    // Just return the method name.  This must happen after Bind syntax has been checked.
                    propVal = value;
                }
                else if (typeof(TimeSpan) == propertyType)
                {
                    propVal = TimeSpan.Parse(value, CultureInfo.InvariantCulture);
                }
                else if (typeof(DateTime) == propertyType)
                {
                    propVal = DateTime.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
                }
                else if (typeof(Guid) == propertyType)
                {
                    propVal = Utility.CreateGuid(value);
                }
                else if (typeof(Type).IsAssignableFrom(propertyType))
                {
                    propVal = serializationManager.GetType(value);
                    if (propVal != null)
                    {
                        Type type = propVal as Type;
                        if (type.IsPrimitive || type.IsEnum || type == typeof(System.String))
                            return type;
                    }
                    ITypeProvider typeProvider = serializationManager.GetService(typeof(ITypeProvider)) as ITypeProvider;
                    if (typeProvider != null)
                    {
                        Type type = typeProvider.GetType(value);
                        if (type != null)
                            return type;
                    }
                    return value;
                }
                else if (typeof(IConvertible).IsAssignableFrom(propertyType))
                {
                    propVal = Convert.ChangeType(value, propertyType, CultureInfo.InvariantCulture);
                }
                else if (propertyType.IsAssignableFrom(value.GetType()))
                {
                    propVal = value;
                }
                else
                {
                    throw CreateSerializationError(SR.GetString(SR.Error_SerializerPrimitivePropertyNoLogic, new object[] { "", value.Trim(), "" }), reader);
                }
            }
            return propVal;
        }
        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;
        }