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);
        }
        private static string GetAssemblyName(Type type, WorkflowMarkupSerializationManager manager)
        {
            TypeProvider service = manager.GetService(typeof(ITypeProvider)) as TypeProvider;

            if (service != null)
            {
                return(service.GetAssemblyName(type));
            }
            if (type.Assembly == null)
            {
                return(string.Empty);
            }
            return(type.Assembly.FullName);
        }
        private static string GetAssemblyName(Type type, WorkflowMarkupSerializationManager manager)
        {
            TypeProvider typeProvider = manager.GetService(typeof(ITypeProvider)) as TypeProvider;

            if (typeProvider != null)
            {
                return(typeProvider.GetAssemblyName(type));
            }
            //
            // Handle DesignTimeType
            if (type.Assembly == null)
            {
                return(string.Empty);
            }
            else
            {
                return(type.Assembly.FullName);
            }
        }
Пример #4
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 }));
        }