Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }