/// <summary>
        /// If the given type is defined in a system assembly, returns the type directly, otherwise <c>null</c>.
        /// </summary>
        /// <param name="type">The type whose equivalent we need.</param>
        /// <returns>If the type lives in a system assembly, the input type, else <c>null</c>.</returns>
        private static Type EquivalentMsCorlibType(Type type)
        {
            if (AssemblyUtilities.IsAssemblyMsCorlib(type.Assembly.GetName()))
            {
                // For now, only a core set of predefined system types are assumed to be supported
                return(TypeUtility.IsPredefinedType(type) ? type : null);
            }

            return(null);
        }
        private static bool IsSharedFrameworkType(string typeName)
        {
            // If this isn't a system assembly, we know immediately that
            // it's not a shared framework type
            Type systemType = Type.GetType(typeName, /*throwOnError*/ false);

            if (systemType != null)
            {
                if (!SystemWebDomainServices::OpenRiaServices.DomainServices.TypeUtility.IsSystemAssembly(systemType.Assembly))
                {
                    return(false);
                }
                // Mock matches the real shared assemblies in allowing all mscorlib to match
                if (AssemblyUtilities.IsAssemblyMsCorlib(systemType.Assembly.GetName()))
                {
                    return(true);
                }
                // The mock declares that anything in System is also shared
                // Anything in EntityFramework.dll is not shared.
                string assemblyName = systemType.Assembly.FullName;
                int    comma        = assemblyName.IndexOf(',');
                if (comma >= 0)
                {
                    assemblyName = assemblyName.Substring(0, comma);
                    if (string.Equals("System", assemblyName, StringComparison.OrdinalIgnoreCase))
                    {
                        return(true);
                    }
                    if (string.Equals("EntityFramework", assemblyName, StringComparison.OrdinalIgnoreCase))
                    {
                        return(false);
                    }
                }
            }
            typeName = MockSharedCodeService.AssemblyQualifiedTypeNameToFullTypeName(typeName);

            int    dot           = typeName.LastIndexOf('.');
            string namespaceName = dot < 0 ? string.Empty : typeName.Substring(0, dot);
            string shortTypeName = typeName.Substring(dot + 1);

            if (string.Equals("System.ComponentModel.DataAnnotations", namespaceName, StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            foreach (Type t in MockSharedCodeService._knownSharedAttributeTypes)
            {
                if (string.Equals(t.FullName, typeName))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #3
0
        public void IsAssemblyMsCorlibTest()
        {
            AssemblyName mscorlib          = typeof(object).Assembly.GetName();
            AssemblyName system            = typeof(System.Uri).Assembly.GetName();
            AssemblyName systemCore        = typeof(System.Linq.IQueryable <>).Assembly.GetName();
            AssemblyName domainServices    = typeof(OpenRiaServices.DomainServices.Server.DomainService).Assembly.GetName();
            AssemblyName dataAnnotations   = typeof(System.ComponentModel.DataAnnotations.DisplayAttribute).Assembly.GetName();
            AssemblyName executingAssembly = Assembly.GetExecutingAssembly().GetName();

            Assert.IsTrue(AssemblyUtilities.IsAssemblyMsCorlib(mscorlib), "mscorlib");
            Assert.IsFalse(AssemblyUtilities.IsAssemblyMsCorlib(system), "system");
            Assert.IsFalse(AssemblyUtilities.IsAssemblyMsCorlib(systemCore), "systemCore");
            Assert.IsFalse(AssemblyUtilities.IsAssemblyMsCorlib(domainServices), "domainServices");
            Assert.IsFalse(AssemblyUtilities.IsAssemblyMsCorlib(dataAnnotations), "dataAnnotations");
            Assert.IsFalse(AssemblyUtilities.IsAssemblyMsCorlib(executingAssembly), "Executing Assembly");
        }
Example #4
0
        public void IsAssemblyMsCorlibTest()
        {
            var mscorlib          = typeof(object).Assembly.GetName();
            var system            = typeof(Uri).Assembly.GetName();
            var systemCore        = typeof(IQueryable <>).Assembly.GetName();
            var simpleEntity      = typeof(EntityDescription).Assembly.GetName();
            var dataAnnotations   = typeof(System.ComponentModel.DataAnnotations.DisplayAttribute).Assembly.GetName();
            var executingAssembly = Assembly.GetExecutingAssembly().GetName();

            Assert.IsTrue(AssemblyUtilities.IsAssemblyMsCorlib(mscorlib), "mscorlib");
            Assert.IsFalse(AssemblyUtilities.IsAssemblyMsCorlib(system), "system");
            Assert.IsFalse(AssemblyUtilities.IsAssemblyMsCorlib(systemCore), "systemCore");
            Assert.IsFalse(AssemblyUtilities.IsAssemblyMsCorlib(simpleEntity), "simpleEntity");
            Assert.IsFalse(AssemblyUtilities.IsAssemblyMsCorlib(dataAnnotations), "dataAnnotations");
            Assert.IsFalse(AssemblyUtilities.IsAssemblyMsCorlib(executingAssembly), "Executing Assembly");
        }