当前位置: 首页>>代码示例>>C#>>正文


C# ModelElement.GetType方法代码示例

本文整理汇总了C#中ModelElement.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ModelElement.GetType方法的具体用法?C# ModelElement.GetType怎么用?C# ModelElement.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ModelElement的用法示例。


在下文中一共展示了ModelElement.GetType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddClass

        public static void AddClass(ModelElement cls, CodeTypeDeclaration declaration)
        {
            if (!isInitialized)
                throw new ArgumentException("CodeGenerationContext must first be initialized");
            if (cls == null)
                throw new ArgumentNullException("No class supplied", "cls");
            if (declaration == null)
                throw new ArgumentNullException("No CodeTypeDeclaration supplied", "declaration");

            if (cls.GetType() == typeof(ModelClass))
            {
                ModelClass modelClass = (ModelClass)cls;
                if (!classDeclarations.ContainsKey(modelClass))
                    classDeclarations.Add(modelClass, declaration);
            }
            else if (cls.GetType() == typeof(NestedClass))
            {
                NestedClass nestedClass = (NestedClass)cls;
                if (!nestedClassDeclarations.ContainsKey(nestedClass))
                    nestedClassDeclarations.Add(nestedClass, declaration);
            }
            else
                throw new ArgumentException("Only ModelClass and NestedClass entities supported", "cls");

            generatedClassNames.Add(((NamedElement)cls).Name);
        }
开发者ID:mgagne-atman,项目名称:Projects,代码行数:26,代码来源:CodeGenerationContext.cs

示例2: GetTypeDeclaration

        public static CodeTypeDeclaration GetTypeDeclaration(ModelElement cls)
        {
            if (!isInitialized)
                throw new ArgumentException("CodeGenerationContext must first be initialized");
            if (cls == null)
                throw new ArgumentNullException("No class supplied", "cls");

            if (cls.GetType() == typeof(ModelClass))
            {
                return classDeclarations[(ModelClass)cls];
            }
            else if (cls.GetType() == typeof(NestedClass))
            {
                return nestedClassDeclarations[(NestedClass)cls];
            }
            else
                throw new ArgumentException("Only ModelClass and NestedClass entities supported", "cls");
        }
开发者ID:mgagne-atman,项目名称:Projects,代码行数:18,代码来源:CodeGenerationContext.cs

示例3: ModelElementToString

		public static string ModelElementToString(ModelElement element)
		{
			Guard.ArgumentNotNull(element, "element");

			string name;
			DomainClassInfo.TryGetName(element, out name);
			name = name ?? "no name";
			string type = element.GetType().Name;
			return String.Format(CultureInfo.CurrentUICulture, "{0} '{1}' {2}", type, name, element.Id);
		}
开发者ID:Phidiax,项目名称:open-wssf-2015,代码行数:10,代码来源:ValidationEngine.cs

示例4: GetPropertyDomainObjectId

        /// <summary>
        /// Gets the domain property id of a property on a model element.
        /// </summary>
        /// <param name="modelElement">Model element containing the named property.</param>
        /// <param name="propertyName">Property name of the property, for which to get the property domain id.</param>
        /// <returns>Domain property id if found, null otherwise.</returns>
        public static Guid? GetPropertyDomainObjectId(ModelElement modelElement, string propertyName)
        {
            PropertyInfo propertyInfo = modelElement.GetType().GetProperty(propertyName);
            if (propertyInfo != null)
            {
                object[] obj = propertyInfo.GetCustomAttributes(typeof(DomainObjectIdAttribute), false);
                if (obj.Length == 1)
                {
                    DomainObjectIdAttribute idAttribute = (DomainObjectIdAttribute)obj[0];
                    return idAttribute.Id;
                }
            }

            return null;
        }
开发者ID:apoorv-vijay-joshi,项目名称:FSE-2011-PDE,代码行数:21,代码来源:PropertyGridEditorViewModel.cs

示例5: CreatePropertyDescriptor

		/// <summary>
		/// Create a property descriptor for the given property on
		/// the element to emulate the behavior of modifying this
		/// property in the properties window. This will succeed if the property
		/// passed in has a corresponding meta attribute.
		/// </summary>
		/// <param name="element">The element to create a descriptor for</param>
		/// <param name="propertyName">The name of the property on the native object.
		/// Note that the name of this property may be displayed differently in the
		/// properties window. For example, Role.RolePlayerDisplay is shown as RolePlayer
		/// in the properties window.</param>
		/// <returns>PropertyDescriptor, or null if not available</returns>
		public PropertyDescriptor CreatePropertyDescriptor(ModelElement element, string propertyName)
		{
			Type elementType = element.GetType();
			PropertyInfo propInfo = elementType.GetProperty(propertyName);
			if (propInfo != null)
			{
				DomainPropertyInfo attrInfo = element.Store.DomainDataDirectory.FindDomainClass(propInfo.DeclaringType).FindDomainProperty(propertyName, true);
				if (attrInfo != null)
				{
					return DomainTypeDescriptor.CreatePropertyDescriptor(element, attrInfo);
				}
			}
			return null;
		}
开发者ID:cjheath,项目名称:NORMA,代码行数:26,代码来源:ORMTestHooks.cs

示例6: DoValidate

 private static void DoValidate(ModelElement element, ValidationContext context, string ruleSet)
 {
     Validator validator = validatorFactory.CreateValidator(element.GetType(), ruleSet);           
     ValidationResults results = validator.Validate(element);
     if (!results.IsValid)
     {
         WriteResultsToLog(context, results);
     }
 }
开发者ID:Phidiax,项目名称:open-wssf-2015,代码行数:9,代码来源:ValidationEngine.cs

示例7: Search

        /// <summary>
        /// Search a specific model element by using the given search criteria.
        /// </summary>
        /// <param name="modelElement">Model element to be searched.</param>
        /// <param name="criteria">Search criteria to use.</param>
		/// <param name="searchText">Text to search.</param>
        /// <param name="options">Search options.</param>
        /// <returns>Search result list if any found. Empty list otherwise.</returns>
        public virtual List<SearchResult> Search(ModelElement modelElement, SearchCriteriaEnum criteria, string searchText, SearchOptions options)
        {
            List<SearchResult> results = new List<SearchResult>();
            DomainClassInfo info = modelElement.GetDomainClass();
            Type modelElementType = modelElement.GetType();

            #region properties
            if (criteria == SearchCriteriaEnum.Name ||
                criteria == SearchCriteriaEnum.NameAndType ||
                criteria == SearchCriteriaEnum.All ||
                criteria == SearchCriteriaEnum.Properties || 
				criteria == SearchCriteriaEnum.PropertiesWithoutName)
                foreach (DomainPropertyInfo propertyInfo in info.AllDomainProperties)
                {
                    if (propertyInfo == info.NameDomainProperty &&
                        criteria != SearchCriteriaEnum.Name &&
                        criteria != SearchCriteriaEnum.NameAndType &&
                        criteria != SearchCriteriaEnum.Properties &&
                        criteria != SearchCriteriaEnum.All)
                        continue;
                    else if (propertyInfo != info.NameDomainProperty &&
                        criteria != SearchCriteriaEnum.All &&
                        criteria != SearchCriteriaEnum.Properties &&
                        criteria != SearchCriteriaEnum.PropertiesWithoutName)
                        continue;

                    object nameValue = GetPropertyValue(modelElement, modelElementType, propertyInfo.Name);
                    if (nameValue == null && System.String.IsNullOrEmpty(searchText))
                    {
                        SearchResult searchResult = new SearchResult();
                        searchResult.IsSuccessFull = true;
                        searchResult.Source = modelElement;
                        searchResult.Reason = "Property " + propertyInfo.Name + " is 'null'";

                        results.Add(searchResult);
                    }
                    else if (nameValue != null && !System.String.IsNullOrEmpty(searchText))
                        if (Contains(nameValue.ToString(), searchText, options))
                        {
                            SearchResult searchResult = new SearchResult();
                            searchResult.IsSuccessFull = true;
                            searchResult.Source = modelElement;
                            searchResult.Reason = "Property " + propertyInfo.Name + " contains '" + searchText + "'";

                            results.Add(searchResult);
                        }

                }
			#endregion

            #region roles
            if (criteria == SearchCriteriaEnum.Roles ||
                criteria == SearchCriteriaEnum.All)
            {
                foreach (DomainRoleInfo roleInfo in info.AllDomainRolesPlayed)
                {
                    if (!roleInfo.IsSource)
                        continue;

                    DomainRelationshipInfo relInfo = roleInfo.DomainRelationship;
                    if (!IsLinkIncludedInDomainTree(modelElement.Store as DomainModelStore, relInfo.Id))
                        continue;

                    ReadOnlyCollection<ElementLink> links = DomainRoleInfo.GetElementLinks<ElementLink>(modelElement, roleInfo.Id);
                    if (links.Count == 0 && String.IsNullOrEmpty(searchText))
                    {
                        SearchResult searchResult = new SearchResult();
                        searchResult.IsSuccessFull = true;
                        searchResult.Source = modelElement;
                        searchResult.Reason = "Role " + roleInfo.PropertyName + " is empty";

                        results.Add(searchResult);
                    }

                    foreach (ElementLink link in links)
                    {
                        ModelElement m = DomainRoleInfo.GetTargetRolePlayer(link);
                        if (m == null && System.String.IsNullOrEmpty(searchText))
                        {
                            SearchResult searchResult = new SearchResult();
                            searchResult.IsSuccessFull = true;
                            searchResult.Source = modelElement;
                            searchResult.Reason = "Role " + roleInfo.PropertyName + " is null";

                            results.Add(searchResult);
                        }
                        else if (m != null && !System.String.IsNullOrEmpty(searchText))
                            if (Contains((m as IDomainModelOwnable).DomainElementFullName, searchText, options))
                            {
                                SearchResult searchResult = new SearchResult();
                                searchResult.IsSuccessFull = true;
                                searchResult.Source = modelElement;
//.........这里部分代码省略.........
开发者ID:apoorv-vijay-joshi,项目名称:FSE-2011-PDE,代码行数:101,代码来源:ModelElementSearchProcessor.cs

示例8: WritePropertiesAsAttributes

        /// <summary>
        /// Write all properties that need to be serialized as XML attributes.
        /// </summary>
        /// <param name="serializationContext">Serialization context.</param>
        /// <param name="element">PatternModelSchemaDiagram instance to be serialized.</param>
        /// <param name="writer">XmlWriter to write serialized data to.</param>
        protected override void WritePropertiesAsAttributes(SerializationContext serializationContext, ModelElement element, XmlWriter writer)
        {
            Guard.NotNull(() => serializationContext, serializationContext);
            Guard.NotNull(() => element, element);
            Guard.NotNull(() => writer, writer);

            writer.WriteAttributeString("type", element.GetType().FullName);
            base.WritePropertiesAsAttributes(serializationContext, element, writer);
        }
开发者ID:StevenVanDijk,项目名称:NuPattern,代码行数:15,代码来源:PatternModelSchemaDiagramSerializer.cs

示例9: GetModelElementProperties

        public static List<KeyValuePair<PropertyInfo, object>> GetModelElementProperties(ModelElement element, params string[] propertyNames)
        {
            var modelElementType = element.GetType();
            var properties = new List<KeyValuePair<PropertyInfo, object>>();

            for (int i = 0; i < propertyNames.Count(); i++)
            {
                var property = modelElementType.GetProperties().FirstOrDefault(p => p.Name == propertyNames[i]);

                properties.Add(new KeyValuePair<PropertyInfo, object>(property, property.GetValue(element)));
            }

            return properties;
        }
开发者ID:Exclr8,项目名称:CloudCore,代码行数:14,代码来源:base.cs


注:本文中的ModelElement.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。