本文整理汇总了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");
}
}
示例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);
}
}
}
}
}
示例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
}
示例4: AddDescription
protected void AddDescription(CodeTypeMember type, IEntityDescription description)
{
if (String.IsNullOrWhiteSpace(description.Description))
return;
AddAttribute(type, "Description", description.Description);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例9: TemplateMemberResult
public TemplateMemberResult(ITemplateClassGenerator templateClass, MemberInfo memberInfo, GenerateMember memberAttribute, CodeTypeMember memberOutput, CodeTypeDeclaration decleration)
{
Decleration = decleration;
TemplateClass = templateClass;
MemberInfo = memberInfo;
MemberAttribute = memberAttribute;
MemberOutput = memberOutput;
}
示例10: Constructor1_NullItem
public void Constructor1_NullItem ()
{
CodeTypeMember[] typeMembers = new CodeTypeMember[] {
new CodeTypeMember (), null };
CodeTypeMemberCollection coll = new CodeTypeMemberCollection (
typeMembers);
}
示例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]);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}