void AddWrappedObjsConstructor(RoslynCodeBuilder roslynCodeBuilder) { string paramsLine = GetWrappedObjConstructorParamStr(); if (paramsLine.IsNullOrEmpty()) { return; } roslynCodeBuilder.PushRegion("Wrappers Constructor"); roslynCodeBuilder.AddLine($"public {this.ClassName}({paramsLine})"); roslynCodeBuilder.Push(); foreach (WrappedObjInfo wrapObjInfo in _wrappedObjInfos) { string assignmentLine = $"{wrapObjInfo.WrappedObjPropName} = {wrapObjInfo.WrappedObjClassName.FirstCharToLowerCase(true)}"; roslynCodeBuilder.AddLine(assignmentLine, true); } roslynCodeBuilder.Pop(true); roslynCodeBuilder.PopRegion(); }
void AddPluginObjsConstructor(RoslynCodeBuilder roslynCodeBuilder) { string paramsLine = GetWrappedObjConstructorParamStr(); if (paramsLine.IsNullOrEmpty()) { return; } roslynCodeBuilder.PushRegion("Plugins Constructor"); roslynCodeBuilder.AddLine($"public {this.ClassName}({paramsLine})"); roslynCodeBuilder.Push(); foreach (PluginInfo pluginInfo in PluginInfos) { pluginInfo.AddPluginInitInConstructorCode(roslynCodeBuilder); roslynCodeBuilder.AddLine(); } roslynCodeBuilder.AddLine($"{INIT_METHOD_NAME}()", true); roslynCodeBuilder.Pop(true); roslynCodeBuilder.PopRegion(); }
public override void Build(IEventSymbol symbol, RoslynCodeBuilder roslynCodeBuilder) { base.Build(symbol, roslynCodeBuilder); roslynCodeBuilder.AddEmptyLine(); roslynCodeBuilder.AddLine("protected void OnPropertyChanged(string propName)"); roslynCodeBuilder.Push(); roslynCodeBuilder.AddLine($"this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName))", true); roslynCodeBuilder.Pop(); }
protected override void BuildImpl(IMethodSymbol methodWrapperSymbol, RoslynCodeBuilder roslynCodeBuilder) { bool shouldOverride = (!ForceNoOverride) && methodWrapperSymbol.ShouldOverride(); roslynCodeBuilder.AddMethodOpeningFromSymbolOnly(methodWrapperSymbol, shouldOverride); string returnVarName = "result"; string firstLineInsert = ""; if (!methodWrapperSymbol.ReturnsVoid) { string returnTypeStr = (methodWrapperSymbol.ReturnType as INamedTypeSymbol).GetFullTypeString(); roslynCodeBuilder.AddLine($"{returnTypeStr} {returnVarName} = default({returnTypeStr})", true); firstLineInsert = $"{returnVarName} = "; } if (this.IncludeBaseVirtualInOverride) { roslynCodeBuilder.AddEmptyLine(); roslynCodeBuilder.AddMethodCall(WrapperSymbol, $"base.{WrapperSymbolName}"); } bool isFirst = true; foreach (MemberMapInfo memberMap in this.WrappedMembers) { memberMap.AddCheckForSharedLine(roslynCodeBuilder); roslynCodeBuilder.Push(); roslynCodeBuilder.AddLine(); if (isFirst) { roslynCodeBuilder.AddText(firstLineInsert); isFirst = false; } memberMap.AddPluginMethodLine(this.WrapperSymbol, roslynCodeBuilder); roslynCodeBuilder.Pop(); } if (!methodWrapperSymbol.ReturnsVoid) { roslynCodeBuilder.AddReturnVar(returnVarName); } roslynCodeBuilder.Pop(true); }
public void AddCallToPluginObjConstructor ( RoslynCodeBuilder roslynCodeBuilder, Dictionary <string, string> sharedPluginsNameMap ) { roslynCodeBuilder.AddText($" new {this.ClassName}("); bool notFirst = false; foreach (PluginInfo pluginInfo in PluginInfos) { if (notFirst) { roslynCodeBuilder.AddText(", "); } else { notFirst = true; } string pluginPropName = pluginInfo.PluginPropName; if (!sharedPluginsNameMap.TryGetValue(pluginPropName, out string valToAdd)) { valToAdd = "null"; } roslynCodeBuilder.AddText(valToAdd); } roslynCodeBuilder.AddText(");"); roslynCodeBuilder.AddLine(); }
private void AddInit(RoslynCodeBuilder roslynCodeBuilder) { roslynCodeBuilder.PushRegion("Init Method"); roslynCodeBuilder.AddLine($"void {INIT_METHOD_NAME}()"); roslynCodeBuilder.Push(); this.PropBuilderInfos.DoForEach(propBuilderInfo => propBuilderInfo.AddInit(roslynCodeBuilder)); roslynCodeBuilder.Pop(); roslynCodeBuilder.PopRegion(); }
private void AddDefaultConstructor(RoslynCodeBuilder roslynCodeBuilder) { roslynCodeBuilder.PushRegion("Constructor"); roslynCodeBuilder .AddConstructorOpening ( this.ClassName, Accessibility.Public ); foreach (PluginInfo wrappedObj in PluginInfos) { wrappedObj.AddPluginDefaultConstructorInitialization(roslynCodeBuilder); } roslynCodeBuilder.AddLine($"{INIT_METHOD_NAME}()", true); roslynCodeBuilder.Pop(); roslynCodeBuilder.PopRegion(); }
protected override void BuildImpl(IPropertySymbol propertyWrapperSymbol, RoslynCodeBuilder roslynCodeBuilder) { Accessibility propAccessibility = propertyWrapperSymbol.DeclaredAccessibility; roslynCodeBuilder.AddPropOpening ( propertyWrapperSymbol.Name, propertyWrapperSymbol.Type as INamedTypeSymbol, propertyWrapperSymbol.DeclaredAccessibility, propertyWrapperSymbol.ShouldOverride() ); if (propertyWrapperSymbol.GetMethod != null) { Accessibility getterAccessibility = propertyWrapperSymbol.GetMethod.DeclaredAccessibility; if (getterAccessibility == propAccessibility) { getterAccessibility = Accessibility.NotApplicable; } roslynCodeBuilder.OpenPropGetter(getterAccessibility); MemberMapInfo firstMemberMap = this.WrappedMembers .FirstOrDefault(member => (!member.IsNonPublic)); if (firstMemberMap == null) { firstMemberMap = this.WrappedMembers.First(); } if (firstMemberMap.IsNonPublic) { if (firstMemberMap.AllowNonPublic) { string returnType = (propertyWrapperSymbol.Type as INamedTypeSymbol).GetFullTypeString(); roslynCodeBuilder.AddLine($"return ({returnType}) {firstMemberMap.WrappedObjPropName}.GetPropValue(\"{firstMemberMap.WrappedMemberName}\", true)", true); } } else { string wrappedMemberStr = firstMemberMap.WrappedClassMemberFullName; roslynCodeBuilder.AddReturnVar(wrappedMemberStr); } roslynCodeBuilder.Pop(); } if (propertyWrapperSymbol.SetMethod != null) { Accessibility setterAccessibility = propertyWrapperSymbol.SetMethod.DeclaredAccessibility; if (setterAccessibility == propAccessibility) { setterAccessibility = Accessibility.NotApplicable; } roslynCodeBuilder.OpenPropSetter(setterAccessibility); if (this.IncludeBaseVirtualInOverride) { roslynCodeBuilder.AddSettingValue($"base.{WrapperSymbolName}"); } foreach (MemberMapInfo memberMap in this.WrappedMembers) { if (memberMap.IsNonPublic) { if (memberMap.AllowNonPublic) { roslynCodeBuilder.AddLine($"{memberMap.WrappedObjPropName}.SetPropValue(\"{memberMap.WrappedMemberName}\", value, true)", true); } } else { string wrappedMemberStr = memberMap.WrappedClassMemberFullName; roslynCodeBuilder.AddSettingValue(wrappedMemberStr); } } roslynCodeBuilder.Pop(); } roslynCodeBuilder.Pop(); }
protected void AddStaticCoreReference(RoslynCodeBuilder roslynCodeBuilder) { roslynCodeBuilder.AddLine($"public static Core {STATIC_CORE_MEMBER_NAME} {{ get; set; }}"); }
void AddStaticCoreReference(RoslynCodeBuilder roslynCodeBuilder) { roslynCodeBuilder.AddLine($"public static Core TheCore {{ get; set; }}"); }