コード例 #1
0
ファイル: PropertyInjector.cs プロジェクト: cj525/yaclops
 private void AddToCollection(ParserPositionalParameterResult param, object collection, Type concreteType, Type[] genericArgs)
 {
     var add = concreteType.GetMethod("Add");
     TypeConverter typeConverter = TypeDescriptor.GetConverter(genericArgs.First());
     foreach (var stringVal in param.Values)
     {
         var val = typeConverter.ConvertFromString(stringVal);
         add.Invoke(collection, new[] { val });
     }
 }
		protected virtual new void BeforeMapSet(IModelInspector modelInspector, PropertyPath member, ISetPropertiesMapper propertyCustomizer)
		{
			if (modelInspector.IsManyToMany(member.LocalMember) == true)
			{
				propertyCustomizer.Key(x => x.Column(member.LocalMember.DeclaringType.Name + "_Id"));

				Type sourceType = member.LocalMember.DeclaringType;
				Type destinationType = member.LocalMember.GetPropertyOrFieldType().GetGenericArguments().First();
				String [] names = new Type[] { sourceType, destinationType }.Select(x => x.Name).OrderBy(x => x).ToArray();

				//set inverse on the relation of the alphabetically first entity name
				propertyCustomizer.Inverse(sourceType.Name == names.First());
				//set mapping table name from the entity names in alphabetical order
				propertyCustomizer.Table(String.Join("_", names));
			}
		}
コード例 #3
0
ファイル: BindingParser.cs プロジェクト: holajan/dotvvm
 private IEnumerable<ParameterExpression> GetParameters(Type contextType, Type[] parents, Type controlType = null)
 {
     if (controlType != null)
     {
         yield return Expression.Parameter(controlType, "_control");
     }
     yield return Expression.Parameter(contextType, "_this");
     if (parents.Length > 0)
     {
         yield return Expression.Parameter(parents.Last(), "_root");
         yield return Expression.Parameter(parents.First(), Constants.ParentSpecialBindingProperty);
         for (int i = 0; i < parents.Length; i++)
         {
             yield return Expression.Parameter(parents[i], Constants.ParentSpecialBindingProperty + i);
         }
     }
     else
     {
         yield return Expression.Parameter(contextType, "_root");
     }
 }
コード例 #4
0
 private Type GetPrimaryProxyType(Type[] typesToProxy)
 {
     if (typesToProxy.Any(x => x.IsSubclassOf(typeof(Delegate)))) return typesToProxy.First(x => x.IsSubclassOf(typeof(Delegate)));
     if (typesToProxy.Any(x => x.IsClass)) return typesToProxy.First(x => x.IsClass);
     return typesToProxy.First();
 }
コード例 #5
0
        public void CreateInheritedClass(bool isMutable)
        {
            var typeNames = new[] { "b", "a" };

            Type[] interfaceTypes = new Type[] { typeof(ITestClass) };
            Type parentType = typeof(TestClass);

            Type anonymousGenericTypeDefinition =
                isMutable
                ? AnonymousTypeUtils.CreateMutableGenericTypeDefinition(typeNames, parentType, interfaceTypes)
                : anonymousGenericTypeDefinition = AnonymousTypeUtils.CreateGenericTypeDefinition(typeNames, parentType, interfaceTypes);

            if (!anonymousGenericTypeDefinition.IsSubclassOf(parentType))
                Debugger.Launch();
            Assert.IsTrue(anonymousGenericTypeDefinition.IsSubclassOf(parentType));

            Assert.IsTrue(anonymousGenericTypeDefinition.GetInterface(interfaceTypes.First().Name) != null);
        }
コード例 #6
0
		private void AddTasks(Type[] taskTypes, ListView listView)
		{
			if (taskTypes == null)
				throw new ArgumentNullException("taskTypes");

			if (listView == null)
				throw new ArgumentNullException("listView");

			//if (Tasks.Any(t => t.GetType() == task.GetType()))
			//{
			//	var msg = "Multi".ValidateLicense();

			//	if (msg != null)
			//	{
			//		_logManager.Application.AddErrorLog(msg);

			//		new MessageBoxBuilder()
			//			.Text(LocalizedStrings.Str2903Params.Put(task.GetDisplayName()))
			//			.Warning()
			//			.Owner(this)
			//			.Show();

			//		return;	
			//	}
			//}

			BusyIndicator.IsBusy = true;
			BusyIndicator.BusyContent = LocalizedStrings.Str2904Params.Put(taskTypes.First().GetDisplayName());

			var tasks = new List<IHydraTask>();

			Task.Factory
				.StartNew(() =>
				{
					foreach (var type in taskTypes)
					{
						this.GuiSync(() =>
						{
							BusyIndicator.BusyContent = LocalizedStrings.Str2904Params.Put(type.GetDisplayName());
						});

						var task = type.CreateInstance<IHydraTask>();

						var settings = new HydraTaskSettings
						{
							Id = Guid.NewGuid(),
							WorkingFrom = TimeSpan.Zero,
							WorkingTo = TimeHelper.LessOneDay,
							IsDefault = true,
							TaskType = type.GetTypeName(false),
						};

						_entityRegistry.TasksSettings.Add(settings);
						_entityRegistry.TasksSettings.DelayAction.WaitFlush();

						InitTask(task, settings);

						var allSec = _entityRegistry.Securities.ReadById(Core.Extensions.AllSecurityId);

						task.Settings.Securities.Add(task.ToTaskSecurity(allSec));
						task.Settings.Securities.DelayAction.WaitFlush();

						tasks.Add(task);
					}
				})
				.ContinueWithExceptionHandling(this, res =>
				{
					BusyIndicator.IsBusy = false;

					if (!res)
						return;

					Tasks.AddRange(tasks);

					var last = tasks.LastOrDefault();

					if (last != null)
					{
						NavigationBar.SelectedIndex = last.IsCategoryOf(TaskCategories.Tool) ? 1 : 0;

						listView.SelectedItem = last;
						listView.ScrollIntoView(last);

						foreach (var task in tasks)
						{
							var pane = EnsureTaskPane(task);

							if (pane != null)
								ShowPane(pane);

							//EditTask(newTask);	
						}
					}
				});
		}
コード例 #7
0
		static void ConventionsMapping(ConventionModelMapper mapper)
		{
			mapper.IsOneToMany((MemberInfo member, Boolean isLikely) =>
			{
				Type sourceType = member.DeclaringType;
				Type destinationType = member.GetMemberFromDeclaringType().GetPropertyOrFieldType();

				//check if the property is of a generic collection type
				if ((destinationType.IsGenericCollection() == true) && (destinationType.GetGenericArguments().Length == 1))
				{
					Type destinationEntityType = destinationType.GetGenericArguments().Single();

					//check if the type of the generic collection property is an entity
					if (mapper.ModelInspector.IsEntity(destinationEntityType) == true)
					{
						//check if there is an equivalent property on the target type that is also a generic collection and points to this entity
						PropertyInfo collectionInDestinationType = destinationEntityType.GetProperties().Where(x => (x.PropertyType.IsGenericCollection() == true) && (x.PropertyType.GetGenericArguments().Length == 1) && (x.PropertyType.GetGenericArguments().Single() == sourceType)).SingleOrDefault();

						if (collectionInDestinationType != null)
						{
							return (false);
						}
					}
				}

				return (true);
			});

			mapper.IsManyToMany((MemberInfo member, Boolean isLikely) =>
			{
				//a relation is many to many if it isn't one to many
				Boolean isOneToMany = mapper.ModelInspector.IsOneToMany(member);
				return (!isOneToMany);
			});

			mapper.BeforeMapClass += (IModelInspector modelInspector, Type type, IClassAttributesMapper classCustomizer) =>
			{
				classCustomizer.Id(x =>
				{
					//set the hilo generator
					x.Generator(Generators.HighLow);
				});
			};

			mapper.BeforeMapManyToMany += (IModelInspector modelInspector, PropertyPath member, IManyToManyMapper collectionRelationManyToManyCustomizer) =>
			{
				Type destinationEntityType = member.LocalMember.GetPropertyOrFieldType().GetGenericArguments().First();
				//set the mapping table column names from each source entity name plus the _Id sufix
				collectionRelationManyToManyCustomizer.Column(destinationEntityType.Name + "_Id");
			};

			mapper.BeforeMapSet += (IModelInspector modelInspector, PropertyPath member, ISetPropertiesMapper propertyCustomizer) =>
			{
				if (modelInspector.IsManyToMany(member.LocalMember) == true)
				{
					propertyCustomizer.Key(x => x.Column(member.LocalMember.DeclaringType.Name + "_Id"));

					Type sourceType = member.LocalMember.DeclaringType;
					Type destinationType = member.LocalMember.GetPropertyOrFieldType().GetGenericArguments().First();
					String [] names = new Type[] { sourceType, destinationType }.Select(x => x.Name).OrderBy(x => x).ToArray();

					//set inverse on the relation of the alphabetically first entity name
					propertyCustomizer.Inverse(sourceType.Name == names.First());
					//set mapping table name from the entity names in alphabetical order
					propertyCustomizer.Table(String.Join("_", names));
				}
			};
		}
コード例 #8
0
ファイル: ConfigurationBuilder.cs プロジェクト: hyrmn/Jubilee
 public void RegisterPlugin(Type[] knownTypes, PluginConfiguration pluginConfiguration, IEnumerable<PluginConfiguration> pluginsConfiguration)
 {
     var plugin = knownTypes.GetType(pluginConfiguration.Name);
     kernel.Bind<IPlugin>().To(plugin).OnActivation((activatedPlugin)=>{
         ((dynamic)activatedPlugin).Initialise(pluginConfiguration.Parameters);
     });
     foreach (var pluginConfig in pluginsConfiguration)
     {
         var openGenericPluginType = typeof(IDependsOnPlugin<>);
         var closedGenericPluginType = openGenericPluginType.MakeGenericType(plugin);
         kernel.Bind(closedGenericPluginType).To(knownTypes.First(x => x.Name == pluginConfig.Name)).OnActivation((activatedPlugin) =>
         {
             ((dynamic)activatedPlugin).Initialise(pluginConfig.Parameters);
         });
     }
 }
コード例 #9
0
        private static void VerifyTypeEquality(Type[] t1, Type[] t2)
        {
            if (TestHelper.AreNotNull(t1, t2))
            {
                Assert.AreEqual(t1.Count(), t2.Count());
                foreach (Type type1 in t1)
                {
                    Type type2 = t2.First(e => e.FullName == type1.FullName);

                    TestHelper.VerifyAttributesEquality(type1.GetCustomAttributesData(), type2.GetCustomAttributesData());
                    TestHelper.VerifyPropertiesEquality(type1.GetProperties(), type2.GetProperties());
                    TestHelper.VerifyMethodsEquality(type1.GetMethods(), type2.GetMethods());
                    TestHelper.VerifyTypeEquality(type1.GetNestedTypes(), type2.GetNestedTypes());
                    TestHelper.VerifyFieldsEquality(type1.GetFields(), type2.GetFields());
                }
            }
        }