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


C# CodeDom.CodeTypeMember类代码示例

本文整理汇总了C#中System.CodeDom.CodeTypeMember的典型用法代码示例。如果您正苦于以下问题:C# CodeTypeMember类的具体用法?C# CodeTypeMember怎么用?C# CodeTypeMember使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CodeTypeMember类属于System.CodeDom命名空间,在下文中一共展示了CodeTypeMember类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValidateTypeMember

        private void ValidateTypeMember(CodeTypeMember e) {
            ValidateCommentStatements(e.Comments);
            ValidateCodeDirectives(e.StartDirectives);
            ValidateCodeDirectives(e.EndDirectives);
            if (e.LinePragma != null) ValidateLinePragmaStart(e.LinePragma);

            if (e is CodeMemberEvent) {
                ValidateEvent((CodeMemberEvent)e);
            } 
            else if (e is CodeMemberField) {
                ValidateField((CodeMemberField)e);
            } 
            else if (e is CodeMemberMethod) {
                ValidateMemberMethod((CodeMemberMethod)e);
            } 
            else if (e is CodeMemberProperty) {
                ValidateProperty((CodeMemberProperty)e);
            } 
            else if (e is CodeSnippetTypeMember) {
                ValidateSnippetMember((CodeSnippetTypeMember)e);
            } 
            else if (e is CodeTypeDeclaration) {
                ValidateTypeDeclaration((CodeTypeDeclaration)e);
            } 
            else {
                throw new ArgumentException(SR.GetString(SR.InvalidElementType, e.GetType().FullName), "e");
            }
        }
开发者ID:uQr,项目名称:referencesource,代码行数:28,代码来源:CodeValidator.cs

示例2: Process

        public void Process(CodeNamespace code, System.Xml.Schema.XmlSchema schema)
        {
            foreach (CodeTypeDeclaration type in code.Types)
            {
                if (type.IsClass || type.IsStruct)
                {
                    // Copy the colletion to an array for safety. We will be
                    // changing this collection.
                    CodeTypeMember[] members = new CodeTypeMember[type.Members.Count];
                    type.Members.CopyTo(members, 0);

                    foreach (CodeTypeMember member in members)
                    {
                        // Process fields only.
                        if (member is CodeMemberField)
                        {
                            CodeMemberProperty prop = new CodeMemberProperty();
                            prop.Name = member.Name;

                            prop.Attributes = member.Attributes;
                            prop.Type = ((CodeMemberField)member).Type;

                            // Copy attributes from field to the property.
                            prop.CustomAttributes.AddRange(member.CustomAttributes);
                            member.CustomAttributes.Clear();

                            // Copy comments from field to the property.
                            prop.Comments.AddRange(member.Comments);
                            member.Comments.Clear();

                            // Modify the field.
                            member.Attributes = MemberAttributes.Private;
                            Char[] letters = member.Name.ToCharArray();
                            letters[0] = Char.ToLower(letters[0]);
                            member.Name = String.Concat("_", new string(letters));

                            prop.HasGet = true;
                            prop.HasSet = true;

                            // Add get/set statements pointing to field. Generates:
                            // return this._fieldname;
                            prop.GetStatements.Add(
                                new CodeMethodReturnStatement(
                                new CodeFieldReferenceExpression(new CodeThisReferenceExpression(),
                                member.Name)));
                            // Generates:
                            // this._fieldname = value;
                            prop.SetStatements.Add(
                                new CodeAssignStatement(
                                new CodeFieldReferenceExpression(new CodeThisReferenceExpression(),
                                member.Name),
                                new CodeArgumentReferenceExpression("value")));

                            // Finally add the property to the type
                            type.Members.Add(prop);
                        }
                    }
                }
            }
        }
开发者ID:Gufalagupagup,项目名称:raml-dotnet-tools,代码行数:60,代码来源:FieldsToPropertiesExtension.cs

示例3: Deny_Unrestricted

		public void Deny_Unrestricted ()
		{
			VBCodeProvider vbprov = new VBCodeProvider ();
			Assert.AreEqual ("vb", vbprov.FileExtension, "FileExtension");
			Assert.AreEqual (LanguageOptions.CaseInsensitive, vbprov.LanguageOptions, "LanguageOptions");
			Assert.IsNotNull (vbprov.CreateCompiler (), "CreateCompiler");
			Assert.IsNotNull (vbprov.CreateGenerator (), "CreateGenerator");
			try {
				Assert.IsNotNull (vbprov.GetConverter (typeof (string)), "GetConverter");
			}
			catch (NotImplementedException) {
				// mono
			}
#if NET_2_0
			CodeTypeMember ctm = new CodeTypeMember ();
			StringWriter sw = new StringWriter ();
			CodeGeneratorOptions cgo = new CodeGeneratorOptions ();
			try {
				vbprov.GenerateCodeFromMember (ctm, sw, cgo);
			}
			catch (NotImplementedException) {
				// mono
			}
#endif
		}
开发者ID:nlhepler,项目名称:mono,代码行数:25,代码来源:VBCodeProviderCas.cs

示例4: AddDescription

        protected void AddDescription(CodeTypeMember type, IEntityDescription description)
        {
            if (String.IsNullOrWhiteSpace(description.Description))
                return;

            AddAttribute(type, "Description", description.Description);
        }
开发者ID:scy0846,项目名称:Umbraco.CodeGen,代码行数:7,代码来源:EntityDescriptionGenerator.cs

示例5: CodeTypeMemberExtension

 /// <summary>
 /// Creates a new instance of CodeTypeMemberExtension class.
 /// </summary>
 /// <param name="extendObject">An object to be decorated by this instance.</param>
 public CodeTypeMemberExtension(CodeTypeMember extendedObject, CodeTypeExtension parent) 
     : base(extendedObject)
 {                                  
     if (typeof(CodeMemberField) == extendedObject.GetType())
     {
         this.kind = CodeTypeMemberKind.Field;
     }
     else if (typeof(CodeMemberMethod) == extendedObject.GetType())
     {
         this.kind = CodeTypeMemberKind.Method;
     }
     else if (typeof(CodeMemberProperty) == extendedObject.GetType())
     {
         this.kind = CodeTypeMemberKind.Property;
     }
     else if (typeof(CodeMemberEvent) == extendedObject.GetType())
     {
         this.kind = CodeTypeMemberKind.Event;
     }
     else if (typeof(CodeSnippetTypeMember) == extendedObject.GetType())
     {
         this.kind = CodeTypeMemberKind.Snippet;
     }
     else if (typeof(CodeConstructor) == extendedObject.GetType())
     {
         this.kind = CodeTypeMemberKind.Constructor;
     }
     else if (typeof(CodeTypeConstructor) == extendedObject.GetType())
     {
         this.kind = CodeTypeMemberKind.StaticConstructor;
     }
     this.parent = parent;
 }
开发者ID:gtri-iead,项目名称:LEXS-NET-Sample-Implementation-3.1.4,代码行数:37,代码来源:CodeTypeMemberExtension.cs

示例6: CreateProperty

		/// <summary>
		/// Creation method.
		/// </summary>
		/// <param name="className">Class name</param>
		/// <param name="isGet">isGet flag</param>
		/// <param name="member">Member</param>
		/// <param name="statement">Statement</param>
		/// <returns></returns>
		/// <remarks>For properties.</remarks>
		public static MethodInfo CreateProperty(string className,
		                                        bool isGet,
												CodeTypeMember member,
		                                        CodeStatement statement)
		{
			return new MethodInfo(member, className, true, isGet, statement);
		}
开发者ID:divyang4481,项目名称:lextudio,代码行数:16,代码来源:MethodInfo.cs

示例7: AddAttribute

 public static CodeAttributeDeclaration AddAttribute(CodeTypeMember tgtMethodCLR, string attr)
 {
     var declaration =
         new CodeAttributeDeclaration(new CodeTypeReference(attr, CodeTypeReferenceOptions.GlobalReference));
     tgtMethodCLR.CustomAttributes.Add(declaration);
     return declaration;
 }
开发者ID:brian-2447,项目名称:jni4net,代码行数:7,代码来源:Utils.cs

示例8: GetCompatibleMemberInClass

		public static IMember GetCompatibleMemberInClass (ProjectDom ctx, IType cls, CodeTypeMember member)
		{
			//check for identical property names
			foreach (IProperty prop in cls.Properties) {
				if (string.Compare (prop.Name, member.Name, StringComparison.OrdinalIgnoreCase) == 0) {
					EnsureClassExists (ctx, prop.ReturnType.FullName, GetValidRegion (prop));
					CodeMemberProperty memProp = member as CodeMemberProperty;
					if (memProp == null || !IsTypeCompatible (ctx, prop.ReturnType.FullName, memProp.Type.BaseType))
						throw new MemberExistsException (cls.FullName, MemberType.Property, member, GetValidRegion (prop), cls.CompilationUnit.FileName);
					return prop;
				}
			}
				
			//check for identical method names
			foreach (IMethod meth in cls.Methods) {
				if (string.Compare (meth.Name, member.Name, StringComparison.OrdinalIgnoreCase) == 0) {
					EnsureClassExists (ctx, meth.ReturnType.FullName, GetValidRegion (meth));
					CodeMemberMethod memMeth = member as CodeMemberMethod;
					if (memMeth == null || !IsTypeCompatible (ctx, meth.ReturnType.FullName, memMeth.ReturnType.BaseType))
						throw new MemberExistsException (cls.FullName, MemberType.Method, member, GetValidRegion (meth), cls.CompilationUnit.FileName);
					return meth;
				}
			}
			
			//check for identical event names
			foreach (IEvent ev in cls.Events) {
				if (string.Compare (ev.Name, member.Name, StringComparison.OrdinalIgnoreCase) == 0) {
					EnsureClassExists (ctx, ev.ReturnType.FullName, GetValidRegion (ev));
					CodeMemberEvent memEv = member as CodeMemberEvent;
					if (memEv == null || !IsTypeCompatible (ctx, ev.ReturnType.FullName, memEv.Type.BaseType))
						throw new MemberExistsException (cls.FullName, MemberType.Event, member, GetValidRegion (ev), cls.CompilationUnit.FileName);
					return ev;
				}
			}
				
			//check for identical field names
			foreach (IField field in cls.Fields) {
				if (string.Compare (field.Name, member.Name, StringComparison.OrdinalIgnoreCase) == 0) {
					EnsureClassExists (ctx, field.ReturnType.FullName, GetValidRegion (field));
					CodeMemberField memField = member as CodeMemberField;
					if (memField == null || !IsTypeCompatible (ctx, field.ReturnType.FullName, memField.Type.BaseType))
						throw new MemberExistsException (cls.FullName, MemberType.Field, member, GetValidRegion (field), cls.CompilationUnit.FileName);
					return field;
				}
			}
			
			//walk down into base classes, if any
			foreach (IReturnType baseType in cls.BaseTypes) {
				IType c = ctx.GetType (baseType);
				if (c == null)
					throw new TypeNotFoundException (baseType.FullName, cls.BodyRegion, cls.CompilationUnit.FileName);
				IMember mem = GetCompatibleMemberInClass (ctx, c, member);
				if (mem != null)
					return mem;
			}
			
			//return null if no match
			return null;
		}
开发者ID:okrmartin,项目名称:monodevelop,代码行数:59,代码来源:BindingService.cs

示例9: TemplateMemberResult

 public TemplateMemberResult(ITemplateClassGenerator templateClass, MemberInfo memberInfo, GenerateMember memberAttribute, CodeTypeMember memberOutput, CodeTypeDeclaration decleration)
 {
     Decleration = decleration;
     TemplateClass = templateClass;
     MemberInfo = memberInfo;
     MemberAttribute = memberAttribute;
     MemberOutput = memberOutput;
 }
开发者ID:InvertGames,项目名称:uFrame.Editor,代码行数:8,代码来源:TemplateMemberResult.cs

示例10: Constructor1_NullItem

		public void Constructor1_NullItem ()
		{
			CodeTypeMember[] typeMembers = new CodeTypeMember[] { 
				new CodeTypeMember (), null };

			CodeTypeMemberCollection coll = new CodeTypeMemberCollection (
				typeMembers);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:CodeTypeMemberCollectionTest.cs

示例11: AddRange

 /// <devdoc>
 /// <para>Copies the elements of an array to the end of the <see cref='System.CodeDom.CodeTypeMemberCollection'/>.</para>
 /// </devdoc>
 public void AddRange(CodeTypeMember[] value) {
     if (value == null) {
         throw new ArgumentNullException("value");
     }
     for (int i = 0; ((i) < (value.Length)); i = ((i) + (1))) {
         this.Add(value[i]);
     }
 }
开发者ID:REALTOBIZ,项目名称:mono,代码行数:11,代码来源:CodeTypeMemberCollection.cs

示例12: AddDisplayNameIfDifferent

 protected static void AddDisplayNameIfDifferent(CodeTypeMember type, IEntityDescription description)
 {
     var name = description.Name;
     if (String.Compare(name, description.Alias, IgnoreCase) == 0 ||
         String.Compare(name, description.Alias.SplitPascalCase(), IgnoreCase) == 0)
         return;
     AddAttribute(type, "DisplayName", name);
 }
开发者ID:scy0846,项目名称:Umbraco.CodeGen,代码行数:8,代码来源:EntityDescriptionGenerator.cs

示例13: AddAttribute

        public void AddAttribute(CodeTypeMember member, string attributeType,
            string expression = null)
        {
            // Add [attributeType(expression)]
            var argument = new CodeAttributeArgument(new CodeSnippetExpression(expression));
            var attribute = new CodeAttributeDeclaration(attributeType, argument);

            member.CustomAttributes.Add(attribute);
        }
开发者ID:brendanhay,项目名称:Shared,代码行数:9,代码来源:CompilerService.cs

示例14: AddXmlEnumAttribute

        private static void AddXmlEnumAttribute(CodeTypeMember member)
        {
            CodeTypeReference attributeType = new CodeTypeReference(typeof (XmlEnumAttribute));
            CodePrimitiveExpression argumentValue = new CodePrimitiveExpression(member.Name);
            CodeAttributeArgument argument = new CodeAttributeArgument(argumentValue);
            CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(attributeType, argument);

            member.CustomAttributes.Add(attribute);
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:9,代码来源:ImproveEnumFieldsCommand.cs

示例15: IsMetaDataGeneratable

        public static bool IsMetaDataGeneratable(CodeTypeMember member)
        {
            foreach (CodeAttributeDeclaration attribute in member.CustomAttributes)
            {
                if (attribute.Name == "PrimaryKey" || attribute.Name == "KeyProperty" || attribute.Name == "Field" || attribute.Name == "Property" || attribute.Name == "Version" || attribute.Name == "Timestamp")
                    return true;
            }

            return false;
        }
开发者ID:mgagne-atman,项目名称:Projects,代码行数:10,代码来源:ModelProperty.cs


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