public void Generate(CSharpGeneratorContext context, IList <GeneratorDeclaredElement <ITypeOwner> > elements, CSharpElementFactory factory) { IMethodDeclaration methodDeclaration = null; ITypeElement declaredElement = context.ClassDeclaration.DeclaredElement; if (declaredElement != null) { IOverridableMember member = declaredElement.Methods.FirstOrDefault(ValidateMethod); if (member != null) { methodDeclaration = (IMethodDeclaration)member.GetDeclarations().FirstOrDefault(); Generate(context, methodDeclaration, elements, factory); return; } } string method = String.Format("public Int32 {0}()", MethodName); methodDeclaration = (IMethodDeclaration)factory.CreateTypeMemberDeclaration(method); Generate(context, methodDeclaration, elements, factory); context.PutMemberDeclaration(methodDeclaration, null, newDeclaration => new GeneratorDeclarationElement(newDeclaration)); }
public void Generate(CSharpGeneratorContext context, IList <GeneratorDeclaredElement <ITypeOwner> > elements, CSharpElementFactory factory) { IMethodDeclaration methodDeclaration = null; ITypeElement declaredElement = context.ClassDeclaration.DeclaredElement; if (declaredElement != null) { IDeclaredType byteType = TypeFactory.CreateTypeByCLRName(PredefinedType.BYTE_FQN, context.PsiModule, context.Anchor.GetResolveContext()); _byteArrayType = TypeFactory.CreateArrayType(byteType, 1); _typeConversionRule = new CSharpTypeConversionRule(context.PsiModule); IOverridableMember member = declaredElement.Methods.FirstOrDefault(ValidateMethod); if (member != null) { methodDeclaration = (IMethodDeclaration)member.GetDeclarations().FirstOrDefault(); Generate(context, methodDeclaration, elements, factory); return; } } string method = String.Format("public Int32 {0}(Byte[] bytes, Int32 startIndex)", MethodName); methodDeclaration = (IMethodDeclaration)factory.CreateTypeMemberDeclaration(method); Generate(context, methodDeclaration, elements, factory); context.PutMemberDeclaration(methodDeclaration, null, newDeclaration => new GeneratorDeclarationElement(newDeclaration)); }
public static TH CollectDeclarationInfo <T, TH>([NotNull] this IOverridableMember member, [NotNull] T name) where T : class, IMemberName where TH : IMemberHierarchy <T>, new() { var decl = new TH { Element = name }; OverridableMemberInstance superMember = null; foreach (var super in member.GetImmediateSuperMembers()) { superMember = super; if (super.DeclaringType.IsInterfaceType() || super.GetRootSuperMembers(false).Any(m => m.DeclaringType.IsInterfaceType())) { break; } } if (superMember != null) { decl.Super = superMember.GetName <T>(); var firstMember = superMember.GetRootSuperMembers(false).FirstOrDefault() ?? superMember; decl.First = firstMember.GetName <T>(); } if (decl.First != null && decl.Super != null && decl.First.Equals(decl.Super)) { if (decl.Super.DeclaringType.IsInterfaceType) { decl.Super = null; } else { decl.First = null; } } return(decl); }