Beispiel #1
0
        // ReSharper disable once RedundantAssignment
        private static void BindSettingsImplementation(
            ref MemenimScriptSettings value)
        {
            var targetType = typeof(MemenimScriptSettings);

            var assemblies = new List <Assembly>
            {
                Assembly.GetEntryAssembly(),
                Assembly.GetCallingAssembly(),
                Assembly.GetExecutingAssembly()
            };

            assemblies.AddRange(AppDomain.CurrentDomain.GetAssemblies());

            foreach (var assembly in assemblies)
            {
                if (assembly == null)
                {
                    continue;
                }

                var types = assembly.GetTypes()
                            .Where(type => type.IsClass &&
                                   targetType.IsAssignableFrom(type) &&
                                   (type != targetType))
                            .ToArray();

                if (types.Length == 0)
                {
                    continue;
                }

                foreach (var type in types)
                {
                    MemenimScriptSettings target;

                    try
                    {
                        target = (MemenimScriptSettings)Activator.CreateInstance(
                            type, true);
                    }
                    catch (Exception)
                    {
                        continue;
                    }

                    if (target == null)
                    {
                        continue;
                    }

                    value = target;

                    return;
                }
            }

            value = new MemenimScriptSettings();
        }
Beispiel #2
0
        private static MemenimScriptSettings GetSettingsImplementation(
            ref MemenimScriptSettings value)
        {
            if (value != null)
            {
                return(value);
            }

            var notImplementedType =
                typeof(MemenimScriptSettings);

            value = (MemenimScriptSettings)Activator.CreateInstance(
                notImplementedType, true);

            return(value);
        }