예제 #1
0
        public static IEnumerable<CodeTypeMember> GetPropertyMembers(
            string propName,
            ITypeSymbol propTypeSymbol,
            string referredMemberName,
            IList<string> namespaces,
            string objectReferenceName = null,
            OneWayEventWrapsByWrappedType oneWayEventWrapsByWrappedType = null
        )
        {
            CodeTypeReference propTypeCode = propTypeSymbol.GetTypeReference(namespaces);

            CodeMemberField field = new CodeMemberField(propTypeCode, referredMemberName);

            yield return field;

            CodeTypeMember prop =
                GetProperty(propName, propTypeSymbol, referredMemberName, namespaces, objectReferenceName, oneWayEventWrapsByWrappedType);
            prop.Attributes = MemberAttributes.Public | MemberAttributes.Final;

            yield return prop;
        }
예제 #2
0
        public static CodeTypeMember GetProperty(
            string propName,
            ITypeSymbol propType,
            string referredMemberName,
            IList<string> namespaces,
            string objectReferenceName = null,
            OneWayEventWrapsByWrappedType oneWayEventWrapsByWrappedType = null
        )
        {
            CodeMemberProperty prop = new CodeMemberProperty
            {
                Type = propType.GetTypeReference(namespaces),
                HasGet = true,
                HasSet = true,
                Name = propName
            };

            prop.GetStatements.Add
            (
                CreatePropertyGetWrapper(referredMemberName, objectReferenceName)
            );

            CodeConditionStatement removeEventHandlersStatement =
                oneWayEventWrapsByWrappedType.GetEventHandlerAddersRemovers(referredMemberName, false);

            if (removeEventHandlersStatement != null)
            {
                prop.SetStatements.Add(removeEventHandlersStatement);
            }

            CodeStatement setWrapper = CreatePropertySetWrapper(referredMemberName, objectReferenceName);
            prop.SetStatements.Add(setWrapper);

            CodeConditionStatement addEventHandlersStatement =
               oneWayEventWrapsByWrappedType.GetEventHandlerAddersRemovers(referredMemberName);

            if (addEventHandlersStatement != null)
            {
                prop.SetStatements.Add(addEventHandlersStatement);
            }

            return prop;
        }