Пример #1
0
        internal static InstantiateObject GetFastObjectCreationDelegate(Type t)
        {
            // Look for the factory class in the same assembly
            Assembly a = t.Assembly;

            string shortAssemblyName = Util.GetAssemblyShortName(t.Assembly);

            shortAssemblyName = shortAssemblyName.ToLower(CultureInfo.InvariantCulture);
            Type factoryType = a.GetType(factoryFullClassNameBase + Util.MakeValidTypeNameFromString(shortAssemblyName));

            if (factoryType == null)
            {
                return(null);
            }

            string methodName = GetCreateMethodNameForType(t.FullName);

            try {
                return((InstantiateObject)Delegate.CreateDelegate(
                           typeof(InstantiateObject), factoryType, methodName));
            }
            catch {
                return(null);
            }
        }
Пример #2
0
        internal ObjectFactoryCodeDomTreeGenerator(string outputAssemblyName)
        {
            _codeCompileUnit = new CodeCompileUnit();

            CodeNamespace sourceDataNamespace = new CodeNamespace(
                BaseCodeDomTreeGenerator.internalAspNamespace);

            _codeCompileUnit.Namespaces.Add(sourceDataNamespace);

            // Make the class name vary based on the assembly (VSWhidbey 363214)
            string factoryClassName = factoryClassNameBase +
                                      Util.MakeValidTypeNameFromString(outputAssemblyName).ToLower(CultureInfo.InvariantCulture);

            // Create a single class, in which a method will be added for each
            // type that needs to be fast created in this assembly
            _factoryClass = new CodeTypeDeclaration(factoryClassName);

            // Make the class internal (VSWhidbey 363214)
            _factoryClass.TypeAttributes &= ~TypeAttributes.Public;

            // We generate a dummy line pragma, just so it will end with a '#line hidden'
            // and prevent the following generated code from ever being treated as user
            // code.  We need to use this hack because CodeDOM doesn't allow simply generating
            // a '#line hidden'. (VSWhidbey 199384)
            CodeSnippetTypeMember dummySnippet = new CodeSnippetTypeMember(String.Empty);

#if !PLATFORM_UNIX /// Unix file system
            // CORIOLISTODO: Unix file system
            dummySnippet.LinePragma = new CodeLinePragma(@"c:\\dummy.txt", 1);
#else // !PLATFORM_UNIX
            dummySnippet.LinePragma = new CodeLinePragma(@"/dummy.txt", 1);
#endif // !PLATFORM_UNIX
            _factoryClass.Members.Add(dummySnippet);

            // Add a private default ctor to make the class non-instantiatable (VSWhidbey 340829)
            CodeConstructor ctor = new CodeConstructor();
            ctor.Attributes |= MemberAttributes.Private;
            _factoryClass.Members.Add(ctor);

            sourceDataNamespace.Types.Add(_factoryClass);
        }
Пример #3
0
 private static string GetCreateMethodNameForType(string typeToCreate)
 {
     return("Create_" + Util.MakeValidTypeNameFromString(typeToCreate));
 }