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 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));
        }