/// <summary> /// Wrap every non-private member in current pMixin with special /// handling for static and virtual members /// </summary> /// <param name="manager"></param> /// <param name="wrapperClass"></param> private void ProcessMembers(pMixinGeneratorPipelineState manager, ICodeGeneratorProxy wrapperClass) { var proxyMemberHelper = new MasterWrapperCodeGeneratorProxyMemberHelper(wrapperClass, manager.BaseState.Context.TypeResolver.Compilation); //Static Members proxyMemberHelper.CreateMembers( manager.CurrentMixinMembers .Select(x => x.Member) .DistinctMembers() .Where(member => member.IsStatic), generateMemberModifier: member => "internal static", baseObjectIdentifierFunc: member => manager.CurrentpMixinAttribute.Mixin.IsStaticOrSealed() ? manager.CurrentpMixinAttribute.Mixin.GetOriginalFullNameWithGlobal() : manager.CurrentMixinAbstractMembersWrapperClass.Name ); //Regular Members proxyMemberHelper.CreateMembers( manager.CurrentMixinMembers .Select(x => x.Member) .DistinctMembers() .Where( member => !member.IsStatic && !(member.IsAbstract && member.IsProtected) && !member.IsOverride && !member.IsOverridable && !member.IsVirtual), generateMemberModifier: member => "internal", baseObjectIdentifierFunc: member => MixinInstanceDataMemberName); //Protected Abstract Members proxyMemberHelper.CreateMembers( manager.CurrentMixinMembers .Select(x => x.Member) .DistinctMembers() .Where(member => (member.IsAbstract || member.IsOverride) && member.IsProtected), generateMemberModifier: member => "internal", baseObjectIdentifierFunc: member => MixinInstanceDataMemberName, baseObjectMemberNameFunc: member => GenerateAbstractMixinMembersWrapperClass.GetProtectedMemberWrapperMemberName(member)); //Virtual Members foreach ( var member in manager.CurrentMixinMembers .Select(x => x.Member) .DistinctMembers() .Where(member => member.IsVirtual || (member.IsOverride || member.IsOverridable && !member.IsProtected))) { #region Virtual Method if (member is IMethod) { //Virtual methods call to the Virtual Method Func wrapperClass.CreateMethod( "internal", member.ReturnType.GetOriginalFullNameWithGlobal(), member.Name, (member as IMethod).Parameters.ToKeyValuePair(), string.Format("{0} {1}({2});", (member as IMethod).GetReturnString(), GenerateVirtualMethodFuncName(member), string.Join(",", (member as IMethod).Parameters.Select(x => x.Name))), (member as IMethod).GetGenericMethodConstraints( manager.BaseState.Context.TypeResolver.Compilation)); } #endregion #region Virtual Property else if (member is IProperty) { wrapperClass.CreateProperty( "internal", member.ReturnType.GetOriginalFullNameWithGlobal(), member.Name, (member as IProperty).CanGet && !(member as IProperty).Getter.IsPrivate ? string.Format("get{{ return {0}(); }}", GenerateVirtualMethodFuncName(member) + "Get") : "", (member as IProperty).CanSet && !(member as IProperty).Setter.IsPrivate ? string.Format("set {{{0}(value); }}", GenerateVirtualMethodFuncName(member) + "Set") : "" ); } #endregion } }
private string CreateConstructorInitializersForVirtualMemberFunctions( pMixinGeneratorPipelineState manager, ICodeGeneratorProxy wrapperClass) { var proxyMemberHelper = new MasterWrapperCodeGeneratorProxyMemberHelper(wrapperClass, manager.BaseState.Context.TypeResolver.Compilation); var sb = new StringBuilder(); foreach ( var member in manager.CurrentMixinMembers .Select(x => x.Member) .DistinctMembers() .Where(member => !member.IsPrivate && (member.IsVirtual || member.IsOverride || member.IsOverridable))) { if (member is IMethod) { //ProtectedVirtualMethodFunc = (i) => AbstractWrapper.ProtectedVirtualMethod(i); sb.AppendFormat("{0} = ({1}) => {2};", GenerateVirtualMethodFuncName(member), string.Join(",", (member as IMethod).Parameters.Select(x => x.Name)), proxyMemberHelper.GetMethodBodyCallStatement( member as IMethod, (m) => MixinInstanceDataMemberName, (m) => m.IsProtected ? GenerateAbstractMixinMembersWrapperClass.GetProtectedMemberWrapperMemberName(m) : m.Name)); } else if (member is IProperty) { if ((member as IProperty).CanGet) { //PublicVirtaulPropertyFuncGet = () => AbstractWrapper.PublicVirtualProperty; sb.AppendFormat( @"{0}Get = () => {1};", GenerateVirtualMethodFuncName(member), proxyMemberHelper.GetPropertyGetterReturnBodyStatement( member as IProperty, (m) => MixinInstanceDataMemberName, (m) => m.IsProtected ? GenerateAbstractMixinMembersWrapperClass.GetProtectedMemberWrapperMemberName(m) : m.Name)); } if ((member as IProperty).CanSet) { //PublicVirtualPropertySetFunc = (s) => AbstractWrapper.PublicVirtualProperty = s; sb.AppendFormat( @"{0}Set = (value) => {1};", GenerateVirtualMethodFuncName(member), proxyMemberHelper.GetPropertySetterReturnBodyStatement( member as IProperty, (m) => MixinInstanceDataMemberName, (m) => m.IsProtected ? GenerateAbstractMixinMembersWrapperClass.GetProtectedMemberWrapperMemberName(m) : m.Name)); } } } return(sb.ToString()); }