public override INotation CreateImplement(ITypeSymbolInfo type) { var @namespace = new NamespaceNotation() { Name = type.Namespace }; var @class = new ClassNotation() { Accessibility = type.Accessibility, Name = $"Proxy{type.Name}{RandomUtils.NewName()}" }; @class.CustomAttributes.Add($"[Norns.Destiny.Attributes.Proxy(typeof({CreateImplementKey(type)}))]".ToNotation()); if (type.IsGenericType) { @class.TypeParameters.AddRange(type.TypeParameters.Select(i => i.ToNotation())); } @namespace.Members.Add(@class); @class.Inherits.Add(type.FullName.ToNotation()); var context = new ProxyGeneratorContext() { Symbol = type }; context.SetCurrentNamespaceNotation(@namespace); context.SetCurrentClassNotation(@class); foreach (var member in type.Members.Union(type.Interfaces.SelectMany(i => i.Members)).Distinct()) { switch (member) { case IMethodSymbolInfo method when !method.IsStatic && method.MethodKind != MethodKindInfo.PropertyGet && method.MethodKind != MethodKindInfo.PropertySet && (method.CanOverride() || (method.ContainingType.IsInterface && !method.IsAbstract)) && method.Name != "Finalize": @class.Members.Add(CreateProxyMethod(method, context)); break; case IMethodSymbolInfo method when !method.IsStatic && method.MethodKind == MethodKindInfo.Constructor: @class.Members.Add(GenerateImplementConstructor(method, @class.Name)); break; case IPropertySymbolInfo property when property.CanOverride(): @class.Members.Add(CreateProxyProperty(property, context)); break; default: break; } } AddProxyInfo(@class, context, type); return(@namespace); }
public override INotation CreateImplement(ITypeSymbolInfo type) { var context = new ProxyGeneratorContext() { Symbol = type }; var @namespace = new NamespaceNotation() { Name = type.Namespace }; var @class = new ClassNotation() { Accessibility = type.Accessibility, Name = $"DefaultImplement{type.Name}{RandomUtils.NewName()}" }; @class.CustomAttributes.Add($"[Norns.Destiny.Attributes.DefaultImplement(typeof({CreateImplementKey(type)}))]".ToNotation()); if (type.IsGenericType) { @class.TypeParameters.AddRange(type.TypeParameters.Select(i => i.ToNotation())); } @namespace.Members.Add(@class); @class.Inherits.Add(type.FullName.ToNotation()); foreach (var member in type.Members.Union(type.Interfaces.SelectMany(i => i.Members)).Distinct(new FullNameSymbolInfoEqualityComparer())) { switch (member) { case IMethodSymbolInfo method when method.Accessibility != AccessibilityInfo.Private && !method.IsStatic && method.IsAbstract && method.MethodKind == MethodKindInfo.Method: @class.Members.Add(GenerateImplementMethod(method, context)); break; case IMethodSymbolInfo method when method.Accessibility != AccessibilityInfo.Private && !method.IsStatic && method.MethodKind == MethodKindInfo.Constructor: @class.Members.Add(GenerateImplementConstructor(method, @class.Name)); break; case IPropertySymbolInfo property when property.Accessibility != AccessibilityInfo.Private && !property.IsStatic: @class.Members.Add(GenerateImplementProperty(property, context)); break; default: break; } } return(@namespace); }
public static void SetCurrentNamespaceNotation(this ProxyGeneratorContext context, NamespaceNotation @namespace) { context[CurrentNamespaceNotation] = @namespace; }