Inheritance: CodeTypeMember
コード例 #1
0
ファイル: EventInfo.cs プロジェクト: divyang4481/lextudio
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="tag">Tag</param>
		/// <param name="className">Class name</param>
		public EventInfo(CodeMemberEvent tag, string className) 
			: base(tag, className)
		{
			Trace.Assert(tag != null);
			name = tag.Name;
			lineNumber = tag.LinePragma.LineNumber;
		}
コード例 #2
0
        public override CodeTypeMember ToCodeDom()
        {
            CodeMemberEvent e = new CodeMemberEvent();
            base.ToCodeDom(e);
            e.Name  = this.Conformer.NormalizeMember(this.Name,this.Attributes);
            e.Type = this.Type.TypeReference;

            return e;
        }
コード例 #3
0
ファイル: CodeMemberEventCas.cs プロジェクト: nlhepler/mono
		public void Constructor0_Deny_Unrestricted ()
		{
			CodeMemberEvent cme = new CodeMemberEvent ();
			Assert.AreEqual (0, cme.ImplementationTypes.Count, "ImplementationTypes");
			Assert.IsNull (cme.PrivateImplementationType, "PrivateImplementationType");
			cme.PrivateImplementationType = new CodeTypeReference ("System.Int32");
			Assert.AreEqual ("System.Void", cme.Type.BaseType, "Type");
			cme.Type = new CodeTypeReference ("System.Void");
		}
コード例 #4
0
 public TypescriptMemberEvent(
     IExpressionFactory expressionFactory,
     ITypescriptTypeMapper typescriptTypeMapper,
     CodeMemberEvent member,
     CodeGeneratorOptions options)
 {
     _expressionFactory = expressionFactory;
     _typescriptTypeMapper = typescriptTypeMapper;
     _member = member;
     _options = options;
 }
コード例 #5
0
ファイル: Event.cs プロジェクト: laymain/CodeDomUtils
        public static CodeMemberEvent Event(CodeTypeReference delegateType, MemberAttributes ma, string name)
        {
            var c = new CodeMemberEvent
            {
                Name = name,
                Attributes = ma,
                Type = delegateType,
            };

            return c;
        }
コード例 #6
0
ファイル: Event.cs プロジェクト: laymain/CodeDomUtils
        public static CodeCustomEvent Event(CodeTypeReference delegateType, MemberAttributes ma, string name,
            CodeMemberProperty add, CodeMemberProperty remove, CodeMemberMethod raise)
        {
            var c = new CodeMemberEvent
            {
                Name = name,
                Attributes = ma,
                Type = delegateType,
            };

            return new CodeCustomEvent(c, add, remove, raise);
        }
 internal DesignTimeEventInfo(DesignTimeType declaringType, CodeMemberEvent codeDomEvent)
 {
     if (declaringType == null)
     {
         throw new ArgumentNullException("Declaring Type");
     }
     if (codeDomEvent == null)
     {
         throw new ArgumentNullException("codeDomEvent");
     }
     this.declaringType = declaringType;
     this.codeDomEvent = codeDomEvent;
     this.name = Helper.EnsureTypeName(codeDomEvent.Name);
     this.memberAttributes = codeDomEvent.Attributes;
     this.addMethod = null;
     this.removeMethod = null;
 }
コード例 #8
0
        public System.CodeDom.CodeTypeMember Compile()
        {
            CodeMemberEvent memberEvent = new CodeMemberEvent();
            memberEvent.Type = new CodeTypeReference(type.Target);
            memberEvent.Name = name;
            memberEvent.Attributes = memberAttribute;

            for( int pos = 0; pos < comments.Count; pos++ ) {
                //  TODO loop in comments.Count
                memberEvent.Comments.Add(new CodeCommentStatement(comments[pos]));
            }
            for( int pos = 0; pos < attributes.Count; pos++ ) {
                //  TODO loop in attributes
                memberEvent.CustomAttributes.Add(new CodeAttributeDeclaration(attributes[pos].name));
            }
            return memberEvent;
        }
コード例 #9
0
        public static void AddPropertyChanging(CodeTypeDeclaration declaration)
        {
            CodeMemberEvent changingEvent = new CodeMemberEvent();
            changingEvent.Name = "PropertyChanging";
            changingEvent.Type = new CodeTypeReference(typeof(PropertyChangingEventHandler));
            changingEvent.Attributes = MemberAttributes.Public;

            declaration.Members.Add(changingEvent);

            CodeMemberMethod changingMethod = new CodeMemberMethod();
            changingMethod.Name = "OnPropertyChanging";
            changingMethod.ReturnType = new CodeTypeReference(typeof(void));
            changingMethod.Attributes = MemberAttributes.Family;
            changingMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "propertyName"));
            changingMethod.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(DebuggerNonUserCodeAttribute))));

            changingMethod.Statements.Add(new CodeConditionStatement(
                    new CodeBinaryOperatorExpression(
                        new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "PropertyChanging"),
                        CodeBinaryOperatorType.IdentityInequality,
                        new CodePrimitiveExpression(null)
                    ),
                    new CodeStatement[] {
                        new CodeExpressionStatement(
                            new CodeMethodInvokeExpression(
                                new CodeThisReferenceExpression(),
                                "PropertyChanging",
                                new CodeExpression[] {
                                    new CodeThisReferenceExpression(),
                                    new CodeObjectCreateExpression(
                                        typeof(PropertyChangingEventArgs),
                                        new CodeExpression[] {
                                            new CodeArgumentReferenceExpression("propertyName")
                                        }
                                    )
                                }
                            )
                        )
                    }
                ));

            declaration.Members.Add(changingMethod);
        }
コード例 #10
0
        public static CodeTypeMember CreateEventDefinition(
            this INamedTypeSymbol typeToWrap,
            WrapsAttrNameChangeView eventNameChangeView, 
            IList<string> namespaces    
        )
        {
            IEventSymbol wrappedEventInfo =
                typeToWrap.GetMembers(eventNameChangeView.Name).FirstOrDefault() as IEventSymbol;

            ITypeSymbol eventTypeSymbol = wrappedEventInfo.Type;

            CodeTypeReference eventTypeReference = eventTypeSymbol.GetTypeReference(namespaces);

            CodeMemberEvent codeEvent = new CodeMemberEvent
            {
                Name = eventNameChangeView.WrapperName,
                Type = eventTypeReference,
                Attributes = wrappedEventInfo.GetFlags(eventNameChangeView.TheEncapsulationLevel)
            };

            return codeEvent;
        }
コード例 #11
0
ファイル: EventEmitter.cs プロジェクト: maleficus1234/Pie
        // Builds a codedom event and attaches it to the given type.
        // It seems that there is a codedom bug: you can't make events static.
        public static void Emit(CodeTypeDeclaration codeType, Event e)
        {
            // Create the codedom event and attach to the codedom type.
            var codeEvent = new CodeMemberEvent();
            codeType.Members.Add(codeEvent);

            // Assign a name
            codeEvent.Name = e.Name;

            // Assign the type.
            codeEvent.Type = new CodeTypeReference(e.DelegateName);

            // Translate the accessibility
            MemberAttributes memberAttributes = MemberAttributes.Public;
            switch (e.Accessibility)
            {
                case Accessibility.Internal:
                    memberAttributes = MemberAttributes.FamilyAndAssembly;
                    break;
                case Accessibility.Private:
                    memberAttributes = MemberAttributes.Private;
                    break;
                case Accessibility.Protected:
                    memberAttributes = MemberAttributes.Family;
                    break;
                case Accessibility.Public:
                    memberAttributes = MemberAttributes.Public;
                    break;
            }

            // This is bugged in codedom: no effect.
            if (e.IsShared)
                memberAttributes |= MemberAttributes.Static;

            codeEvent.Attributes = memberAttributes;
        }
コード例 #12
0
ファイル: CodeGenerator.cs プロジェクト: carrie901/mono
			public void Visit (CodeMemberEvent o)
			{
				g.GenerateEvent (o, g.CurrentClass);
			}
コード例 #13
0
 public override void EnterEvent_([NotNull] XSharpParser.Event_Context context)
 {
     CodeMemberEvent evt = new CodeMemberEvent();
     evt.Name = context.Id.GetText();
     evt.Attributes = MemberAttributes.Public;
     evt.Type = new CodeTypeReference(context.Type.GetText());
     //
     if (context.Modifiers != null)
     {
         // Get standard Visibilities
         evt.Attributes = ContextToEventModifiers(context.Modifiers);
         if (context.Modifiers.NEW().Length > 0)
             evt.Attributes |= MemberAttributes.New;
         if (context.Modifiers.STATIC().Length > 0)
             evt.Attributes |= MemberAttributes.Static;
         if (context.Modifiers.VIRTUAL().Length > 0)
         {
             // According to MSDN, The absence of the Final flag makes a member virtual in C#, same for us
             evt.Attributes &= ~MemberAttributes.Final;
         }
         else
         {
             // Other cases = FINAL
             evt.Attributes |= MemberAttributes.Final;
         }
     }
     //
     this.CurrentClass.Members.Add(evt);
 }
        static CodeTypeMember GenerateEvent(EventDefinition eventDefinition)
        {
            var @event = new CodeMemberEvent
            {
                Name = eventDefinition.Name,
                Attributes = MemberAttributes.Public | MemberAttributes.Final,
                CustomAttributes = CreateCustomAttributes(eventDefinition),
                Type = CreateCodeTypeReference(eventDefinition.EventType)
            };

            return @event;
        }
コード例 #15
0
ファイル: csharpcodeprovider.cs プロジェクト: ArildF/masters
        protected override void GenerateEvent(CodeMemberEvent e, CodeTypeDeclaration c) {
            if (IsCurrentDelegate || IsCurrentEnum) return;

            if (e.CustomAttributes.Count > 0) {
                GenerateAttributes(e.CustomAttributes);
            }

            if (e.PrivateImplementationType == null) {
                OutputMemberAccessModifier(e.Attributes);
            }
            Output.Write("event ");
            string name = e.Name;
            if (e.PrivateImplementationType != null) {
                name = e.PrivateImplementationType.BaseType + "." + name;
            }
            OutputTypeNamePair(e.Type, name);
            Output.WriteLine(";");
        }
コード例 #16
0
ファイル: CodeValidator.cs プロジェクト: uQr/referencesource
        private void ValidateEvent(CodeMemberEvent e) {

            if (e.CustomAttributes.Count > 0) {
                ValidateAttributes(e.CustomAttributes);
            }
            if (e.PrivateImplementationType != null) {
                ValidateTypeReference(e.Type);
                ValidateIdentifier(e,"Name",e.Name);
            }

            ValidateTypeReferences(e.ImplementationTypes);
        }
コード例 #17
0
ファイル: CSharpCodeGenerator.cs プロジェクト: runefs/Marvin
		protected override void GenerateEvent (CodeMemberEvent eventRef, CodeTypeDeclaration declaration)
		{
			if (IsCurrentDelegate || IsCurrentEnum) {
				return;
			}

			OutputAttributes (eventRef.CustomAttributes, null, false);

			if (eventRef.PrivateImplementationType == null) {
				OutputMemberAccessModifier (eventRef.Attributes);
			}

			Output.Write ("event ");

			if (eventRef.PrivateImplementationType != null) {
				OutputTypeNamePair (eventRef.Type,
					eventRef.PrivateImplementationType.BaseType + "." + 
					eventRef.Name);
			} else {
				OutputTypeNamePair (eventRef.Type, GetSafeName (eventRef.Name));
			}
			Output.WriteLine (';');
		}
コード例 #18
0
        public bool ValidateCodeMemberEvent (CodeMemberEvent exp) {
            bool result = false;
            PushLocation(exp);

            if (IsValidAttribute (exp.Attributes) &&
                    ValidateCodeTypeReference (exp.Type))
                result = true;

            PopLocation();
            return result;
        }
コード例 #19
0
		protected override void GenerateEvent(CodeMemberEvent e, CodeTypeDeclaration c)
		{
			Output.WriteLine("[CodeMemberEvent: {0}]", e.ToString());
		}
コード例 #20
0
 protected override void GenerateEvent(CodeMemberEvent e, CodeTypeDeclaration c)
 {
     if (!base.IsCurrentDelegate && !base.IsCurrentEnum)
     {
         if (e.CustomAttributes.Count > 0)
         {
             this.OutputAttributes(e.CustomAttributes, false);
         }
         string name = e.Name;
         if (e.PrivateImplementationType != null)
         {
             string str2 = this.GetBaseTypeOutput(e.PrivateImplementationType).Replace('.', '_');
             e.Name = str2 + "_" + e.Name;
         }
         this.OutputMemberAccessModifier(e.Attributes);
         base.Output.Write("Event ");
         this.OutputTypeNamePair(e.Type, e.Name);
         if (e.ImplementationTypes.Count > 0)
         {
             base.Output.Write(" Implements ");
             bool flag = true;
             foreach (CodeTypeReference reference in e.ImplementationTypes)
             {
                 if (flag)
                 {
                     flag = false;
                 }
                 else
                 {
                     base.Output.Write(" , ");
                 }
                 this.OutputType(reference);
                 base.Output.Write(".");
                 this.OutputIdentifier(name);
             }
         }
         else if (e.PrivateImplementationType != null)
         {
             base.Output.Write(" Implements ");
             this.OutputType(e.PrivateImplementationType);
             base.Output.Write(".");
             this.OutputIdentifier(name);
         }
         base.Output.WriteLine("");
     }
 }
コード例 #21
0
ファイル: VBCodeGenerator.cs プロジェクト: nlhepler/mono
		protected override void GenerateEvent (CodeMemberEvent eventRef, CodeTypeDeclaration declaration)
		{
			if (IsCurrentDelegate || IsCurrentEnum)
				return;

			TextWriter output = Output;

			OutputAttributes (eventRef.CustomAttributes, null,
				LineHandling.ContinueLine);

			OutputMemberAccessModifier (eventRef.Attributes);

			output.Write ("Event ");
			OutputTypeNamePair (eventRef.Type, GetEventName(eventRef));

			if (eventRef.ImplementationTypes.Count > 0) {
				OutputImplementationTypes (eventRef.ImplementationTypes, eventRef.Name);
			} else if (eventRef.PrivateImplementationType != null) {
				output.Write (" Implements ");
				OutputType (eventRef.PrivateImplementationType);
				output.Write ('.');
				output.Write (eventRef.Name);
			}

			output.WriteLine ();
		}
コード例 #22
0
ファイル: CodeGenerator.cs プロジェクト: carrie901/mono
		protected abstract void GenerateEvent (CodeMemberEvent ev, CodeTypeDeclaration d);
コード例 #23
0
 protected override void GenerateEvent(System.CodeDom.CodeMemberEvent e, System.CodeDom.CodeTypeDeclaration c)
 {
     throw new Exception("The method or operation is not implemented.");
 }
コード例 #24
0
ファイル: VBCodeGenerator.cs プロジェクト: nlhepler/mono
		private string GetEventName (CodeMemberEvent evt)
		{
			if (evt.PrivateImplementationType == null)
				return evt.Name;

			string baseType = evt.PrivateImplementationType.BaseType.Replace ('.', '_');
			return baseType + "_" + evt.Name;
		}
コード例 #25
0
		protected string GenerateEventMembersType2 (CodeGeneratorOptions options)
		{
			TypeDeclaration.Name = "Test1";

			CodeMemberEvent evt = new CodeMemberEvent ();
			evt.Name = "Click";
			evt.Attributes = MemberAttributes.Public | MemberAttributes.Override
				| MemberAttributes.Static | MemberAttributes.Abstract |
				MemberAttributes.New;
			evt.Type = new CodeTypeReference (typeof (int));
			TypeDeclaration.Members.Add (evt);

			return GenerateCodeFromType (TypeDeclaration, options);
		}
コード例 #26
0
ファイル: CodeGeneratorCas.cs プロジェクト: Profit0004/mono
		protected override void GenerateEvent (CodeMemberEvent e, CodeTypeDeclaration c)
		{
		}
コード例 #27
0
		protected string GenerateEventImplementationTypes (CodeGeneratorOptions options)
		{
			TypeDeclaration.Name = "Test1";

			CodeMemberEvent evt = new CodeMemberEvent ();
			evt.Name = "Click";
			evt.Attributes = MemberAttributes.FamilyAndAssembly;
			evt.Type = new CodeTypeReference (typeof (int));
			evt.ImplementationTypes.Add (new CodeTypeReference ("IPolicy"));
			evt.ImplementationTypes.Add (new CodeTypeReference ("IWhatever"));
			TypeDeclaration.Members.Add (evt);

			return GenerateCodeFromType (TypeDeclaration, options);
		}
コード例 #28
0
        // RG
        public override object VisitEventDeclaration(EventDeclaration eventDeclaration, object data)
        {
            CodeMemberEvent evt = new CodeMemberEvent();
            evt.Type = ConvType(eventDeclaration.TypeReference);
            evt.Name = eventDeclaration.Name;

            evt.Attributes = ConvMemberAttributes(eventDeclaration.Modifier);

            typeDeclarations.Peek().Members.Add(evt);

            return null;
        }
コード例 #29
0
		protected string GenerateEventImplementationTypeOrder (CodeGeneratorOptions options)
		{
			TypeDeclaration.Name = "Test1";

			CodeMemberEvent evt = new CodeMemberEvent ();
			evt.Name = "Click";
			evt.Attributes = MemberAttributes.Public | MemberAttributes.Overloaded;
			evt.Type = new CodeTypeReference (typeof (int));
			evt.PrivateImplementationType = new CodeTypeReference (typeof (int));
			evt.ImplementationTypes.Add (new CodeTypeReference ("IPolicy"));
			TypeDeclaration.Members.Add (evt);

			return GenerateCodeFromType (TypeDeclaration, options);
		}
コード例 #30
0
        private void AddINotifyPropertyChangedRegion(CodeTypeDeclaration declaration)
        {
            CodeMemberEvent memberEvent = new CodeMemberEvent();
            declaration.Members.Add(memberEvent);
            memberEvent.Attributes = MemberAttributes.Public;
            memberEvent.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "INotifyPropertyChanged Members"));
            memberEvent.Name = "PropertyChanged";
            memberEvent.Type = new CodeTypeReference("PropertyChangedEventHandler");

            CodeMemberMethod propertyChangedMethod = new CodeMemberMethod();
            declaration.Members.Add(propertyChangedMethod);
            propertyChangedMethod.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, null));
            propertyChangedMethod.Attributes = MemberAttributes.Family;
            propertyChangedMethod.Name = Common.PropertyChangedInternalMethod;
            propertyChangedMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof (string), "information"));
            CodeConditionStatement ifStatement = new CodeConditionStatement(
                new CodeBinaryOperatorExpression(
                    new CodeFieldReferenceExpression(null, "PropertyChanged"),
                    CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null)
                    ), new CodeExpressionStatement(
                new CodeMethodInvokeExpression(null, "PropertyChanged",
                                               new CodeThisReferenceExpression(),
                                               new CodeObjectCreateExpression(
                                                   "PropertyChangedEventArgs",
                                                   new CodeFieldReferenceExpression(null, "information"))))
                );
            propertyChangedMethod.Statements.Add(ifStatement);
        }
コード例 #31
0
ファイル: OnChangingCall.cs プロジェクト: wskplho/Tools
 /// <summary>Called when extension shall processs generated CodeDOM</summary>
 /// <param name="code">Object tree representing generated CodeDOM</param>
 /// <param name="schema">Input XML schema</param>
 /// <param name="provider">CodeDOM provider (the language)</param>
 /// <version version="1.5.3">Added documentation</version>
 /// <version version="1.5.3">Parameter <c>Provider</c> renamed to <c>provider</c></version>
 public void Process(CodeNamespace code, XmlSchema schema, CodeDomProvider provider)
 {
     foreach (CodeTypeDeclaration type in code.Types) {
         if (type.IsClass || type.IsStruct) {
             bool iNotifyPropertyChangingRequired = false;
             List<CodeTypeMember> addMembers = new List<CodeTypeMember>();
             foreach (CodeTypeMember member in type.Members) {
                 if (member is CodeMemberProperty) {
                     CodeMemberProperty prp = (CodeMemberProperty)member;
                     if (prp.HasSet) {
                         CodeTypeReference argType = new CodeTypeReference("Tools.ComponentModelT.PropertyChangingEventArgsEx") {
                             TypeArguments = { prp.Type }
                         };
                         prp.SetStatements.Insert(0,
                             new CodeExpressionStatement(
                                 new CodeMethodInvokeExpression(
                                     new CodeThisReferenceExpression(), string.Format("On{0}Changing", prp.Name),
                                         new CodeExpression[]{ new CodeObjectCreateExpression(argType, new CodeExpression[]{
                                             new CodePrimitiveExpression(prp.Name),
                                             new CodePropertySetValueReferenceExpression()
                                         })}
                             )));
                         CodeMemberMethod on = new CodeMemberMethod();
                         on.Name = string.Format("On{0}Changing", prp.Name);
                         on.Attributes = MemberAttributes.Family;
                         if (prp.Attributes.HasFlag(MemberAttributes.Static)) on.Attributes |= MemberAttributes.Static;
                         else iNotifyPropertyChangingRequired = true;
                         on.Parameters.Add(new CodeParameterDeclarationExpression(argType, "e"));
                         on.Comments.Add(new CodeCommentStatement(string.Format(Resources.Summary_OnChanging, prp.Name), true));
                         CodeTypeReference evType = new CodeTypeReference("System.EventHandler");
                         evType.TypeArguments.Add(argType);
                         on.Statements.Add(new CodeDelegateInvokeExpression(new CodeEventReferenceExpression(new CodeThisReferenceExpression(),
                             string.Format("{0}Changing", prp.Name)), new CodeExpression[] {
                                 new CodeThisReferenceExpression(),
                                 new CodeArgumentReferenceExpression("e")
                             }));
                         on.Statements.Add(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "OnPropertyChanging", new CodeArgumentReferenceExpression("e")));
                         addMembers.Add(on);
                         CodeMemberEvent ev = new CodeMemberEvent() { Attributes = MemberAttributes.Public };
                         ev.Name = string.Format("{0}Changing", prp.Name);
                         ev.Type = evType;
                         ev.Comments.Add(new CodeCommentStatement(string.Format(Resources.Summary_Changing, prp.Name), true));
                         if (prp.Attributes.HasFlag(MemberAttributes.Static)) ev.Attributes |= MemberAttributes.Static;
                         addMembers.Add(ev);
                     }
                 }
             }
             if (iNotifyPropertyChangingRequired) {
                 type.BaseTypes.Add(typeof(INotifyPropertyChanging));
                 addMembers.Add(new CodeMemberEvent() {
                     Attributes = MemberAttributes.Public,
                     Comments = { new CodeCommentStatement(Resources.Summary_PropertyChanging, true) },
                     ImplementationTypes = { new CodeTypeReference(typeof(INotifyPropertyChanging)) },
                     Name = "PropertyChanging",
                     Type = new CodeTypeReference(typeof(PropertyChangingEventHandler))
                 });
                 addMembers.Add(new CodeMemberMethod() {
                     Name = "OnPropertyChanging",
                     Attributes = MemberAttributes.Family,
                     Comments = {
                         new CodeCommentStatement(Resources.Summary_OnPropertyChanging,true),
                         new CodeCommentStatement(Resources.Param_OnPropertyChanging_e,true)
                     },
                     Parameters = { new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(PropertyChangingEventArgs)), "e") },
                     Statements = {
                         new CodeDelegateInvokeExpression(new CodeEventReferenceExpression(new CodeThisReferenceExpression() ,
                             "PropertyChanging"), new CodeThisReferenceExpression(),new CodeArgumentReferenceExpression("e"))
                     }
                 });
             }
             foreach (CodeTypeMember m in addMembers) {
                 type.Members.Add(m);
             }
         }
     }
 }