System.Collections.Generic.Dictionary.ContainsKey(System.Type)

Here are the examples of the csharp api System.Collections.Generic.Dictionary.ContainsKey(System.Type) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1557 Examples 7

19 Source : UnpackerRegistry.cs
with MIT License
from Azukee

public static void Register<T>(Func<string, bool> condition) where T : IUnpacker, new()
        {
            var type = typeof(T);
            if (Conditions.ContainsKey(type))
                throw new Exception($"Condition for unpacker {type} has already been registered.");

            Conditions.Add(type, condition);
        }

19 Source : ListObjectTypeVisitor.cs
with MIT License
from Azure

public override void Visit(IAcceptor acceptor, KeyValuePair<string, Type> type, NamingStrategy namingStrategy, params Attribute[] attributes)
        {
            var name = this.Visit(acceptor, name: type.Key, replacedle: null, dataType: "array", dataFormat: null, attributes: attributes);

            if (name.IsNullOrWhiteSpace())
            {
                return;
            }

            var instance = acceptor as OpenApiSchemaAcceptor;
            if (instance.IsNullOrDefault())
            {
                return;
            }

            // Gets the schema for the underlying type.
            var underlyingType = type.Value.GetUnderlyingType();
            var types = new Dictionary<string, Type>()
            {
                { underlyingType.GetOpenApiReferenceId(underlyingType.IsOpenApiDictionary(), underlyingType.IsOpenApiArray(), namingStrategy), underlyingType }
            };
            var schemas = new Dictionary<string, OpenApiSchema>();

            OpenApiSchemaAcceptor subAcceptor;
            if (!this.visitedTypes.ContainsKey(underlyingType))
            {
                subAcceptor = new OpenApiSchemaAcceptor()
                {
                    Types = types, RootSchemas = instance.RootSchemas, Schemas = schemas,
                };
                this.visitedTypes.Add(underlyingType, subAcceptor);
                subAcceptor.Accept(this.VisitorCollection, namingStrategy);

            }
            else
            {
                subAcceptor = this.visitedTypes[underlyingType];
            }

            var items = subAcceptor.Schemas.First().Value;

            // Forces to remove the replacedle value from the items attribute.
            items.replacedle = null;

            // Adds the reference to the schema for the underlying type.
            if (this.IsReferential(underlyingType))
            {
                var reference = new OpenApiReference()
                {
                    Type = ReferenceType.Schema,
                    Id = underlyingType.GetOpenApiReferenceId(underlyingType.IsOpenApiDictionary(), underlyingType.IsOpenApiArray(), namingStrategy)
                };

                items.Reference = reference;
            }

            instance.Schemas[name].Items = items;

            // Adds schemas to the root.
            var schemasToBeAdded = subAcceptor.Schemas
                                              .Where(p => p.Value.IsOpenApiSchemaObject()
                                                       || p.Value.IsOpenApiSchemaArray()
                                                       || p.Value.IsOpenApiSchemaDictionary()
                                                    )
                                              .ToDictionary(p => p.Key, p => p.Value);

            if (!schemasToBeAdded.Any())
            {
                return;
            }

            foreach (var schema in schemasToBeAdded)
            {
                if (instance.RootSchemas.ContainsKey(schema.Key))
                {
                    continue;
                }

                instance.RootSchemas.Add(schema.Key, schema.Value);
            }
        }

19 Source : DictionaryObjectTypeVisitor.cs
with MIT License
from Azure

public override void Visit(IAcceptor acceptor, KeyValuePair<string, Type> type, NamingStrategy namingStrategy, params Attribute[] attributes)
        {
            var name = this.Visit(acceptor, name: type.Key, replacedle: null, dataType: "object", dataFormat: null, attributes: attributes);

            if (name.IsNullOrWhiteSpace())
            {
                return;
            }

            var instance = acceptor as OpenApiSchemaAcceptor;
            if (instance.IsNullOrDefault())
            {
                return;
            }

            // Gets the schema for the underlying type.
            var underlyingType = type.Value.GetUnderlyingType();
            var types = new Dictionary<string, Type>()
            {
                { underlyingType.GetOpenApiReferenceId(underlyingType.IsOpenApiDictionary(), underlyingType.IsOpenApiArray(), namingStrategy), underlyingType }
            };
            var schemas = new Dictionary<string, OpenApiSchema>();

            OpenApiSchemaAcceptor subAcceptor;
            if (!this.visitedTypes.ContainsKey(underlyingType))
            {
                subAcceptor = new OpenApiSchemaAcceptor()
                {
                    Types = types, RootSchemas = instance.RootSchemas, Schemas = schemas,
                };
                this.visitedTypes.Add(underlyingType, subAcceptor);
                subAcceptor.Accept(this.VisitorCollection, namingStrategy);
            }
            else
            {
                subAcceptor = this.visitedTypes[underlyingType];
            }

            var properties = subAcceptor.Schemas.First().Value;

            // Forces to remove the replacedle value from the additionalProperties attribute.
            properties.replacedle = null;

            // Adds the reference to the schema for the underlying type.
            if (this.IsReferential(underlyingType))
            {
                var reference = new OpenApiReference()
                {
                    Type = ReferenceType.Schema,
                    Id = underlyingType.GetOpenApiReferenceId(underlyingType.IsOpenApiDictionary(), underlyingType.IsOpenApiArray(), namingStrategy)
                };

                properties.Reference = reference;
            }

            instance.Schemas[name].AdditionalProperties = properties;

            // Adds schemas to the root.
            var schemasToBeAdded = subAcceptor.Schemas
                                              .Where(p => p.Value.IsOpenApiSchemaObject()
                                                       || p.Value.IsOpenApiSchemaArray()
                                                       || p.Value.IsOpenApiSchemaDictionary()
                                                    )
                                              .ToDictionary(p => p.Key, p => p.Value);

            if (!schemasToBeAdded.Any())
            {
                return;
            }

            foreach (var schemaToBeAdded in schemasToBeAdded)
            {
                if (instance.RootSchemas.ContainsKey(schemaToBeAdded.Key))
                {
                    continue;
                }

                instance.RootSchemas.Add(schemaToBeAdded.Key, schemaToBeAdded.Value);
            }
        }

19 Source : ObjectGenerator.cs
with MIT License
from Azure

public static bool CanGenerateObject(Type type)
            {
                return DefaultGenerators.ContainsKey(type);
            }

19 Source : AzureDevOpsService.cs
with MIT License
from Azure

private async Task<T> GetClientAsync<T>() 
            where T : VssHttpClientBase
        {
            var type = typeof(T);
            T result;
            await clientCacheSemapreplaced.WaitAsync();
            if (clientCache.ContainsKey(type))
            {
                
                result = (T)clientCache[type];
            }
            else
            {
                result = await connection.GetClientAsync<T>();
                clientCache.Add(type, result);
            }

            clientCacheSemapreplaced.Release();
            return result;
        }

19 Source : Connector.cs
with MIT License
from banditoth

public static Page CreateInstance<TViewmodel>(Action<TViewmodel, Page> initialiser = null) where TViewmodel : BaseViewModel
        {
            if (_connections.ContainsKey(typeof(TViewmodel)) == false)
                throw new Exception($"The ({typeof(TViewmodel)}) is not registered. Use the {nameof(Register)} method to register it");

            Type pageType = _connections[typeof(TViewmodel)];
            Page pageInstance = (Page)Activator.CreateInstance(pageType);
            TViewmodel viewModelInstance = (TViewmodel)Activator.CreateInstance(typeof(TViewmodel));

            pageInstance.BindingContext = viewModelInstance;

            if (initialiser != null)
            {
                initialiser.Invoke(viewModelInstance, pageInstance);
            }

            return pageInstance;
        }

19 Source : Connector.cs
with MIT License
from banditoth

public static void Register(Type viewModelType, Type viewType)
        {
            if (viewType == null)
                throw new Exception($"The {nameof(viewType)} could not be null!");

            if (viewModelType == null)
                throw new Exception($"The {nameof(viewModelType)} could not be null!");

            if (_connections.ContainsKey(viewModelType))
                throw new Exception($"This type has been already registered.: {viewModelType.FullName}");

            _connections.Add(viewModelType, viewType);
        }

19 Source : SolutionItemIconRegistry.cs
with The Unlicense
from BAndysc

private ImageUri GetIcon<T>(T item) where T : ISolutionItem
        {
            if (nameProviders.ContainsKey(item.GetType()))
            {
                var x = (ISolutionItemIconProvider<T>)nameProviders[item.GetType()];
                return x.GetIcon(item);                
            }

            return item.IsContainer ? new ImageUri("Icons/folder.png") : new ImageUri("Icons/doreplacedent.png");
        }

19 Source : DBEntry.cs
with The Unlicense
from BAndysc

public int[] GetPadding()
        {
            var padding = new int[Data.Columns.Count];

            var bytecounts = new Dictionary<Type, int>
            {
                {typeof(byte), 1},
                {typeof(short), 2},
                {typeof(ushort), 2}
            };

            if (Header is WDC1 header)
            {
                var c = 0;

                foreach (ColumnStructureEntry field in header.ColumnMeta)
                {
                    Type type = Data.Columns[c].DataType;
                    bool isneeded = field.CompressionType >= CompressionType.Sparse;

                    if (bytecounts.ContainsKey(type) && isneeded)
                    {
                        for (var x = 0; x < field.ArraySize; x++)
                            padding[c++] = 4 - bytecounts[type];
                    }
                    else
                        c += field.ArraySize;
                }
            }

            return padding;
        }

19 Source : FieldUtil.cs
with MIT License
from Baste-RainGames

public static float HeightRequiredToDraw(Type t, int currentRecursionDepth = 0)
        {
            if (!heightRequiredToDrawType.ContainsKey(t))
                CacheRequiredHeightFor(t, currentRecursionDepth);
            return heightRequiredToDrawType[t];
        }

19 Source : FieldUtil.cs
with MIT License
from Baste-RainGames

public static List<FieldInfo> SerializableFields(Type t)
        {
            if (!serializableFieldsForType.ContainsKey(t))
                CacheSerializableFieldsFor(t);
            return serializableFieldsForType[t];
        }

19 Source : FieldUtil.cs
with MIT License
from Baste-RainGames

public static List<FieldInfo> DrawableFields(Type t)
        {
            if (!drawableFieldsForType.ContainsKey(t))
                CacheDrawableFieldsFor(t);
            return drawableFieldsForType[t];
        }

19 Source : SerializableAction_SingleDrawer.cs
with MIT License
from Baste-RainGames

private static void EnsureDataCached(Type type)
        {
            if (!typeToMethods.ContainsKey(type))
            {
                var methods = MethodLister.SerializeableMethodsOn(type);
                var methodNames = new string[methods.Count + 1];
                methodNames[0] = NoMethodSelected;
                for (int i = 0; i < methods.Count; i++)
                {
                    methodNames[i + 1] = MethodName(methods[i]);
                }

                var fields = FieldUtil.SerializableFields(type);

                typeToMethods[type] = methods;
                typeToFields[type] = fields.Select(field => new SerializableFieldSetter(field)).ToList();
                typeToNames[type] = methodNames.Concat(fields.Select(ShowFieldName)).ToArray();
            }
        }

19 Source : SubscribedMethodsCacheSingleton.cs
with MIT License
from BEagle1984

public IReadOnlyCollection<SubscribedMethod> GetMethods(
            object message,
            IServiceProvider serviceProvider)
        {
            var messageType = message.GetType();

            lock (_cache)
            {
                if (_cache.ContainsKey(messageType))
                    return _cache[messageType];
            }

            var subscribers = GetAllSubscribedMethods(serviceProvider)
                .Where(subscribedMethod => AreCompatible(message, subscribedMethod)).ToList();

            lock (_cache)
            {
                _cache[messageType] = subscribers;
            }

            return subscribers;
        }

19 Source : MessageController.cs
with Apache License 2.0
from beetlex-io

public static ObjectInstanceHandler InstanceHandler(Type type)
		{
			ObjectInstanceHandler handler;
			if (mInstanceHandlers.ContainsKey(type))
			{
				handler = mInstanceHandlers[type];
			}
			else
			{
				lock (typeof(ReflectionHandlerFactory))
				{
					if (mInstanceHandlers.ContainsKey(type))
					{
						handler = mInstanceHandlers[type];
					}
					else
					{
						handler = CreateInstanceHandler(type);
						mInstanceHandlers.Add(type, handler);
					}
				}
			}
			return handler;
		}

19 Source : EntityReader.cs
with Apache License 2.0
from beetlex-io

public static ObjectInstanceHandler InstanceHandler(Type type)
        {
            ObjectInstanceHandler handler;
            if (mInstanceHandlers.ContainsKey(type))
            {
                handler = mInstanceHandlers[type];
            }
            else
            {
                lock (typeof(ReflectionHandlerFactory))
                {
                    if (mInstanceHandlers.ContainsKey(type))
                    {
                        handler = mInstanceHandlers[type];
                    }
                    else
                    {
                        handler = CreateInstanceHandler(type);
                        mInstanceHandlers.Add(type, handler);
                    }
                }
            }
            return handler;
        }

19 Source : InheritedTypesRegistry.cs
with MIT License
from Belenar

void IInheritedTypesRegistry.RegisterInheritedType<TParentType, TChildType>(string typeName)
        {
            var parentType = typeof(TParentType);

            if (!_registrations.ContainsKey(parentType))
            {
                _registrations[parentType] = new Dictionary<string, Func<object>>();
                _registrations[parentType][string.Empty] = () => new TParentType();
            }

            _registrations[parentType][typeName] = () => new TChildType();
        }

19 Source : InheritedTypesRegistry.cs
with MIT License
from Belenar

public bool CanConvert(Type objectType)
        {
            return _registrations.ContainsKey(objectType);
        }

19 Source : UnifiedLibManager.cs
with GNU General Public License v3.0
from benaclejames

private static void FindAndInitRuntimes(bool eye = true, bool lip = true)
        {
            IL2CPP.il2cpp_thread_attach(IL2CPP.il2cpp_domain_get());

            var trackingModules = replacedembly.GetExecutingreplacedembly().GetTypes()
                .Where(type => typeof(ITrackingModule).IsreplacedignableFrom(type) && !type.IsInterface);

            foreach (var module in trackingModules)
            {
                bool eyeSuccess = false, lipSuccess = false;    // Init result for every 
                
                var moduleObj = (ITrackingModule) Activator.CreateInstance(module);
                // If there is still a need for a module with eye or lip tracking and this module supports the current need, try initialize it
                if (!EyeEnabled && moduleObj.SupportsEye || !LipEnabled && moduleObj.SupportsLip)
                    (eyeSuccess, lipSuccess) = moduleObj.Initialize(eye, lip);

                // If the module successfully initialized anything, add it to the list of useful modules and start its update thread
                if ((eyeSuccess || lipSuccess) && !UsefulModules.ContainsKey(module))
                {
                    UsefulModules.Add(module, moduleObj);
                    if (ShouldThread)
                        moduleObj.StartThread();
                }

                if (eyeSuccess) EyeEnabled = true;
                if (lipSuccess) LipEnabled = true;

                if (EyeEnabled && LipEnabled) break;    // Keep enumerating over all modules until we find ones we can use
            }

            if (eye)
                MelonLogger.Msg(EyeEnabled
                    ? "Eye Tracking Initialized"
                    : "Eye Tracking will be unavailable for this session.");

            if (lip)
            {
                if (LipEnabled) MelonLogger.Msg("Lip Tracking Initialized");
                else MelonLogger.Warning("Lip Tracking will be unavailable for this session.");
            }

            if (SceneManager.GetActiveScene().buildIndex == -1 && QuickModeMenu.MainMenu != null)
                MainMod.MainThreadExecutionQueue.Add(() => QuickModeMenu.MainMenu.UpdateEnabledTabs(EyeEnabled, LipEnabled));
        }

19 Source : SettingFieldDrawer.cs
with GNU Lesser General Public License v3.0
from BepInEx

private bool CanCovert(string value, Type type)
        {
            if (_canCovertCache.ContainsKey(type))
                return _canCovertCache[type];

            try
            {
                var _ = Convert.ChangeType(value, type);
                _canCovertCache[type] = true;
                return true;
            }
            catch
            {
                _canCovertCache[type] = false;
                return false;
            }
        }

19 Source : EmitBasic.cs
with MIT License
from BigBigZBBing

private Delegate CacheMethod<T>()
        {
            if (emitMethod.ContainsKey(typeof(T)))
            {
                return emitMethod[typeof(T)];
            }
            MethodInfo method = generatorType.GetMethod("Emit", new[] { typeof(OpCode), typeof(T) });
            Delegate deleg = method.CreateDelegate(typeof(Action<OpCode, T>), generator);
            emitMethod.Add(typeof(T), deleg);
            return deleg;
        }

19 Source : Services.cs
with MIT License
from bilal-fazlani

public void Add(Type type, object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if(!type.IsInstanceOfType(value))
            {
                throw new ArgumentException($"{nameof(value)} '{value.GetType()}' must be an instance of {nameof(type)} '{type}'");
            }
            if (_servicesByType.ContainsKey(type))
            {
                throw new ArgumentException($"service for {nameof(type)} '{type}' already exists '{_servicesByType[type]}'");
            }

            _servicesByType.Add(type, value);
        }

19 Source : Services.cs
with MIT License
from bilal-fazlani

public bool Contains(Type type)
        {
            return _servicesByType.ContainsKey(type)
                   || (_appConfigServices?.Contains(type) ?? false);
        }

19 Source : TestDependencyResolver.cs
with MIT License
from bilal-fazlani

public object? Resolve(Type type)
        {
            if (!_services.ContainsKey(type))
            {
                throw new Exception($"Dependency not registered: {type}");
            }
            return _services[type];
        }

19 Source : Diagram.cs
with MIT License
from Blazor-Diagrams

public void RegisterBehavior(Behavior behavior)
        {
            var type = behavior.GetType();
            if (_behaviors.ContainsKey(type))
                throw new Exception($"Behavior '{type.Name}' already registered");

            _behaviors.Add(type, behavior);
        }

19 Source : Diagram.cs
with MIT License
from Blazor-Diagrams

public void UnregisterBehavior<T>() where T : Behavior
        {
            var type = typeof(T);
            if (!_behaviors.ContainsKey(type))
                return;

            _behaviors[type].Dispose();
            _behaviors.Remove(type);
        }

19 Source : Diagram.cs
with MIT License
from Blazor-Diagrams

public void RegisterModelComponent(Type modelType, Type componentType)
        {
            if (_componentByModelMapping.ContainsKey(modelType))
                throw new Exception($"Component already registered for model '{modelType.Name}'.");

            _componentByModelMapping.Add(modelType, componentType);
        }

19 Source : Diagram.cs
with MIT License
from Blazor-Diagrams

public Type? GetComponentForModel<M>(M model) where M : Model
        {
            var modelType = model.GetType();
            return _componentByModelMapping.ContainsKey(modelType) ? _componentByModelMapping[modelType] : null;
        }

19 Source : EnumUtil.cs
with MIT License
from blish-hud

public static T[] GetCachedValues<T>() where T : Enum {
            if (!_cachedEnumValues.ContainsKey(typeof(T))) {
                _cachedEnumValues.Add(typeof(T), Enum.GetValues(typeof(T)));
            }

            return _cachedEnumValues[typeof(T)].Cast<T>().ToArray();
        }

19 Source : ContextsService.cs
with MIT License
from blish-hud

private void UnregisterContext<TContext>() {
            if (_registeredContexts.ContainsKey(typeof(TContext))) {
                var context = _registeredContexts[typeof(TContext)];

                _registeredContexts.Remove(typeof(TContext));

                context.DoUnload();
            }
        }

19 Source : ContextsService.cs
with MIT License
from blish-hud

public TContext GetContext<TContext>() where TContext : Context {
            if (!_registeredContexts.ContainsKey(typeof(TContext))) return null;

            return _registeredContexts[typeof(TContext)] as TContext;
        }

19 Source : EntityBase.cs
with GNU General Public License v3.0
from BlowaXD

public virtual bool HasComponent<T>() where T : IComponent => Components.ContainsKey(typeof(T));

19 Source : RuntimeSmartIpcRouter.cs
with GNU General Public License v3.0
from BlowaXD

public Task RegisterAsync(Type type, IRoutingInformation routingInformation)
        {
            if (_infos.ContainsKey(type))
            {
                return Task.CompletedTask;
            }

            _infos.Add(type, routingInformation);
            return Task.CompletedTask;
        }

19 Source : PacketHandlersContainer.cs
with GNU General Public License v3.0
from BlowaXD

public Task UnregisterAsync(Type type)
        {
            if (_packetHandlers.ContainsKey(type))
            {
                OnUnregistered(type);
                _packetHandlers.Remove(type);
            }

            return Task.CompletedTask;
        }

19 Source : BasicPacketPipelineAsync.cs
with GNU General Public License v3.0
from BlowaXD

public Task RegisterAsync(IPacketProcessor processor, Type packetType)
        {
            if (_packetProcessors.ContainsKey(packetType))
            {
                return Task.CompletedTask;
            }

            _packetTypesByHeader.Add(packetType.GetCustomAttribute<PacketHeaderAttribute>().Identification, packetType);
            _packetProcessors[packetType] = processor;
            return Task.CompletedTask;
        }

19 Source : PacketHandlersContainer.cs
with GNU General Public License v3.0
from BlowaXD

public Task RegisterAsync(IIpcPacketHandler handler, Type type)
        {
            if (_packetHandlers.ContainsKey(type))
            {
                Log.Info($"{type} is already handled");
                return Task.CompletedTask;
            }

            Log.Warn($"HANDLING -> {type}");
            _packetHandlers.Add(type, handler);
            OnRegistered(type);
            return Task.CompletedTask;
        }

19 Source : MethodWarpsCache.cs
with MIT License
from blueberryzzz

public LuaCSFunction GetDelegateWrap(Type type)
        {
            //UnityEngine.Debug.LogWarning("GetDelegateWrap:" + type );
            if (!typeof(Delegate).IsreplacedignableFrom(type))
            {
                return null;
            }
            if (!delegateCache.ContainsKey(type))
            {
                delegateCache[type] = _GenMethodWrap(type, type.ToString(), new MethodBase[] { type.GetMethod("Invoke") }).Call;
            }
            return delegateCache[type];
        }

19 Source : LuaBehaviorEditor.cs
with MIT License
from blueberryzzz

static Type GetWrapType(Type objType)
    {
        if (objWrapEditorDict.ContainsKey(objType))
        {
            return objWrapEditorDict[objType];
        }
        TypeBuilder wrapTypeBld = editorModule.DefineType("wrap" + objType.FullName, TypeAttributes.Public, typeof(ScriptableObject));
        FieldBuilder objField = wrapTypeBld.DefineField("obj", objType, FieldAttributes.Public);
        Type wrapType = wrapTypeBld.CreateType();
        objWrapEditorDict.Add(objType, wrapType);
        return wrapType;
    }

19 Source : LuaBehaviour.cs
with MIT License
from blueberryzzz

public static object JsonToValue(string json, Type type)
    {
        if(wrapTypeDict.ContainsKey(type))
        {
            Type wrapType = wrapTypeDict[type];
            var target = JsonUtility.FromJson(json, wrapType);
            return ((IObjWrap)target).GetObj();
        }
        else if(type.IsValueType())
        {
            //Debug.LogError($"msut register {type.FullName} in wrapTypeDict!");
            Debug.LogError($"msut register {type.FullName} in wrapTypeDict, because it is value type!");
            return null;
        }
        else
        {
            Type wrapType = typeof(ObjWrap<>).MakeGenericType(type);
            wrapTypeDict.Add(type, wrapType);
            var target = JsonUtility.FromJson(json, wrapType);
            return ((IObjWrap)target).GetObj();
        }
    }

19 Source : MethodWarpsCache.cs
with MIT License
from blueberryzzz

public LuaCSFunction GetConstructorWrap(Type type)
        {
            //UnityEngine.Debug.LogWarning("GetConstructor:" + type);
            if (!constructorCache.ContainsKey(type))
            {
                var constructors = type.GetConstructors();
                if (type.IsAbstract() || constructors == null || constructors.Length == 0)
                {
                    if (type.IsValueType())
                    {
                        constructorCache[type] = (L) =>
                        {
                            translator.PushAny(L, Activator.CreateInstance(type));
                            return 1;
                        };
                    }
                    else
                    {
                        return null;
                    }
                }
                else
                {
                    LuaCSFunction ctor = _GenMethodWrap(type, ".ctor", constructors, true).Call;
                    
                    if (type.IsValueType())
                    {
                        bool hasZeroParamsCtor = false;
                        for (int i = 0; i < constructors.Length; i++)
                        {
                            if (constructors[i].GetParameters().Length == 0)
                            {
                                hasZeroParamsCtor = true;
                                break;
                            }
                        }
                        if (hasZeroParamsCtor)
                        {
                            constructorCache[type] = ctor;
                        }
                        else
                        {
                            constructorCache[type] = (L) =>
                            {
                                if (LuaAPI.lua_gettop(L) == 1)
                                {
                                    translator.PushAny(L, Activator.CreateInstance(type));
                                    return 1;
                                }
                                else
                                {
                                    return ctor(L);
                                }
                            };
                        }
                    }
                    else
                    {
                        constructorCache[type] = ctor;
                    }
                }
            }
            return constructorCache[type];
        }

19 Source : MethodWarpsCache.cs
with MIT License
from blueberryzzz

public LuaCSFunction GetMethodWrap(Type type, string methodName)
        {
            //UnityEngine.Debug.LogWarning("GetMethodWrap:" + type + " " + methodName);
            if (!methodsCache.ContainsKey(type))
            {
                methodsCache[type] = new Dictionary<string, LuaCSFunction>();
            }
            var methodsOfType = methodsCache[type];
            if (!methodsOfType.ContainsKey(methodName))
            {
                MemberInfo[] methods = type.GetMember(methodName, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
                if (methods == null || methods.Length == 0 ||
#if UNITY_WSA && !UNITY_EDITOR
                    methods[0] is MethodBase
#else
                    methods[0].MemberType != MemberTypes.Method
#endif
                    )
                {
                    return null;
                }
                methodsOfType[methodName] = _GenMethodWrap(type, methodName, methods).Call;
            }
            return methodsOfType[methodName];
        }

19 Source : MethodWarpsCache.cs
with MIT License
from blueberryzzz

public LuaCSFunction GetEventWrap(Type type, string eventName)
        {
            if (!methodsCache.ContainsKey(type))
            {
                methodsCache[type] = new Dictionary<string, LuaCSFunction>();
            }

            var methodsOfType = methodsCache[type];
            if (!methodsOfType.ContainsKey(eventName))
            {
                {
                    EventInfo eventInfo = type.GetEvent(eventName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.NonPublic);
                    if (eventInfo == null)
                    {
                        throw new Exception(type.Name + " has no event named: " + eventName);
                    }
                    int start_idx = 0;

                    MethodInfo add = eventInfo.GetAddMethod(true);
                    MethodInfo remove = eventInfo.GetRemoveMethod(true);

                    if (add == null && remove == null)
                    {
                        throw new Exception(type.Name + "'s " + eventName + " has either add nor remove");
                    }

                    bool is_static = add != null ? add.IsStatic : remove.IsStatic;
                    if (!is_static) start_idx = 1;

                    methodsOfType[eventName] = (L) =>
                    {
                        object obj = null;

                        if (!is_static)
                        {
                            obj = translator.GetObject(L, 1, type);
                            if (obj == null)
                            {
                                return LuaAPI.luaL_error(L, "invalid #1, needed:" + type);
                            }
                        }

                        try
                        {
                            object handlerDelegate = translator.CreateDelegateBridge(L, eventInfo.EventHandlerType, start_idx + 2);
                            if (handlerDelegate == null)
                            {
                                return LuaAPI.luaL_error(L, "invalid #" + (start_idx + 2) + ", needed:" + eventInfo.EventHandlerType);
                            }
                            switch (LuaAPI.lua_tostring(L, start_idx + 1))
                            {
                                case "+":
                                    if (add == null)
                                    {
                                        return LuaAPI.luaL_error(L, "no add for event " + eventName);
                                    }
                                    add.Invoke(obj, new object[] { handlerDelegate });
                                    break;
                                case "-":
                                    if (remove == null)
                                    {
                                        return LuaAPI.luaL_error(L, "no remove for event " + eventName);
                                    }
                                    remove.Invoke(obj, new object[] { handlerDelegate });
                                    break;
                                default:
                                    return LuaAPI.luaL_error(L, "invalid #" + (start_idx + 1) + ", needed: '+' or '-'" + eventInfo.EventHandlerType);
                            }
                        }
                        catch (System.Exception e)
                        {
                            return LuaAPI.luaL_error(L, "c# exception:" + e + ",stack:" + e.StackTrace);
                        }

                        return 0;
                    };
                }
            }
            return methodsOfType[eventName];
        }

19 Source : MethodWarpsCache.cs
with MIT License
from blueberryzzz

public LuaCSFunction GetMethodWrapInCache(Type type, string methodName)
        {
            //string retriKey = type.ToString() + "." + methodName;
            //return methodsCache.ContainsKey(retriKey) ? methodsCache[retriKey] : null;
            if (!methodsCache.ContainsKey(type))
            {
                methodsCache[type] = new Dictionary<string, LuaCSFunction>();
            }
            var methodsOfType = methodsCache[type];
            return methodsOfType.ContainsKey(methodName) ? methodsOfType[methodName] : null;
        }

19 Source : MapRepository.cs
with GNU General Public License v3.0
from bonarr

public ColumnMapCollection GetColumns(Type enreplacedyType)
        {
            if (!Columns.ContainsKey(enreplacedyType))
            {
                lock (_columnsLock)
                {
                    if (!Columns.ContainsKey(enreplacedyType))
                    {
                        ColumnMapCollection columnMaps = GetMapStrategy(enreplacedyType).MapColumns(enreplacedyType);
                        Columns.Add(enreplacedyType, columnMaps);
                        return columnMaps;
                    }
                }
            }

            return Columns[enreplacedyType];
        }

19 Source : MapRepository.cs
with GNU General Public License v3.0
from bonarr

public RelationshipCollection GetRelationships(Type type)
        {
            if (!Relationships.ContainsKey(type))
            {
                lock (_relationshipsLock)
                {
                    if (!Relationships.ContainsKey(type))
                    {
                        RelationshipCollection relationships = GetMapStrategy(type).MapRelationships(type);
                        Relationships.Add(type, relationships);
                        return relationships;
                    }
                }
            }

            return Relationships[type];
        }

19 Source : MapRepository.cs
with GNU General Public License v3.0
from bonarr

internal IConverter GetConverter(Type dataType)
        {
            if (TypeConverters.ContainsKey(dataType))
            {
                // User registered type converter
                return TypeConverters[dataType];
            }
            if (TypeConverters.ContainsKey(typeof(Enum)) && dataType.IsEnum)
            {
                // A converter is registered to handled enums
                return TypeConverters[typeof(Enum)];
            }
            if (TypeConverters.ContainsKey(typeof(object)))
            {
                // User registered default converter
                return TypeConverters[typeof(object)];
            }
            // No conversion
            return null;
        }

19 Source : MapRepository.cs
with GNU General Public License v3.0
from bonarr

public void RegisterMapStrategy(Type enreplacedyType, IMapStrategy strategy)
        {
            if (_columnMapStrategies.ContainsKey(enreplacedyType))
                _columnMapStrategies[enreplacedyType] = strategy;
            else
                _columnMapStrategies.Add(enreplacedyType, strategy);
        }

19 Source : MapRepository.cs
with GNU General Public License v3.0
from bonarr

private IMapStrategy GetMapStrategy(Type enreplacedyType)
        {
            if (_columnMapStrategies.ContainsKey(enreplacedyType))
            {
                // Return enreplacedy specific column map strategy
                return _columnMapStrategies[enreplacedyType];
            }
            // Return the default column map strategy
            return _columnMapStrategies[typeof(object)];
        }

19 Source : MapRepository.cs
with GNU General Public License v3.0
from bonarr

internal string GetTableName(Type enreplacedyType)
        {
            if (!Tables.ContainsKey(enreplacedyType))
            {
                lock (_tablesLock)
                {
                    if (!Tables.ContainsKey(enreplacedyType))
                    {
                        string tableName = GetMapStrategy(enreplacedyType).MapTable(enreplacedyType);
                        Tables.Add(enreplacedyType, tableName);
                        return tableName;
                    }
                }
            }

            return Tables[enreplacedyType];
        }

19 Source : HashAlgoFactory.cs
with GNU General Public License v3.0
from bonarr

public static T Create<T>()
            where T : HashAlgorithm
        {
            if (algos.ContainsKey(typeof(T)))
                return (T)Activator.CreateInstance(algos[typeof(T)]);
            return null;
        }

See More Examples