Пример #1
0
        private void InitFunctions()
        {
            if (!this.initFunctions)
            {
                _lock.AcquireWriterLock(Timeout.Infinite);
                try {
                    if (!this.initFunctions)
                    {
                        if (this.contextType != typeof(DataContext))
                        {
                            for (Type type = this.contextType; type != typeof(DataContext); type = type.BaseType)
                            {
                                foreach (MethodInfo mi in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
                                {
                                    if (IsUserFunction(mi))
                                    {
                                        if (mi.IsGenericMethodDefinition)
                                        {
                                            // Added this constraint because XML mapping model didn't support mapping sprocs to generic method.
                                            // The attribute mapping model was, however, able to support it. This check is for parity between
                                            // the two models.
                                            throw Error.InvalidUseOfGenericMethodAsMappedFunction(mi.Name);
                                        }
                                        MetaPosition mp = new MetaPosition(mi);
                                        if (!this.metaFunctions.ContainsKey(mp))
                                        {
                                            MetaFunction metaFunction = new AttributedMetaFunction(this, mi);
                                            this.metaFunctions.Add(mp, metaFunction);

                                            // pre-set all known function result types into metaType map
                                            foreach (MetaType rt in metaFunction.ResultRowTypes)
                                            {
                                                foreach (MetaType it in rt.InheritanceTypes)
                                                {
                                                    if (!this.metaTypes.ContainsKey(it.Type))
                                                    {
                                                        this.metaTypes.Add(it.Type, it);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        this.initFunctions = true;
                    }
                }
                finally {
                    _lock.ReleaseWriterLock();
                }
            }
        }
Пример #2
0
 private void InitFunctions()
 {
     if (!initFunctions)
     {
         @lock.AcquireWriterLock(-1);
         try {
             if (!initFunctions)
             {
                 if (contextType != typeof(DataContext))
                 {
                     Type baseType = contextType;
                     while (baseType != typeof(DataContext))
                     {
                         MethodInfo[] methods = baseType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                         foreach (MethodInfo methodInfo in methods)
                         {
                             if (IsUserFunction(methodInfo))
                             {
                                 if (methodInfo.IsGenericMethodDefinition)
                                 {
                                     throw System.Data.Linq.Mapping.Error.InvalidUseOfGenericMethodAsMappedFunction(methodInfo.Name);
                                 }
                                 MetaPosition key = new MetaPosition(methodInfo);
                                 if (!metaFunctions.ContainsKey(key))
                                 {
                                     MetaFunction metaFunction = new AttributedMetaFunction(this, methodInfo);
                                     metaFunctions.Add(key, metaFunction);
                                     foreach (MetaType resultRowType in metaFunction.ResultRowTypes)
                                     {
                                         foreach (MetaType inheritanceType in resultRowType.InheritanceTypes)
                                         {
                                             if (!metaTypes.ContainsKey(inheritanceType.Type))
                                             {
                                                 metaTypes.Add(inheritanceType.Type, inheritanceType);
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         baseType = baseType.BaseType;
                     }
                 }
                 initFunctions = true;
             }
         } finally {
             @lock.ReleaseWriterLock();
         }
     }
 }
        private void InitFunctions() {
            if (!this.initFunctions) {
                @lock.AcquireWriterLock(Timeout.Infinite);
                try {
                    if (!this.initFunctions) {
                        if (this.contextType != typeof(DataContext)) {
                            for (Type type = this.contextType; type != typeof(DataContext); type = type.BaseType) {
                                foreach (MethodInfo mi in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)) {
                                    if (IsUserFunction(mi)) {
                                        if (mi.IsGenericMethodDefinition) {
                                            // Added this constraint because XML mapping model didn't support mapping sprocs to generic method.
                                            // The attribute mapping model was, however, able to support it. This check is for parity between 
                                            // the two models.
                                            throw Error.InvalidUseOfGenericMethodAsMappedFunction(mi.Name);
                                        }
                                        MetaPosition mp = new MetaPosition(mi);
                                        if (!this.metaFunctions.ContainsKey(mp)) {
                                            MetaFunction metaFunction = new AttributedMetaFunction(this, mi);
                                            this.metaFunctions.Add(mp, metaFunction);

                                            // pre-set all known function result types into metaType map
                                            foreach (MetaType rt in metaFunction.ResultRowTypes) {
                                                foreach (MetaType it in rt.InheritanceTypes) {
                                                    if (!this.metaTypes.ContainsKey(it.Type)) {
                                                        this.metaTypes.Add(it.Type, it);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        this.initFunctions = true;
                    }
                }
                finally {
                    @lock.ReleaseWriterLock();
                }
            }
        }
        private void InitFunctions()
        {
            if (areFunctionsInitialized)
            {
                return;
            }

            metaModelLock.AcquireWriterLock(Timeout.Infinite);
            try
            {
                if (areFunctionsInitialized)
                {
                    return;
                }

                if (contextType != typeof(DataContext))
                {
                    for (var type = contextType; type != typeof(DataContext); type = type.BaseType)
                    {
                        foreach (var method in type.GetMethods(
                                     BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
                        {
                            if (IsUserFunction(method))
                            {
                                // Added this constraint because XML mapping model didn't support
                                // mapping sprocs to generic method.
                                // The attribute mapping model was, however, able to support it. This check is for parity between
                                // the two models.
                                if (method.IsGenericMethodDefinition)
                                {
                                    throw Error.InvalidUseOfGenericMethodAsMappedFunction(method.Name);
                                }

                                var metaPosition = new MetaPosition(method);
                                if (!metaFunctions.ContainsKey(metaPosition))
                                {
                                    var metaFunction = new AttributedMetaFunction(this, method);
                                    metaFunctions.Add(metaPosition, metaFunction);

                                    // pre-set all known function result types into metaType map
                                    foreach (var resultRowType in metaFunction.ResultRowTypes)
                                    {
                                        foreach (var inheritanceType in resultRowType.InheritanceTypes)
                                        {
                                            if (!metaTypes.ContainsKey(inheritanceType.Type))
                                            {
                                                metaTypes.Add(inheritanceType.Type, inheritanceType);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                areFunctionsInitialized = true;
            }
            finally
            {
                metaModelLock.ReleaseWriterLock();
            }
        }